From 7e085023eecb0150d926916fc4e0ed7f656084b0 Mon Sep 17 00:00:00 2001 From: Christos Themelis Date: Fri, 6 Feb 2026 20:49:12 +0200 Subject: [PATCH] ui helpers --- examples/simple_secure_chat_ui/lvBase.h | 74 +++++++++++++++++++++++ examples/simple_secure_chat_ui/lvButton.h | 16 +++++ examples/simple_secure_chat_ui/lvLabel.h | 41 +++++++++++++ examples/simple_secure_chat_ui/lvList.h | 25 ++++++++ examples/simple_secure_chat_ui/lvObj.h | 30 +++++++++ 5 files changed, 186 insertions(+) create mode 100644 examples/simple_secure_chat_ui/lvBase.h create mode 100644 examples/simple_secure_chat_ui/lvButton.h create mode 100644 examples/simple_secure_chat_ui/lvLabel.h create mode 100644 examples/simple_secure_chat_ui/lvList.h create mode 100644 examples/simple_secure_chat_ui/lvObj.h diff --git a/examples/simple_secure_chat_ui/lvBase.h b/examples/simple_secure_chat_ui/lvBase.h new file mode 100644 index 000000000..dc4fd89fd --- /dev/null +++ b/examples/simple_secure_chat_ui/lvBase.h @@ -0,0 +1,74 @@ +#include "lvgl.h" + +#ifndef LV_BASE_h +#define LV_BASE_h +class LvBase { +public: + operator lv_obj_t*() const { return obj; } + lv_obj_t* raw() const { return obj; } + + LvBase& width(int v) { + lv_obj_set_width(obj, v == 100 ? lv_pct(100) : v); + return *this; + } + + LvBase& height(int v) { + lv_obj_set_height(obj, v); + return *this; + } + + LvBase& size(int w, int h) { + lv_obj_set_size(obj, w, h); + return *this; + } + + LvBase& align(lv_align_t a, int x = 0, int y = 0) { + lv_obj_align(obj, a, x, y); + return *this; + } + + LvBase& pos(int x, int y) { + lv_obj_set_pos(obj, x, y); + return *this; + } + + LvBase& padAll(int v) { + lv_obj_set_style_pad_all(obj, v, 0); + return *this; + } + + LvBase& bgOpa(int v) { + lv_obj_set_style_bg_opa(obj, v, 0); + return *this; + } + + LvBase& bgColor(uint32_t hex) { + lv_obj_set_style_bg_color(obj, lv_color_hex(hex), 0); + return *this; + } + + LvBase& border(int w) { + lv_obj_set_style_border_width(obj, w, 0); + return *this; + } + + LvBase& radius(int r) { + lv_obj_set_style_radius(obj, r, 0); + return *this; + } + + LvBase& noScroll() { + lv_obj_clear_flag(obj, LV_OBJ_FLAG_SCROLLABLE); + return *this; + } + + LvBase& clickable(bool v = true) { + v ? lv_obj_add_flag(obj, LV_OBJ_FLAG_CLICKABLE) + : lv_obj_clear_flag(obj, LV_OBJ_FLAG_CLICKABLE); + return *this; + } + +protected: + lv_obj_t* obj = nullptr; +}; +#endif \ No newline at end of file diff --git a/examples/simple_secure_chat_ui/lvButton.h b/examples/simple_secure_chat_ui/lvButton.h new file mode 100644 index 000000000..aa192e23f --- /dev/null +++ b/examples/simple_secure_chat_ui/lvButton.h @@ -0,0 +1,16 @@ +#include "lvBase.h" + +#ifndef LV_BUTTON_h +#define LV_BUTTON_h +class LvButton : public LvBase { +public: + explicit LvButton(lv_obj_t* parent) { + obj = lv_btn_create(parent); + } + + LvButton& onClick(lv_event_cb_t cb, void* user = nullptr) { + lv_obj_add_event_cb(obj, cb, LV_EVENT_CLICKED, user); + return *this; + } +}; +#endif \ No newline at end of file diff --git a/examples/simple_secure_chat_ui/lvLabel.h b/examples/simple_secure_chat_ui/lvLabel.h new file mode 100644 index 000000000..eb5aae140 --- /dev/null +++ b/examples/simple_secure_chat_ui/lvLabel.h @@ -0,0 +1,41 @@ +#include "lvBase.h" + + +#ifndef LV_LABEL_h +#define LV_LABEL_h +class LvLabel : public LvBase { +public: + explicit LvLabel(lv_obj_t* parent, const char* text = "") { + obj = lv_label_create(parent); + lv_label_set_text(obj, text); + } + + LvLabel& text(const char* t) { + lv_label_set_text(obj, t); + return *this; + } + + LvLabel& font(const lv_font_t* f) { + lv_obj_set_style_text_font(obj, f, 0); + return *this; + } + + LvLabel& textColor(uint32_t hex) { + lv_obj_set_style_text_color(obj, lv_color_hex(hex), 0); + return *this; + } + + LvLabel& opa(int v) { + lv_obj_set_style_text_opa(obj, v, 0); + return *this; + } + + LvLabel& wrap(bool v = true) { + lv_label_set_long_mode( + obj, + v ? LV_LABEL_LONG_WRAP : LV_LABEL_LONG_CLIP + ); + return *this; + } +}; +#endif \ No newline at end of file diff --git a/examples/simple_secure_chat_ui/lvList.h b/examples/simple_secure_chat_ui/lvList.h new file mode 100644 index 000000000..9ef1794c9 --- /dev/null +++ b/examples/simple_secure_chat_ui/lvList.h @@ -0,0 +1,25 @@ +#include "lvBase.h" + +#ifndef LV_LIST_h +#define LV_LIST_h + +class LvList : public LvBase { +public: + explicit LvList(lv_obj_t* parent) { + obj = lv_list_create(parent); + } + + LvList& transparent() { + lv_obj_set_style_bg_opa(obj, LV_OPA_TRANSP, 0); + lv_obj_set_style_border_width(obj, 0, 0); + lv_obj_set_style_bg_opa(obj, LV_OPA_TRANSP, LV_PART_ITEMS); + lv_obj_set_style_border_width(obj, 0, LV_PART_ITEMS); + return *this; + } + + LvList& padRow(int v) { + lv_obj_set_style_pad_row(obj, v, 0); + return *this; + } +}; +#endif \ No newline at end of file diff --git a/examples/simple_secure_chat_ui/lvObj.h b/examples/simple_secure_chat_ui/lvObj.h new file mode 100644 index 000000000..30ccc857c --- /dev/null +++ b/examples/simple_secure_chat_ui/lvObj.h @@ -0,0 +1,30 @@ +#include "lvBase.h" + +#ifndef LV_OBJ_h +#define LV_OBJ_h +class LvObj : public LvBase { +public: + explicit LvObj(lv_obj_t* parent) { + obj = lv_obj_create(parent); + } + + explicit LvObj(lv_obj_t* existing, bool wrapOnly) { + obj = existing; + } + + // Fluent Flex + LvObj& flexFlow(lv_flex_flow_t flow) { + lv_obj_set_flex_flow(obj, flow); + return *this; + } + + LvObj& flexAlign( + lv_flex_align_t main, + lv_flex_align_t cross, + lv_flex_align_t track = LV_FLEX_ALIGN_START + ) { + lv_obj_set_flex_align(obj, main, cross, track); + return *this; + } +}; +#endif \ No newline at end of file