mirror of
https://github.com/skoelle/wt32sc01-dashboard.git
synced 2026-09-18 09:50:25 +00:00
Phase 3: reusable UI widgets (tile_button, back_button) + screen_base lifecycle
- tile_button: large touch tile with accent bg + title + icon + value, fires LV_EVENT_CLICKED (for home screen tiles) - back_button: fixed bottom-left Zurueck button (LV_SYMBOL_LEFT), large touch target, reused on all detail screens - screen_base.h: Screen struct with create/show/hide/refresh/tick lifecycle around an lv_obj_t root (replaces old ScreenId-only header) - lv_conf.h: enable Montserrat 16/20/24 fonts used by the widgets
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
#pragma once
|
||||
#include <lvgl.h>
|
||||
|
||||
enum class ScreenId {
|
||||
HOME,
|
||||
WEATHER_DETAIL,
|
||||
CALENDAR_DETAIL,
|
||||
MVG
|
||||
};
|
||||
|
||||
// Common lifecycle for all screens. Each screen owns one lv_obj_t screen
|
||||
// object; create() builds the UI once, show()/hide() toggle visibility,
|
||||
// refresh() re-fetches data and updates the widgets, tick() is called
|
||||
// every loop iteration for periodic refresh checks.
|
||||
struct Screen {
|
||||
lv_obj_t *root = nullptr;
|
||||
bool created = false;
|
||||
|
||||
// Build the screen object tree (hidden). Called once at startup.
|
||||
void (*create_fn)(Screen &) = nullptr;
|
||||
// Re-fetch data and update widgets.
|
||||
void (*refresh_fn)(Screen &) = nullptr;
|
||||
// Per-loop tick: check refresh timers / inactivity.
|
||||
void (*tick_fn)(Screen &) = nullptr;
|
||||
|
||||
void create() {
|
||||
if (created || !create_fn) return;
|
||||
root = lv_obj_create(nullptr);
|
||||
lv_obj_set_size(root, 320, 480);
|
||||
lv_obj_set_style_bg_color(root, lv_color_hex(0x000000), 0);
|
||||
lv_obj_set_style_border_width(root, 0, 0);
|
||||
lv_obj_set_style_pad_all(root, 0, 0);
|
||||
lv_obj_clear_flag(root, LV_OBJ_FLAG_SCROLLABLE);
|
||||
create_fn(*this);
|
||||
created = true;
|
||||
}
|
||||
|
||||
void show() {
|
||||
if (!created) create();
|
||||
lv_screen_load(root);
|
||||
refresh();
|
||||
}
|
||||
|
||||
void hide() {}
|
||||
|
||||
void refresh() {
|
||||
if (created && refresh_fn) refresh_fn(*this);
|
||||
}
|
||||
|
||||
void tick() {
|
||||
if (created && tick_fn) tick_fn(*this);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user