125 operator lv_obj_t *()
const {
return obj_; }
131 explicit operator bool()
const {
return obj_ !=
nullptr; }
146 return lv_obj_get_child_count(
obj_);
186static_assert(
sizeof(
ObjectView) ==
sizeof(
void *),
187 "ObjectView must be pointer-sized");
205template <
typename Derived>
214 Derived &
size(int32_t w, int32_t h) {
215 lv_obj_set_size(self().get(), w, h);
225 lv_obj_set_width(self().get(), w);
235 lv_obj_set_height(self().get(), h);
245 Derived &
pos(int32_t x, int32_t y) {
246 lv_obj_set_pos(self().get(), x, y);
255 lv_obj_center(self().get());
266 Derived &
align(lv_align_t a, int32_t x_ofs = 0, int32_t y_ofs = 0) {
267 lv_obj_align(self().get(), a, x_ofs, y_ofs);
276 lv_obj_add_flag(self().get(), LV_OBJ_FLAG_HIDDEN);
285 lv_obj_remove_flag(self().get(), LV_OBJ_FLAG_HIDDEN);
302 lv_obj_add_flag(self().get(), f);
312 lv_obj_remove_flag(self().get(), f);
322 lv_obj_add_state(self().get(), s);
332 lv_obj_remove_state(self().get(), s);
342 lv_obj_set_user_data(self().get(), data);
353 lv_obj_add_flag(self().get(), LV_OBJ_FLAG_CLICKABLE);
355 lv_obj_remove_flag(self().get(), LV_OBJ_FLAG_CLICKABLE);
360 Derived &self() {
return static_cast<Derived &
>(*this); }
399template <
typename Derived>
413 template <detail::StatelessCallable F>
414 Derived &
on(lv_event_code_t code, F &&fn) {
415 lv_obj_add_event_cb(self().get(),
416 static_cast<lv_event_cb_t
>(fn),
434 template <auto MemFn,
typename T>
435 Derived &
on(lv_event_code_t code, T *instance) {
436 lv_obj_add_event_cb(self().get(),
438 auto *self =
static_cast<T *
>(
439 lv_event_get_user_data(e));
452 template <detail::StatelessCallable F>
454 return on(LV_EVENT_CLICKED,
static_cast<F &&
>(fn));
464 template <auto MemFn,
typename T>
475 template <detail::StatelessCallable F>
487 template <auto MemFn,
typename T>
512template <
typename Derived>
521 lv_obj_set_style_bg_color(self().get(), c, LV_PART_MAIN);
531 lv_obj_set_style_bg_opa(self().get(), opa, LV_PART_MAIN);
541 lv_obj_set_style_border_color(self().get(), c, LV_PART_MAIN);
551 lv_obj_set_style_border_width(self().get(), w, LV_PART_MAIN);
561 lv_obj_set_style_radius(self().get(), r, LV_PART_MAIN);
571 lv_obj_set_style_pad_all(self().get(), p, LV_PART_MAIN);
581 lv_obj_set_style_pad_hor(self().get(), p, LV_PART_MAIN);
591 lv_obj_set_style_pad_ver(self().get(), p, LV_PART_MAIN);
601 lv_obj_set_style_pad_gap(self().get(), g, LV_PART_MAIN);
611 lv_obj_set_style_text_color(self().get(), c, LV_PART_MAIN);
621 lv_obj_set_style_text_font(self().get(), f, LV_PART_MAIN);
626 Derived &self() {
return static_cast<Derived &
>(*this); }
666 lv_style_init(&other.style_);
675 if (
this != &other) {
676 lv_style_reset(&style_);
677 style_ = other.style_;
678 lv_style_init(&other.style_);
687 lv_style_t *
get() {
return &style_; }
693 const lv_style_t *
get()
const {
return &style_; }
701 lv_style_set_bg_color(&style_, c);
711 lv_style_set_bg_opa(&style_, opa);
721 lv_style_set_radius(&style_, r);
731 lv_style_set_border_color(&style_, c);
741 lv_style_set_border_width(&style_, w);
751 lv_style_set_pad_all(&style_, p);
761 lv_style_set_text_color(&style_, c);
771 lv_style_set_text_font(&style_, f);
801template <std::
integral T>
808 explicit State(T initial = 0) {
809 lv_subject_init_int(&subject_,
static_cast<int32_t
>(initial));
815 ~State() { lv_subject_deinit(&subject_); }
817 State(
const State &) =
delete;
818 State &operator=(
const State &) =
delete;
824 void set(T val) { lv_subject_set_int(&subject_,
static_cast<int32_t
>(val)); }
831 return static_cast<T
>(lv_subject_get_int(
832 const_cast<lv_subject_t *
>(&subject_)));
839 operator T()
const {
return get(); }
845 State &operator++() {
set(
get() + 1);
return *
this; }
851 State &operator--() {
set(
get() - 1);
return *
this; }
857 lv_subject_t *subject() {
return &subject_; }
860 lv_subject_t subject_;
994 template <std::
integral T>
1002static_assert(
sizeof(Label) ==
sizeof(
void *),
1003 "Label must be pointer-sized");
1094static_assert(
sizeof(Bar) ==
sizeof(
void *),
1095 "Bar must be pointer-sized");
1133static_assert(
sizeof(Box) ==
sizeof(
void *),
1134 "Box must be pointer-sized");
1147 lv_obj_set_flex_flow(b.get(), LV_FLEX_FLOW_COLUMN);
1148 lv_obj_set_size(b.get(), LV_SIZE_CONTENT, LV_SIZE_CONTENT);
1159 lv_obj_set_flex_flow(b.get(), LV_FLEX_FLOW_ROW);
1160 lv_obj_set_size(b.get(), LV_SIZE_CONTENT, LV_SIZE_CONTENT);
1189template <
typename Derived>
1212 root_ =
static_cast<Derived *
>(
this)->build(parent);
1214 lv_obj_set_user_data(
root_.
get(),
this);
1217 delete_cb, LV_EVENT_DELETE,
this);
1254 lv_obj_add_flag(
root_.
get(), LV_OBJ_FLAG_HIDDEN);
1262 lv_obj_remove_flag(
root_.
get(), LV_OBJ_FLAG_HIDDEN);
1276 lv_obj_t *target =
static_cast<lv_obj_t *
>(lv_event_get_target(e));
1278 void *ud = lv_obj_get_user_data(target);
1280 return static_cast<Derived *
>(
1282 target = lv_obj_get_parent(target);
1297 static void delete_cb(lv_event_t *e) {
1299 lv_event_get_user_data(e));
C++ wrapper for an LVGL progress-bar widget.
Definition lvgl.hpp:1022
static Bar create(ObjectView parent)
Factory method — creates a new LVGL bar as a child of parent.
Definition lvgl.hpp:1035
Bar & range(int32_t min, int32_t max)
Sets the minimum and maximum values for the bar.
Definition lvgl.hpp:1066
Bar & indicator_color(lv_color_t c)
Sets the background color of the indicator (filled) part.
Definition lvgl.hpp:1076
Bar & bar_color(lv_color_t c)
Sets the background color of the bar track (unfilled) part.
Definition lvgl.hpp:1086
Bar & value(int32_t val)
Sets the current value of the bar with animation enabled.
Definition lvgl.hpp:1044
Bar(lv_obj_t *obj)
Constructs a Bar wrapping an existing LVGL bar object.
Definition lvgl.hpp:1028
Bar & value(int32_t val, lv_anim_enable_t anim)
Sets the current value of the bar with explicit animation control.
Definition lvgl.hpp:1055
C++ wrapper for a generic LVGL container object with scrolling disabled.
Definition lvgl.hpp:1113
static Box create(ObjectView parent)
Factory method — creates a new LVGL container with scrolling disabled.
Definition lvgl.hpp:1126
Box(lv_obj_t *obj)
Constructs a Box wrapping an existing LVGL object.
Definition lvgl.hpp:1119
CRTP base class for reusable, self-contained LVGL UI components.
Definition lvgl.hpp:1190
bool is_mounted() const
Returns true if the component is currently mounted.
Definition lvgl.hpp:1241
void mount(ObjectView parent)
Builds and mounts the component under the given parent.
Definition lvgl.hpp:1209
Component()=default
Default constructor — component starts in the unmounted state.
void show()
Shows the component's root widget if mounted.
Definition lvgl.hpp:1260
ObjectView root_
Non-owning view of the component's root LVGL widget.
Definition lvgl.hpp:1289
void unmount()
Unmounts and deletes the component's widget subtree.
Definition lvgl.hpp:1227
static Derived * from_event(lv_event_t *e)
Walks up the LVGL object tree from the event target to find the Derived component instance.
Definition lvgl.hpp:1275
void hide()
Hides the component's root widget if mounted.
Definition lvgl.hpp:1252
ObjectView root() const
Returns an ObjectView of the component's root widget.
Definition lvgl.hpp:1247
CRTP mixin that adds type-safe LVGL event registration to widget classes.
Definition lvgl.hpp:400
Derived & on_click(F &&fn)
Registers a stateless click callback (shorthand for on(LV_EVENT_CLICKED, fn)).
Definition lvgl.hpp:453
Derived & on_value_changed(F &&fn)
Registers a stateless value-changed callback (shorthand for on(LV_EVENT_VALUE_CHANGED,...
Definition lvgl.hpp:476
Derived & on_click(T *instance)
Registers a member function click callback.
Definition lvgl.hpp:465
Derived & on(lv_event_code_t code, F &&fn)
Registers a stateless callback for the given event code.
Definition lvgl.hpp:414
Derived & on_value_changed(T *instance)
Registers a member function value-changed callback.
Definition lvgl.hpp:488
Derived & on(lv_event_code_t code, T *instance)
Registers a member function pointer as an event callback — zero-cost trampoline.
Definition lvgl.hpp:435
C++ wrapper for an LVGL label widget.
Definition lvgl.hpp:888
Label & font(const lv_font_t *f)
Sets the font used to render the label text.
Definition lvgl.hpp:955
Label & color(lv_color_t c)
Sets the text color.
Definition lvgl.hpp:965
Label & text(const char *txt)
Sets the label text by copying the string (LVGL allocates internally).
Definition lvgl.hpp:910
Label & long_mode(lv_label_long_mode_t mode)
Sets the long-text mode (wrap, scroll, clip, etc.).
Definition lvgl.hpp:975
Label(lv_obj_t *obj)
Constructs a Label wrapping an existing LVGL label object.
Definition lvgl.hpp:894
Label & text_fmt(const char *fmt,...)
Sets the label text using a printf-style format string.
Definition lvgl.hpp:939
static Label create(ObjectView parent)
Factory method — creates a new LVGL label as a child of parent.
Definition lvgl.hpp:901
Label & text_static(const char *txt)
Sets the label text to a static string (no copy — pointer must remain valid).
Definition lvgl.hpp:924
RAII scoped lock for thread-safe access to the LVGL rendering context.
Definition lvgl.hpp:66
LvglGuard()
Acquires the LVGL lock, blocking until it is available.
Definition lvgl.hpp:71
~LvglGuard()
Releases the LVGL lock.
Definition lvgl.hpp:76
CRTP mixin that adds fluent layout and visibility setters to widget classes.
Definition lvgl.hpp:206
Derived & hide()
Hides the object by adding LV_OBJ_FLAG_HIDDEN.
Definition lvgl.hpp:275
Derived & user_data(void *data)
Stores an arbitrary user data pointer on the LVGL object.
Definition lvgl.hpp:341
Derived & show()
Shows the object by removing LV_OBJ_FLAG_HIDDEN.
Definition lvgl.hpp:284
Derived & height(int32_t h)
Sets the height of the object.
Definition lvgl.hpp:234
Derived & clickable(bool on)
Enables or disables click events on the object.
Definition lvgl.hpp:351
Derived & width(int32_t w)
Sets the width of the object.
Definition lvgl.hpp:224
Derived & size(int32_t w, int32_t h)
Sets both width and height of the object.
Definition lvgl.hpp:214
Derived & align(lv_align_t a, int32_t x_ofs=0, int32_t y_ofs=0)
Aligns the object to an anchor with an optional offset.
Definition lvgl.hpp:266
Derived & add_state(lv_state_t s)
Adds one or more object states.
Definition lvgl.hpp:321
Derived & visible(bool v)
Conditionally shows or hides the object.
Definition lvgl.hpp:294
Derived & pos(int32_t x, int32_t y)
Sets the position of the object relative to its parent.
Definition lvgl.hpp:245
Derived & center()
Centers the object within its parent.
Definition lvgl.hpp:254
Derived & remove_flag(lv_obj_flag_t f)
Removes one or more object flags.
Definition lvgl.hpp:311
Derived & add_flag(lv_obj_flag_t f)
Adds one or more object flags.
Definition lvgl.hpp:301
Derived & remove_state(lv_state_t s)
Removes one or more object states.
Definition lvgl.hpp:331
Non-owning, pointer-sized wrapper around an lv_obj_t*.
Definition lvgl.hpp:102
ObjectView(lv_obj_t *obj)
Constructs an ObjectView wrapping the given lv_obj_t*.
Definition lvgl.hpp:113
uint32_t child_count() const
Returns the number of direct children of this object.
Definition lvgl.hpp:145
void clean()
Deletes all children of this object without deleting the object itself.
Definition lvgl.hpp:171
static ObjectView screen_active()
Returns an ObjectView wrapping the currently active screen.
Definition lvgl.hpp:177
int32_t get_width() const
Returns the current rendered width of this object.
Definition lvgl.hpp:153
int32_t get_height() const
Returns the current rendered height of this object.
Definition lvgl.hpp:159
lv_obj_t * get() const
Returns the raw lv_obj_t* pointer.
Definition lvgl.hpp:119
ObjectView()
Constructs a null ObjectView (no associated LVGL object).
Definition lvgl.hpp:107
lv_obj_t * obj_
Raw pointer to the wrapped LVGL object.
Definition lvgl.hpp:183
void del()
Deletes the LVGL object and all its children, then nulls the pointer.
Definition lvgl.hpp:166
ObjectView parent() const
Returns an ObjectView wrapping the parent of this object.
Definition lvgl.hpp:137
CRTP mixin that adds inline per-object style setters to widget classes.
Definition lvgl.hpp:513
Derived & radius(int32_t r)
Sets the corner radius.
Definition lvgl.hpp:560
Derived & pad_gap(int32_t g)
Sets the gap between children in flex/grid layouts.
Definition lvgl.hpp:600
Derived & pad_hor(int32_t p)
Sets horizontal (left + right) padding.
Definition lvgl.hpp:580
Derived & border_width(int32_t w)
Sets the border width in pixels.
Definition lvgl.hpp:550
Derived & text_font(const lv_font_t *f)
Sets the font used to render text.
Definition lvgl.hpp:620
Derived & pad_all(int32_t p)
Sets uniform padding on all four sides.
Definition lvgl.hpp:570
Derived & bg_color(lv_color_t c)
Sets the background color of the object.
Definition lvgl.hpp:520
Derived & pad_ver(int32_t p)
Sets vertical (top + bottom) padding.
Definition lvgl.hpp:590
Derived & border_color(lv_color_t c)
Sets the border color.
Definition lvgl.hpp:540
Derived & text_color(lv_color_t c)
Sets the text color.
Definition lvgl.hpp:610
Derived & bg_opa(lv_opa_t opa)
Sets the background opacity.
Definition lvgl.hpp:530
RAII wrapper around an lv_style_t object.
Definition lvgl.hpp:646
const lv_style_t * get() const
Returns a const pointer to the underlying lv_style_t.
Definition lvgl.hpp:693
Style & pad_all(int32_t p)
Sets uniform padding on all four sides.
Definition lvgl.hpp:750
Style & border_color(lv_color_t c)
Sets the border color.
Definition lvgl.hpp:730
Style & bg_opa(lv_opa_t opa)
Sets the background opacity.
Definition lvgl.hpp:710
Style()
Constructs and initialises an empty LVGL style.
Definition lvgl.hpp:651
Style & operator=(Style &&other) noexcept
Move-assignment operator — transfers the style data and reinitialises the source.
Definition lvgl.hpp:674
Style & border_width(int32_t w)
Sets the border width in pixels.
Definition lvgl.hpp:740
~Style()
Destroys the style, releasing any resources held by LVGL.
Definition lvgl.hpp:656
Style & bg_color(lv_color_t c)
Sets the background color.
Definition lvgl.hpp:700
Style & text_color(lv_color_t c)
Sets the text color.
Definition lvgl.hpp:760
Style & text_font(const lv_font_t *f)
Sets the font used to render text.
Definition lvgl.hpp:770
lv_style_t * get()
Returns a mutable pointer to the underlying lv_style_t.
Definition lvgl.hpp:687
Style & radius(int32_t r)
Sets the corner radius.
Definition lvgl.hpp:720
Style(Style &&other) noexcept
Move constructor — transfers the style data and reinitialises the source.
Definition lvgl.hpp:665
Concept satisfied by callables that are directly convertible to void(*)(lv_event_t*).
Definition lvgl.hpp:379
int get(unsigned int port, unsigned int pin)
Reads the current logic level of a GPIO pin.
Definition gpio.hpp:62
int set(unsigned int port, unsigned int pin, int value)
Drives a GPIO output pin to the specified logic level.
Definition gpio.hpp:51
C++ abstractions for the LVGL embedded GUI library.
Box hbox(ObjectView parent)
Creates a horizontal flex container (LV_FLEX_FLOW_ROW) sized to its content.
Definition lvgl.hpp:1157
Box vbox(ObjectView parent)
Creates a vertical flex container (LV_FLEX_FLOW_COLUMN) sized to its content.
Definition lvgl.hpp:1145