text/plain
•
2.17 KB
•
62 lines
#include "games_screen.h"
#include <stdlib.h>
static void list_event_cb(lv_event_t *e) {
lv_event_code_t code = lv_event_get_code(e);
if (code == LV_EVENT_CLICKED) {
lv_obj_t *btn = lv_event_get_target(e);
screen_type_t screen = (screen_type_t)(uintptr_t)lv_obj_get_user_data(btn);
navigate_to(screen);
}
}
static void cancel_event_cb(lv_event_t *e) {
(void)e;
navigate_to(SCREEN_HOME);
}
ui_state_t setup_games_screen(void) {
games_screen_state_t *state = calloc(1, sizeof(games_screen_state_t));
state->list = bvs_list_create();
// Add list header with styled background
bvs_list_add_header(state->list, "Games");
// Add Demo entry
lv_obj_t *demo_btn = bvs_list_add_button(state->list, NULL, "Demo");
lv_obj_set_user_data(demo_btn, (void *)(uintptr_t)SCREEN_DEMO);
lv_obj_add_event_cb(demo_btn, list_event_cb, LV_EVENT_CLICKED, NULL);
lv_obj_add_event_cb(demo_btn, cancel_event_cb, LV_EVENT_CANCEL, NULL);
// Add Breakout entry
lv_obj_t *breakout_btn = bvs_list_add_button(state->list, NULL, "Breakout");
lv_obj_set_user_data(breakout_btn, (void *)(uintptr_t)SCREEN_BREAKOUT);
lv_obj_add_event_cb(breakout_btn, list_event_cb, LV_EVENT_CLICKED, NULL);
lv_obj_add_event_cb(breakout_btn, cancel_event_cb, LV_EVENT_CANCEL, NULL);
// Add Back entry
lv_obj_t *back_btn = bvs_list_add_button(state->list, NULL, "Back");
lv_obj_set_user_data(back_btn, (void *)(uintptr_t)SCREEN_HOME);
lv_obj_add_event_cb(back_btn, list_event_cb, LV_EVENT_CLICKED, NULL);
lv_obj_add_event_cb(back_btn, cancel_event_cb, LV_EVENT_CANCEL, NULL);
// Add all buttons to group for keyboard navigation
lv_group_add_obj(lv_group_get_default(), demo_btn);
lv_group_add_obj(lv_group_get_default(), breakout_btn);
lv_group_add_obj(lv_group_get_default(), back_btn);
lv_group_focus_obj(demo_btn);
return (ui_state_t){.type = SCREEN_GAMES, .games = state};
}
void free_games_screen(games_screen_state_t *state) {
if (!state) return;
bvs_list_clear(state->list);
free(state);
}
void update_games_screen(games_screen_state_t *state) {
(void)state; // LVGL handles updates via timer
}