Files
ui-library-playground/Core/Src/ui.c
Dylan Smith b48cb11197 Menu work
2026-01-15 15:53:02 -05:00

126 lines
4.3 KiB
C

#include "ui.h"
#include "graphics.h"
#include "menu.h"
void ui_enter_submenu(void *const args);
/******************* */
/* Menu declarations */
/******************* */
static graphical_menu_t main_menu;
static graphical_menu_t runescape_memes_menu;
/******************* */
/* Menu definitions */
/******************* */
static const graphical_menu_layout_t main_menu_layout = {
.parent_menu = 0,
.num_entries = 3,
.entries = (graphical_menu_entry_t[]){
{.title = "runescape memes", .enabled = true, .highlighted_callback_function = 0, .highlighted_callback_function_args = 0, .selected_callback_function = ui_enter_submenu, .selected_callback_function_args = &runescape_memes_menu},
{.title = "Settings", .enabled = true, .highlighted_callback_function = 0, .highlighted_callback_function_args = 0, .selected_callback_function = 0, .selected_callback_function_args = 0},
{.title = "About", .enabled = true, .highlighted_callback_function = 0, .highlighted_callback_function_args = 0, .selected_callback_function = 0, .selected_callback_function_args = 0},
}
};
static const graphical_menu_layout_t runescape_memes_menu_layout = {
.parent_menu = &main_menu,
.num_entries = 8,
.entries = (graphical_menu_entry_t[]){
{.title = "where varock", .enabled = true, .highlighted_callback_function = 0, .highlighted_callback_function_args = 0, .selected_callback_function = 0, .selected_callback_function_args = 0},
{.title = "buying gf", .enabled = true, .highlighted_callback_function = 0, .highlighted_callback_function_args = 0, .selected_callback_function = 0, .selected_callback_function_args = 0},
{.title = "le goblin", .enabled = true, .highlighted_callback_function = 0, .highlighted_callback_function_args = 0, .selected_callback_function = 0, .selected_callback_function_args = 0},
{.title = "you chop the tree", .enabled = true, .highlighted_callback_function = 0, .highlighted_callback_function_args = 0, .selected_callback_function = 0, .selected_callback_function_args = 0},
{.title = "you chop the tree", .enabled = true, .highlighted_callback_function = 0, .highlighted_callback_function_args = 0, .selected_callback_function = 0, .selected_callback_function_args = 0},
{.title = "you chop the tree", .enabled = true, .highlighted_callback_function = 0, .highlighted_callback_function_args = 0, .selected_callback_function = 0, .selected_callback_function_args = 0},
{.title = "you chop the tree", .enabled = true, .highlighted_callback_function = 0, .highlighted_callback_function_args = 0, .selected_callback_function = 0, .selected_callback_function_args = 0},
{.title = "you chop the tree", .enabled = true, .highlighted_callback_function = 0, .highlighted_callback_function_args = 0, .selected_callback_function = 0, .selected_callback_function_args = 0},
}
};
static graphical_menu_t main_menu = {
.layout = &main_menu_layout,
.selected_entry_idx = 0,
};
static graphical_menu_t runescape_memes_menu = {
.layout = &runescape_memes_menu_layout,
.selected_entry_idx = 0,
};
/********************** */
/* UI state definitions */
/********************** */
enum ui_state_t {
UI_STATE_MENU,
};
static bool redraw_requested = true;
static enum ui_state_t ui_state = UI_STATE_MENU;
static graphical_menu_t *current_menu = &main_menu;
/************************* */
/* UI function definitions */
/************************* */
void ui_enter_submenu(void *const args)
{
current_menu = (graphical_menu_t *)args;
redraw_requested = true;
}
void ui_exit_submenu(void)
{
if (current_menu->layout->parent_menu == 0)
{
return;
}
current_menu = current_menu->layout->parent_menu;
redraw_requested = true;
}
void ui_left_button_pressed(void)
{
// decrement_selected_menu_entry_idx(&main_menu);
ui_exit_submenu();
}
void ui_right_button_pressed(void)
{
// increment_selected_menu_entry_idx(&main_menu);
}
void ui_up_button_pressed(void)
{
decrement_selected_menu_entry_idx(current_menu);
}
void ui_down_button_pressed(void)
{
increment_selected_menu_entry_idx(current_menu);
}
void ui_ok_button_pressed(void)
{
select_menu_entry(current_menu);
}
void ui_request_redraw(void)
{
redraw_requested = true;
}
void ui_task(void)
{
if (redraw_requested)
{
redraw_requested = false;
draw_menu(current_menu);
}
}