Fixes and improvements (#132)
- Fix glitch when turning on WiFi: It would temporarily show "No networks found" right before starting the first scan. - Fix spinner to use Assets.h - Replace statusbar battery icons - Better statusbar icon for when WiFi is on but not connected - Replace statusbar WiFi icons and Wifi Manage RSSI/lock icons - Fix for crash when timer is null in I2cScanner - Deprecate Spacer - Fixes for toolbar layout (simplified) - Improved ImageViewer app: center image and add filename text on the bottom - Add LV debug params to sdkconfig.developer - Disabled LV spinner, msgbox and window widgets. These have equivalents in Tactility.
This commit is contained in:
committed by
GitHub
parent
b4592dd7d1
commit
f34440eb6f
@@ -4,6 +4,7 @@
|
||||
|
||||
namespace tt::lvgl {
|
||||
|
||||
[[deprecated("Use margin")]]
|
||||
lv_obj_t* spacer_create(lv_obj_t* parent, int32_t width, int32_t height);
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
#define LV_USE_PRIVATE_API 1 // For actual lv_obj_t declaration
|
||||
|
||||
#include "lvgl.h"
|
||||
#include "Assets.h"
|
||||
#include "CoreDefines.h"
|
||||
#include "Log.h"
|
||||
#include "lvgl.h"
|
||||
|
||||
static void tt_spinner_constructor(const lv_obj_class_t* object_class, lv_obj_t* object);
|
||||
namespace tt::lvgl {
|
||||
|
||||
static void spinner_constructor(const lv_obj_class_t* object_class, lv_obj_t* object);
|
||||
|
||||
const lv_obj_class_t tt_spinner_class = {
|
||||
.base_class = &lv_image_class,
|
||||
.constructor_cb = tt_spinner_constructor,
|
||||
.constructor_cb = spinner_constructor,
|
||||
.destructor_cb = nullptr,
|
||||
.event_cb = nullptr,
|
||||
.user_data = nullptr,
|
||||
@@ -21,11 +24,11 @@ const lv_obj_class_t tt_spinner_class = {
|
||||
.theme_inheritable = 0
|
||||
};
|
||||
|
||||
lv_obj_t* tt_spinner_create(lv_obj_t* parent) {
|
||||
lv_obj_t* spinner_create(lv_obj_t* parent) {
|
||||
lv_obj_t* obj = lv_obj_class_create_obj(&tt_spinner_class, parent);
|
||||
lv_obj_class_init_obj(obj);
|
||||
|
||||
lv_image_set_src(obj, "A:/assets/spinner.png");
|
||||
lv_image_set_src(obj, TT_ASSETS_UI_SPINNER);
|
||||
|
||||
return obj;
|
||||
}
|
||||
@@ -39,7 +42,7 @@ static void anim_rotation_callback(void* var, int32_t v) {
|
||||
lv_obj_set_style_transform_rotation(object, v, 0);
|
||||
}
|
||||
|
||||
static void tt_spinner_constructor(TT_UNUSED const lv_obj_class_t* object_class, lv_obj_t* object) {
|
||||
static void spinner_constructor(TT_UNUSED const lv_obj_class_t* object_class, lv_obj_t* object) {
|
||||
lv_obj_remove_flag(object, LV_OBJ_FLAG_CLICKABLE);
|
||||
|
||||
lv_anim_t a;
|
||||
@@ -51,3 +54,5 @@ static void tt_spinner_constructor(TT_UNUSED const lv_obj_class_t* object_class,
|
||||
lv_anim_set_exec_cb(&a, anim_rotation_callback);
|
||||
lv_anim_start(&a);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
#include "lvgl.h"
|
||||
|
||||
namespace tt::lvgl {
|
||||
|
||||
/**
|
||||
* Create the Tactility spinner widget
|
||||
* @param parent pointer to an object, it will be the parent of the new spinner.
|
||||
* @return the created spinner
|
||||
*/
|
||||
lv_obj_t* tt_spinner_create(lv_obj_t* parent);
|
||||
lv_obj_t* spinner_create(lv_obj_t* parent);
|
||||
|
||||
}
|
||||
|
||||
@@ -90,8 +90,6 @@ static void statusbar_destructor(TT_UNUSED const lv_obj_class_t* class_p, lv_obj
|
||||
|
||||
static void update_icon(lv_obj_t* image, const StatusbarIcon* icon) {
|
||||
if (icon->image != nullptr && icon->visible && icon->claimed) {
|
||||
lv_obj_set_style_image_recolor(image, lv_color_white(), 0);
|
||||
lv_obj_set_style_image_recolor_opa(image, 255, 0);
|
||||
lv_image_set_src(image, icon->image);
|
||||
lv_obj_remove_flag(image, LV_OBJ_FLAG_HIDDEN);
|
||||
} else {
|
||||
|
||||
@@ -16,7 +16,6 @@ typedef struct {
|
||||
lv_obj_t* close_button;
|
||||
lv_obj_t* close_button_image;
|
||||
lv_obj_t* action_container;
|
||||
ToolbarAction* action_array[TOOLBAR_ACTION_LIMIT];
|
||||
uint8_t action_count;
|
||||
} Toolbar;
|
||||
|
||||
@@ -60,30 +59,23 @@ lv_obj_t* toolbar_create(lv_obj_t* parent, const std::string& title) {
|
||||
lv_obj_center(obj);
|
||||
lv_obj_set_flex_flow(obj, LV_FLEX_FLOW_ROW);
|
||||
|
||||
int32_t title_offset_x = (TOOLBAR_HEIGHT - TOOLBAR_TITLE_FONT_HEIGHT - 8) / 4 * 3;
|
||||
int32_t title_offset_y = (TOOLBAR_HEIGHT - TOOLBAR_TITLE_FONT_HEIGHT - 8) / 2;
|
||||
|
||||
toolbar->close_button = lv_button_create(obj);
|
||||
lv_obj_set_size(toolbar->close_button, TOOLBAR_HEIGHT - 4, TOOLBAR_HEIGHT - 4);
|
||||
obj_set_style_no_padding(toolbar->close_button);
|
||||
toolbar->close_button_image = lv_image_create(toolbar->close_button);
|
||||
lv_obj_align(toolbar->close_button_image, LV_ALIGN_CENTER, 0, 0);
|
||||
|
||||
// Need spacer to avoid button press glitch animation
|
||||
spacer_create(obj, title_offset_x, 1);
|
||||
|
||||
lv_obj_t* label_container = lv_obj_create(obj);
|
||||
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);
|
||||
|
||||
toolbar->title_label = lv_label_create(label_container);
|
||||
toolbar->title_label = lv_label_create(obj);
|
||||
lv_obj_set_style_text_font(toolbar->title_label, &lv_font_montserrat_18, 0); // TODO replace with size 18
|
||||
lv_obj_set_height(toolbar->title_label, TOOLBAR_TITLE_FONT_HEIGHT);
|
||||
lv_label_set_text(toolbar->title_label, title.c_str());
|
||||
lv_obj_set_pos(toolbar->title_label, 0, title_offset_y);
|
||||
lv_obj_set_style_text_align(toolbar->title_label, LV_TEXT_ALIGN_LEFT, 0);
|
||||
lv_obj_set_flex_grow(toolbar->title_label, 1);
|
||||
int32_t title_offset_x = (TOOLBAR_HEIGHT - TOOLBAR_TITLE_FONT_HEIGHT - 8) / 4 * 3;
|
||||
// Margin top doesn't work
|
||||
lv_obj_set_style_pad_top(toolbar->title_label, title_offset_x, 0);
|
||||
lv_obj_set_style_margin_left(toolbar->title_label, 8, 0);
|
||||
// Hack for margin bug where buttons in flex get rendered more narrowly
|
||||
lv_obj_set_style_margin_right(toolbar->title_label, -8, 0);
|
||||
|
||||
toolbar->action_container = lv_obj_create(obj);
|
||||
lv_obj_set_width(toolbar->action_container, LV_SIZE_CONTENT);
|
||||
@@ -112,7 +104,7 @@ void toolbar_set_nav_action(lv_obj_t* obj, const char* icon, lv_event_cb_t callb
|
||||
lv_image_set_src(toolbar->close_button_image, icon); // e.g. LV_SYMBOL_CLOSE
|
||||
}
|
||||
|
||||
uint8_t toolbar_add_action(lv_obj_t* obj, const char* icon, lv_event_cb_t callback, void* user_data) {
|
||||
lv_obj_t* toolbar_add_button_action(lv_obj_t* obj, const char* icon, lv_event_cb_t callback, void* user_data) {
|
||||
auto* toolbar = (Toolbar*)obj;
|
||||
uint8_t id = toolbar->action_count;
|
||||
tt_check(toolbar->action_count < TOOLBAR_ACTION_LIMIT, "max actions reached");
|
||||
@@ -126,7 +118,7 @@ uint8_t toolbar_add_action(lv_obj_t* obj, const char* icon, lv_event_cb_t callba
|
||||
lv_image_set_src(action_button_image, icon);
|
||||
lv_obj_align(action_button_image, LV_ALIGN_CENTER, 0, 0);
|
||||
|
||||
return id;
|
||||
return action_button;
|
||||
}
|
||||
|
||||
lv_obj_t* toolbar_add_switch_action(lv_obj_t* obj) {
|
||||
@@ -138,7 +130,7 @@ lv_obj_t* toolbar_add_switch_action(lv_obj_t* obj) {
|
||||
|
||||
lv_obj_t* toolbar_add_spinner_action(lv_obj_t* obj) {
|
||||
auto* toolbar = (Toolbar*)obj;
|
||||
return tt_spinner_create(toolbar->action_container);
|
||||
return tt::lvgl::spinner_create(toolbar->action_container);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -6,23 +6,14 @@
|
||||
namespace tt::lvgl {
|
||||
|
||||
#define TOOLBAR_HEIGHT 40
|
||||
#define TOOLBAR_ACTION_LIMIT 8
|
||||
#define TOOLBAR_TITLE_FONT_HEIGHT 18
|
||||
|
||||
typedef void(*ToolbarActionCallback)(void* _Nullable context);
|
||||
|
||||
typedef struct {
|
||||
const char* icon;
|
||||
const char* text;
|
||||
ToolbarActionCallback callback;
|
||||
void* _Nullable callback_context;
|
||||
} ToolbarAction;
|
||||
#define TOOLBAR_ACTION_LIMIT 4
|
||||
|
||||
lv_obj_t* toolbar_create(lv_obj_t* parent, const std::string& title);
|
||||
lv_obj_t* toolbar_create(lv_obj_t* parent, const app::AppContext& app);
|
||||
void toolbar_set_title(lv_obj_t* obj, const std::string& title);
|
||||
void toolbar_set_nav_action(lv_obj_t* obj, const char* icon, lv_event_cb_t callback, void* user_data);
|
||||
uint8_t toolbar_add_action(lv_obj_t* obj, const char* icon, lv_event_cb_t callback, void* user_data);
|
||||
lv_obj_t* toolbar_add_button_action(lv_obj_t* obj, const char* icon, lv_event_cb_t callback, void* user_data);
|
||||
lv_obj_t* toolbar_add_switch_action(lv_obj_t* obj);
|
||||
lv_obj_t* toolbar_add_spinner_action(lv_obj_t* obj);
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user