From cf1a6ed2998eb22b112f233d65975c27fa5ced5b Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Sun, 23 May 2021 23:19:26 +0200 Subject: Added title to app bar --- apps/chess/main.c | 2 +- apps/generic.mk | 2 +- apps/paint/main.c | 16 ++++++++++------ apps/wm/main.c | 7 ++++--- 4 files changed, 16 insertions(+), 11 deletions(-) (limited to 'apps') diff --git a/apps/chess/main.c b/apps/chess/main.c index 8e1d470..a546e63 100644 --- a/apps/chess/main.c +++ b/apps/chess/main.c @@ -239,7 +239,7 @@ static void draw_board(void) int main(void) { - gui_new_custom_window(&win, vec2(0, 0), vec2(TILE * 8, TILE * 8)); + win = gui_new_custom_window(APPNAME, vec2(0, 0), vec2(TILE * 8, TILE * 8)); fen_parse(START_FEN); draw_board(); diff --git a/apps/generic.mk b/apps/generic.mk index c0ddd3e..809ad16 100644 --- a/apps/generic.mk +++ b/apps/generic.mk @@ -14,4 +14,4 @@ clean: @$(RM) -f $(OBJS) %.o: %.c - @$(CC) -c $(CFLAGS) $< -o $@ + @$(CC) -c $(CFLAGS) -DAPPNAME=\"$(NAME)\" $< -o $@ diff --git a/apps/paint/main.c b/apps/paint/main.c index e537004..464a925 100644 --- a/apps/paint/main.c +++ b/apps/paint/main.c @@ -30,26 +30,30 @@ static void color_click(struct gui_event_mouse *event) current_color = colors[event->widget - 2]; } +// TODO: Simplify using predefined widgets and utilities int main(void) { - u32 win; - gui_new_window(&win); + u32 win = gui_new_window(APPNAME); vec2 win_size = gui_window_size(win); - u32 toolbar = gui_new_widget(win, GUI_MAIN, vec2(0, 0), vec2(win_size.x, COLOR_SIZE)); + u32 toolbar = gui_new_widget(win, GUI_MAIN, vec2(0, 0), + vec2(win_size.x, COLOR_SIZE + 2 * TOOLBAR_MARGIN)); gui_fill(win, toolbar, GUI_LAYER_BG, COLOR_WHITE); u32 color_count = COUNT(colors); for (u32 i = 0; i < color_count; i++) { - u32 color = gui_new_widget(win, toolbar, vec2(i * (COLOR_SIZE + TOOLBAR_MARGIN), 0), + u32 color = gui_new_widget(win, toolbar, + vec2(TOOLBAR_MARGIN + i * (COLOR_SIZE + TOOLBAR_MARGIN), + TOOLBAR_MARGIN), vec2(COLOR_SIZE, COLOR_SIZE)); gui_fill(win, color, GUI_LAYER_FG, colors[i]); gui_draw_border(win, color, GUI_LAYER_FG, 2, COLOR_BLACK); gui_listen_widget(win, color, GUI_LISTEN_MOUSECLICK, (u32)color_click); } - u32 canvas = gui_new_widget(win, GUI_MAIN, vec2(0, COLOR_SIZE), - vec2(win_size.x, win_size.y - COLOR_SIZE)); + u32 canvas = + gui_new_widget(win, GUI_MAIN, vec2(0, COLOR_SIZE + 2 * TOOLBAR_MARGIN), + vec2(win_size.x, win_size.y - (COLOR_SIZE + 2 * TOOLBAR_MARGIN))); gui_fill(win, canvas, GUI_LAYER_BG, COLOR_WHITE); gui_listen_widget(win, canvas, GUI_LISTEN_MOUSEMOVE, (u32)mousemove); diff --git a/apps/wm/main.c b/apps/wm/main.c index 0c30a3f..25478ff 100644 --- a/apps/wm/main.c +++ b/apps/wm/main.c @@ -20,7 +20,7 @@ struct client { struct window { u32 id; u32 shid; - struct context ctx; + struct gfx_context ctx; struct client client; u32 flags; vec2 pos; @@ -470,11 +470,12 @@ static void window_bar_mousemove(struct window *win, struct event_mouse *event, window_move(win, vec2_sub(mouse_pos, vec2(win->ctx.size.x / 2, BAR_HEIGHT / 2))); } -static void window_bar_draw(struct window *win) +static void window_bar_draw(struct window *win, char name[64]) { if (!(win->flags & WF_BAR)) return; + gfx_write(&win->ctx, vec2(BAR_MARGIN, BAR_MARGIN), FONT_24, COLOR_WHITE, name); gfx_load_image_filter(&win->ctx, vec2(win->ctx.size.x - BAR_CLOSE_SIZE - BAR_MARGIN, BAR_MARGIN), GFX_FILTER_INVERT, "/icons/close-" STRINGIFY(BAR_CLOSE_SIZE) ".png"); @@ -592,7 +593,7 @@ static void handle_message_new_window(struct message_new_window *msg) { struct window *win = window_new((struct client){ .conn = msg->header.bus.conn }, msg->pos, vec2_add(msg->size, vec2(0, BAR_HEIGHT)), WF_BAR); - window_bar_draw(win); + window_bar_draw(win, msg->name); msg->ctx = win->ctx; msg->off = vec2(0, BAR_HEIGHT); -- cgit v1.2.3