cleanup and fixes for widgets

This commit is contained in:
Ken Van Hoeylandt 2024-01-03 14:59:10 +01:00
parent bb047b4a5f
commit eed990217f
6 changed files with 34 additions and 2 deletions

View File

@ -0,0 +1,9 @@
#include "spacer.h"
#include "widgets.h"
lv_obj_t* spacer(lv_obj_t* parent, lv_coord_t width, lv_coord_t height) {
lv_obj_t* spacer = lv_obj_create(parent);
lv_obj_set_size(spacer, width, height);
lv_obj_set_style_bg_invisible(spacer);
return spacer;
}

View File

@ -0,0 +1,13 @@
#pragma once
#include "lvgl.h"
#ifdef __cplusplus
extern "C" {
#endif
lv_obj_t* spacer(lv_obj_t* parent, lv_coord_t width, lv_coord_t height);
#ifdef __cplusplus
}
#endif

View File

@ -26,9 +26,12 @@ void toolbar(lv_obj_t* parent, lv_coord_t offset_y, const AppManifest* manifest)
lv_img_set_src(close_button_image, LV_SYMBOL_CLOSE);
lv_obj_align(close_button_image, LV_ALIGN_CENTER, 0, 0);
// Need spacer to avoid button press glitch animation
spacer(toolbar, 2, 1);
lv_obj_t* label_container = lv_obj_create(toolbar);
lv_obj_set_style_no_padding(label_container);
lv_obj_set_height(label_container, LV_PCT(100));
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* label = lv_label_create(label_container);

View File

@ -7,7 +7,7 @@ extern "C" {
#endif
#define TOP_BAR_ICON_SIZE 18
#define TOP_BAR_HEIGHT (TOP_BAR_ICON_SIZE + 2)
#define TOP_BAR_HEIGHT (TOP_BAR_ICON_SIZE + 4) // 4 extra pixels for border and outline
void top_bar(lv_obj_t* parent);

View File

@ -5,6 +5,11 @@ void lv_obj_set_style_bg_blacken(lv_obj_t* obj) {
lv_obj_set_style_border_color(obj, lv_color_black(), 0);
}
void lv_obj_set_style_bg_invisible(lv_obj_t* obj) {
lv_obj_set_style_bg_opa(obj, 0, 0);
lv_obj_set_style_border_opa(obj, 0, 0);
}
void lv_obj_set_style_no_padding(lv_obj_t* obj) {
lv_obj_set_style_pad_all(obj, LV_STATE_DEFAULT, 0);
lv_obj_set_style_pad_gap(obj, LV_STATE_DEFAULT, 0);

View File

@ -2,12 +2,14 @@
#include "top_bar.h"
#include "toolbar.h"
#include "spacer.h"
#ifdef __cplusplus
extern "C" {
#endif
void lv_obj_set_style_bg_blacken(lv_obj_t* obj);
void lv_obj_set_style_bg_invisible(lv_obj_t* obj);
void lv_obj_set_style_no_padding(lv_obj_t* obj);
#ifdef __cplusplus