mirror of https://github.com/meshcore-dev/MeshCore
5 changed files with 186 additions and 0 deletions
@ -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 |
|||
@ -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 |
|||
@ -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 |
|||
@ -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 |
|||
@ -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 |
|||
Loading…
Reference in new issue