aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi.dcr@tutanota.com>2022-07-02 00:58:50 +0200
committerXavier Del Campo Romero <xavi.dcr@tutanota.com>2022-07-02 00:58:50 +0200
commita71ce379297384df42e720641d39a4d2ade6bbd9 (patch)
treebd9bfc06e64b742a41c22fc1ab0004885fe3d15b /src
parente68c2fb4be6096f3dffbefe56696ba9e864446fc (diff)
menu: implement main menu using new GUI improvements
Diffstat (limited to 'src')
-rw-r--r--src/menu/src/menu.c27
1 files changed, 19 insertions, 8 deletions
diff --git a/src/menu/src/menu.c b/src/menu/src/menu.c
index 41adbb5..38f8632 100644
--- a/src/menu/src/menu.c
+++ b/src/menu/src/menu.c
@@ -4,6 +4,7 @@
#include <gfx.h>
#include <gui.h>
#include <gui/button.h>
+#include <gui/container.h>
#include <system.h>
#include <stdbool.h>
@@ -15,22 +16,35 @@ static void on_pressed(void *const arg)
int menu(void)
{
struct camera cam = {0};
- struct gui_button play;
+ struct gui_button play, exit_btn;
+ struct gui_container cnt;
union peripheral p;
- bool start = false;
+ bool start = false, exit = false;
if (game_resinit())
return -1;
cursor_init(&cam.cursor);
+ gui_container_init(&cnt);
+ cnt.mode = GUI_CONTAINER_MODE_V;
+ cnt.common.hcentered = true;
+ cnt.common.vcentered = true;
gui_button_init(&play);
+ gui_button_init(&exit_btn);
play.on_pressed = on_pressed;
play.arg = &start;
play.w = 140;
play.common.hcentered = true;
- play.common.vcentered = true;
play.label.text = "Play";
+ exit_btn.arg = &exit;
+ exit_btn.w = 140;
+ exit_btn.common.hcentered = true;
+ exit_btn.label.text = "Exit";
+ exit_btn.on_pressed = on_pressed;
+ gui_add_child(&cnt.common, &play.common);
+ gui_add_child(&cnt.common, &exit_btn.common);
+
{
const struct peripheral_cfg cfg =
{
@@ -46,9 +60,6 @@ int menu(void)
peripheral_update(&p);
camera_update(&cam, &p);
- play.label.common.x = play.w / 2 - 20;
- play.label.common.y = 4;
-
if (gui_update(&play.common, &p, &cam))
return -1;
@@ -58,10 +69,10 @@ int menu(void)
r->h = screen_h;
rect_sort(r);
- if (p.common.exit)
+ if (p.common.exit || exit)
return 0;
- if (gui_render(&play.common)
+ if (gui_render(&cnt.common)
|| cursor_render(&cam.cursor)
|| gfx_draw())
return -1;