aboutsummaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorMarvin Borner2021-06-28 16:37:30 +0200
committerMarvin Borner2021-06-28 16:37:30 +0200
commit5a4eea5c6b39d221fe4828cb279c68c60bad8fae (patch)
tree64b91481a4257980785b3a57684b5580e5d81f80 /apps
parent461e6fcb6a0abbf594ea08d6828b841ea6dc964e (diff)
Implemented basic layout rendering
Diffstat (limited to 'apps')
-rw-r--r--apps/chess/main.c21
-rw-r--r--apps/paint/main.c16
-rw-r--r--apps/view/main.c9
-rw-r--r--apps/wm/main.c2
4 files changed, 27 insertions, 21 deletions
diff --git a/apps/chess/main.c b/apps/chess/main.c
index abfad59..d8c52c1 100644
--- a/apps/chess/main.c
+++ b/apps/chess/main.c
@@ -93,11 +93,11 @@ static void mouseclick(struct gui_event_mouse *event)
gui_clear(win, selected_piece->widget, GUI_LAYER_FG);
load_image(clicked_piece);
- gui_redraw_window(win);
+ gui_window_redraw(win);
selected = vec2(-1, -1);
} else if (clicked_piece->piece) {
- gui_redraw_widget(win, clicked_piece->widget);
+ gui_widget_redraw(win, clicked_piece->widget);
selected = clicked;
}
}
@@ -212,10 +212,15 @@ static void fen_parse(const char *fen)
static void draw_board(void)
{
- for (u8 x = 0; x < 8; x++) {
- for (u8 y = 0; y < 8; y++) {
- u32 widget = gui_widget(win, gui_main_widget(win), vec2(TILE * x, TILE * y),
- vec2(TILE, TILE));
+ gui_widget_margin(win, gui_widget_main(win), vec2(0, 0));
+ gui_widget_layout(win, gui_widget_main(win), GUI_VLAYOUT);
+
+ for (u8 y = 0; y < 8; y++) {
+ u8 row = gui_widget(win, gui_widget_main(win), vec2(TILE * 8, TILE));
+ gui_widget_margin(win, row, vec2(0, 0));
+
+ for (u8 x = 0; x < 8; x++) {
+ u32 widget = gui_widget(win, row, vec2(TILE, TILE));
assert((signed)widget > 0);
u8 colored = (x + y + 1) % 2 == 0;
@@ -234,12 +239,12 @@ static void draw_board(void)
}
}
- gui_redraw_window(win);
+ gui_window_redraw(win);
}
int main(void)
{
- win = gui_custom_window(APPNAME, vec2(0, 0), vec2(TILE * 8, TILE * 8));
+ win = gui_window_custom(APPNAME, vec2(0, 0), vec2(TILE * 8, TILE * 8));
fen_parse(START_FEN);
draw_board();
diff --git a/apps/paint/main.c b/apps/paint/main.c
index 626d41d..0f0dd8c 100644
--- a/apps/paint/main.c
+++ b/apps/paint/main.c
@@ -20,7 +20,7 @@ static void mousemove(struct gui_event_mouse *event)
if (event->but.left) {
gui_draw_line(event->win, event->widget, GUI_LAYER_FG, last, event->pos, size,
current_color);
- gui_redraw_widget(event->win, event->widget);
+ gui_widget_redraw(event->win, event->widget);
}
last = event->pos;
}
@@ -37,27 +37,27 @@ int main(void)
u32 win = gui_window(APPNAME);
vec2 win_size = gui_window_size(win);
- u32 toolbar = gui_widget(win, gui_main_widget(win), vec2(0, 0),
+ gui_widget_margin(win, gui_widget_main(win), vec2(0, 0));
+ gui_widget_layout(win, gui_widget_main(win), GUI_VLAYOUT);
+
+ u32 toolbar = gui_widget(win, gui_widget_main(win),
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_widget(win, toolbar,
- vec2(TOOLBAR_MARGIN + i * (COLOR_SIZE + TOOLBAR_MARGIN),
- TOOLBAR_MARGIN),
- vec2(COLOR_SIZE, COLOR_SIZE));
+ u32 color = gui_widget(win, toolbar, 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_widget_listen(win, color, GUI_LISTEN_MOUSECLICK, (u32)color_click);
}
- u32 canvas = gui_widget(win, gui_main_widget(win), vec2(0, COLOR_SIZE + 2 * TOOLBAR_MARGIN),
+ u32 canvas = gui_widget(win, gui_widget_main(win),
vec2(win_size.x, win_size.y - (COLOR_SIZE + 2 * TOOLBAR_MARGIN)));
gui_fill(win, canvas, GUI_LAYER_BG, COLOR_WHITE);
gui_widget_listen(win, canvas, GUI_LISTEN_MOUSEMOVE, (u32)mousemove);
- gui_redraw_window(win);
+ gui_window_redraw(win);
gui_loop();
return 0;
}
diff --git a/apps/view/main.c b/apps/view/main.c
index fc7e3bc..f3ccb3d 100644
--- a/apps/view/main.c
+++ b/apps/view/main.c
@@ -14,7 +14,7 @@ static void mousemove(struct gui_event_mouse *event)
size = vec2_mul(size, event->scroll < 0 ? SCALING_FACTOR + 1 : 1 - SCALING_FACTOR);
gui_fill(event->win, event->widget, GUI_LAYER_FG, COLOR_WHITE);
gui_draw_image(event->win, event->widget, GUI_LAYER_FG, vec2(0, 0), size, path);
- gui_redraw_widget(event->win, event->widget);
+ gui_widget_redraw(event->win, event->widget);
}
}
@@ -25,12 +25,13 @@ int main(int argc, char *argv[])
path = "/res/test.png";
- u32 win = gui_custom_window(APPNAME, vec2(0, 0), size);
- u32 canvas = gui_widget(win, gui_main_widget(win), vec2(0, 0), size);
+ u32 win = gui_window_custom(APPNAME, vec2(0, 0), size);
+ gui_widget_margin(win, gui_widget_main(win), vec2(0, 0));
+ u32 canvas = gui_widget(win, gui_widget_main(win), size);
gui_fill(win, canvas, GUI_LAYER_BG, COLOR_WHITE);
gui_widget_listen(win, canvas, GUI_LISTEN_MOUSEMOVE, (u32)mousemove);
- gui_redraw_window(win);
+ gui_window_redraw(win);
gui_loop();
return 0;
diff --git a/apps/wm/main.c b/apps/wm/main.c
index 6a4b9bf..8c12b1a 100644
--- a/apps/wm/main.c
+++ b/apps/wm/main.c
@@ -754,7 +754,7 @@ int main(int argc, char **argv)
assert(dev_control(DEV_BUS, DEVCTL_BUS_REGISTER, "wm") == EOK);
- assert(exec("view", NULL) == EOK);
+ assert(exec("chess", NULL) == EOK);
u8 msg[1024] = { 0 };
struct event_keyboard event_keyboard = { 0 };