-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c641f69
commit b8cfb02
Showing
5 changed files
with
82 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#include "toolbar.h" | ||
|
||
#include "services/loader/loader.h" | ||
#include "ui/spacer.h" | ||
#include "ui/style.h" | ||
|
||
#define TOOLBAR_HEIGHT 40 | ||
#define TOOLBAR_FONT_HEIGHT 18 | ||
|
||
static void on_nav_pressed(lv_event_t* event) { | ||
NavAction action = (NavAction)event->user_data; | ||
action(); | ||
} | ||
|
||
lv_obj_t* tt_lv_toolbar_create(lv_obj_t* parent, const Toolbar* toolbar) { | ||
lv_obj_t* wrapper = lv_obj_create(parent); | ||
lv_obj_set_width(wrapper, LV_PCT(100)); | ||
lv_obj_set_height(wrapper, TOOLBAR_HEIGHT); | ||
tt_lv_obj_set_style_no_padding(wrapper); | ||
lv_obj_center(wrapper); | ||
lv_obj_set_flex_flow(wrapper, LV_FLEX_FLOW_ROW); | ||
|
||
lv_obj_t* close_button = lv_btn_create(wrapper); | ||
lv_obj_set_size(close_button, TOOLBAR_HEIGHT - 4, TOOLBAR_HEIGHT - 4); | ||
tt_lv_obj_set_style_no_padding(close_button); | ||
lv_obj_add_event_cb(close_button, &on_nav_pressed, LV_EVENT_CLICKED, toolbar->nav_action); | ||
lv_obj_t* close_button_image = lv_img_create(close_button); | ||
lv_img_set_src(close_button_image, toolbar->nav_icon); // e.g. LV_SYMBOL_CLOSE | ||
lv_obj_align(close_button_image, LV_ALIGN_CENTER, 0, 0); | ||
|
||
// Need spacer to avoid button press glitch animation | ||
tt_lv_spacer_create(wrapper, 2, 1); | ||
|
||
lv_obj_t* label_container = lv_obj_create(wrapper); | ||
tt_lv_obj_set_style_no_padding(label_container); | ||
lv_obj_set_style_border_width(label_container, 0, 0); | ||
lv_obj_set_height(label_container, LV_PCT(100)); // 2% less due to 4px translate (it's not great, but it works) | ||
lv_obj_set_flex_grow(label_container, 1); | ||
|
||
lv_obj_t* title_label = lv_label_create(label_container); | ||
lv_label_set_text(title_label, toolbar->title); | ||
lv_obj_set_style_text_font(title_label, &lv_font_montserrat_18, 0); | ||
lv_obj_set_size(title_label, LV_PCT(100), 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); | ||
|
||
return wrapper; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#pragma once | ||
|
||
#include "lvgl.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
typedef void(*NavAction)(); | ||
|
||
typedef struct { | ||
const char* _Nullable title; | ||
const char* _Nullable nav_icon; // LVGL compatible definition (e.g. local file or embedded icon from LVGL) | ||
NavAction nav_action; | ||
} Toolbar; | ||
|
||
lv_obj_t* tt_lv_toolbar_create(lv_obj_t* parent, const Toolbar* toolbar); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |