Various improvements (#34)

* Cleanup function declarations
* Align window toolbar title to the left
This commit is contained in:
Ken Van Hoeylandt 2024-02-04 17:59:25 +01:00 committed by GitHub
parent 69165263f1
commit 93e4378a9e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 11 additions and 7 deletions

View File

@ -11,7 +11,7 @@ static void on_app_pressed(lv_event_t* e) {
} }
} }
static void create_app_widget(const AppManifest* manifest, void* _Nullable parent) { static void create_app_widget(const AppManifest* manifest, void* parent) {
tt_check(parent); tt_check(parent);
lv_obj_t* list = (lv_obj_t*)parent; lv_obj_t* list = (lv_obj_t*)parent;
lv_obj_t* btn = lv_list_add_btn(list, LV_SYMBOL_FILE, manifest->name); lv_obj_t* btn = lv_list_add_btn(list, LV_SYMBOL_FILE, manifest->name);

View File

@ -11,14 +11,14 @@ static void on_app_pressed(lv_event_t* e) {
} }
} }
static void create_app_widget(const AppManifest* manifest, void* _Nullable parent) { static void create_app_widget(const AppManifest* manifest, void* parent) {
tt_check(parent); tt_check(parent);
lv_obj_t* list = (lv_obj_t*)parent; lv_obj_t* list = (lv_obj_t*)parent;
lv_obj_t* btn = lv_list_add_btn(list, LV_SYMBOL_FILE, manifest->name); lv_obj_t* btn = lv_list_add_btn(list, LV_SYMBOL_FILE, manifest->name);
lv_obj_add_event_cb(btn, &on_app_pressed, LV_EVENT_CLICKED, (void*)manifest); lv_obj_add_event_cb(btn, &on_app_pressed, LV_EVENT_CLICKED, (void*)manifest);
} }
static void on_show(TT_UNUSED App app, TT_UNUSED lv_obj_t* parent) { static void on_show(TT_UNUSED App app, lv_obj_t* parent) {
lv_obj_t* list = lv_list_create(parent); lv_obj_t* list = lv_list_create(parent);
lv_obj_set_size(list, LV_PCT(100), LV_PCT(100)); lv_obj_set_size(list, LV_PCT(100), LV_PCT(100));
lv_obj_center(list); lv_obj_center(list);

View File

@ -22,6 +22,9 @@ lv_obj_t* tt_lv_toolbar_create(lv_obj_t* parent, const Toolbar* toolbar) {
lv_obj_center(wrapper); lv_obj_center(wrapper);
lv_obj_set_flex_flow(wrapper, LV_FLEX_FLOW_ROW); lv_obj_set_flex_flow(wrapper, LV_FLEX_FLOW_ROW);
lv_coord_t title_offset_x = (TOOLBAR_HEIGHT - TOOLBAR_FONT_HEIGHT - 8) / 4 * 3;
lv_coord_t title_offset_y = (TOOLBAR_HEIGHT - TOOLBAR_FONT_HEIGHT - 8) / 2;
lv_obj_t* close_button = lv_btn_create(wrapper); lv_obj_t* close_button = lv_btn_create(wrapper);
lv_obj_set_size(close_button, TOOLBAR_HEIGHT - 4, TOOLBAR_HEIGHT - 4); lv_obj_set_size(close_button, TOOLBAR_HEIGHT - 4, TOOLBAR_HEIGHT - 4);
tt_lv_obj_set_style_no_padding(close_button); tt_lv_obj_set_style_no_padding(close_button);
@ -31,7 +34,7 @@ lv_obj_t* tt_lv_toolbar_create(lv_obj_t* parent, const Toolbar* toolbar) {
lv_obj_align(close_button_image, LV_ALIGN_CENTER, 0, 0); lv_obj_align(close_button_image, LV_ALIGN_CENTER, 0, 0);
// Need spacer to avoid button press glitch animation // Need spacer to avoid button press glitch animation
tt_lv_spacer_create(wrapper, 2, 1); tt_lv_spacer_create(wrapper, title_offset_x, 1);
lv_obj_t* label_container = lv_obj_create(wrapper); lv_obj_t* label_container = lv_obj_create(wrapper);
tt_lv_obj_set_style_no_padding(label_container); tt_lv_obj_set_style_no_padding(label_container);
@ -42,9 +45,10 @@ lv_obj_t* tt_lv_toolbar_create(lv_obj_t* parent, const Toolbar* toolbar) {
lv_obj_t* title_label = lv_label_create(label_container); lv_obj_t* title_label = lv_label_create(label_container);
lv_label_set_text(title_label, toolbar->title); lv_label_set_text(title_label, toolbar->title);
lv_obj_set_style_text_font(title_label, &lv_font_montserrat_18, 0); // TODO replace with size 18 lv_obj_set_style_text_font(title_label, &lv_font_montserrat_18, 0); // TODO replace with size 18
lv_obj_set_size(title_label, LV_PCT(100), TOOLBAR_FONT_HEIGHT); lv_obj_set_height(title_label, TOOLBAR_FONT_HEIGHT);
lv_obj_set_pos(title_label, 0, (TOOLBAR_HEIGHT - TOOLBAR_FONT_HEIGHT - 10) / 2);
lv_obj_set_style_text_align(title_label, LV_TEXT_ALIGN_CENTER, 0); lv_obj_set_pos(title_label, 0, title_offset_y);
lv_obj_set_style_text_align(title_label, LV_TEXT_ALIGN_LEFT, 0);
return wrapper; return wrapper;
} }