From f83d5e4b8e315f2b17f0c8bf390bf967f02f5837 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Sun, 25 Oct 2020 12:09:38 +0100 Subject: Added buttons --- apps/window.c | 50 ++------------------------------------------------ 1 file changed, 2 insertions(+), 48 deletions(-) (limited to 'apps/window.c') diff --git a/apps/window.c b/apps/window.c index 70131a6..601f187 100644 --- a/apps/window.c +++ b/apps/window.c @@ -12,61 +12,15 @@ int main() { print("[test context loaded]\n"); - struct window *win = gui_init("test", 0, 0); - struct context *ctx = win->ctx; - - int font_height = gfx_font_height(); - int font_width = gfx_font_width(); - - char *hello = "Hello, world!"; - gfx_write(ctx, ctx->width / 2 - (strlen(hello) * font_width) / 2, 0, COLOR_GREEN, hello); + struct element *container = gui_init("test", 0, 0); + gui_add_button(container, 10, 10, 100, 20, "hallo", COLOR_RED); struct message *msg; - int char_x = 0; - int char_y = 1; while (1) { if (!(msg = msg_receive())) { yield(); continue; } - - // TODO: Export to text widget or sth - switch (msg->type) { - case WM_KEYBOARD: { - struct msg_keyboard *event = msg->data; - char ch = event->ch; - if (!event->press) - break; - - if (char_x * font_width >= (int)ctx->width) { - char_y++; - char_x = 0; - } - - if (ch == '\n') { - char_x = 0; - char_y++; - } else if (ch == '\t') { - char_x += 8; - } else if (ch == '\b') { - if (char_x > 0) { - char_x--; - gfx_draw_rectangle(ctx, font_width * char_x, - font_height * char_y, - font_width * (char_x + 1), - font_height * (char_y + 1), COLOR_BG); - } - } else if (ch == ' ' && event->scancode == KEY_SPACE) { - char_x++; - } else if (ch != ' ' && ch != '\0') { - gfx_write_char(ctx, font_width * char_x++, font_height * char_y, - COLOR_CYAN, ch); - } - break; - } - default: - break; - } } return 0; } -- cgit v1.2.3