oveRTOS C++ API
C++20 RAII wrappers for the oveRTOS C API
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
ove::lvgl::Component< Derived > Class Template Reference

CRTP base class for reusable, self-contained LVGL UI components. More...

#include <lvgl.hpp>

Collaboration diagram for ove::lvgl::Component< Derived >:
Collaboration graph
[legend]

Public Member Functions

 Component ()=default
 Default constructor — component starts in the unmounted state.
 
 Component (const Component &)=delete
 
Componentoperator= (const Component &)=delete
 
void mount (ObjectView parent)
 Builds and mounts the component under the given parent.
 
void unmount ()
 Unmounts and deletes the component's widget subtree.
 
bool is_mounted () const
 Returns true if the component is currently mounted.
 
ObjectView root () const
 Returns an ObjectView of the component's root widget.
 
void hide ()
 Hides the component's root widget if mounted.
 
void show ()
 Shows the component's root widget if mounted.
 

Static Public Member Functions

static Derived * from_event (lv_event_t *e)
 Walks up the LVGL object tree from the event target to find the Derived component instance.
 

Protected Attributes

ObjectView root_
 Non-owning view of the component's root LVGL widget.
 

Detailed Description

template<typename Derived>
class ove::lvgl::Component< Derived >

CRTP base class for reusable, self-contained LVGL UI components.

A Component encapsulates a subtree of LVGL widgets behind a mount() / unmount() lifecycle. The derived class must implement a build(ObjectView parent) method that constructs and returns the root widget of the component.

The root object's user-data pointer is set to this so that event handlers can recover the component instance via from_event(). An internal LV_EVENT_DELETE callback clears the cached root reference if the LVGL object tree is deleted externally (e.g., by a screen transition).

Template Parameters
DerivedThe concrete component class. Must implement: ObjectView build(ObjectView parent).
Note
Non-copyable.
All methods must be called from within the LVGL task context or while holding an LvglGuard lock.

Member Function Documentation

◆ mount()

template<typename Derived >
void ove::lvgl::Component< Derived >::mount ( ObjectView  parent)
inline

Builds and mounts the component under the given parent.

Calls Derived::build(parent) to create the widget subtree, stores the component pointer in the root's user-data slot, and registers an internal LV_EVENT_DELETE callback. If the component is already mounted, this call is a no-op.

Parameters
[in]parentThe parent ObjectView to attach the component to.

◆ unmount()

template<typename Derived >
void ove::lvgl::Component< Derived >::unmount ( )
inline

Unmounts and deletes the component's widget subtree.

The internal LV_EVENT_DELETE callback is bypassed by clearing root_ before calling lv_obj_delete(). If the component is not mounted, this call is a no-op.

◆ is_mounted()

template<typename Derived >
bool ove::lvgl::Component< Derived >::is_mounted ( ) const
inline

Returns true if the component is currently mounted.

Returns
true when the root widget exists.

◆ root()

template<typename Derived >
ObjectView ove::lvgl::Component< Derived >::root ( ) const
inline

Returns an ObjectView of the component's root widget.

Returns
The root widget, or a null ObjectView if not mounted.

◆ from_event()

template<typename Derived >
static Derived * ove::lvgl::Component< Derived >::from_event ( lv_event_t *  e)
inlinestatic

Walks up the LVGL object tree from the event target to find the Derived component instance.

Retrieves the user-data pointer stored by mount() from each ancestor until a non-null pointer is found, then casts it to Derived*.

Parameters
[in]eThe LVGL event whose target is the starting point of the walk.
Returns
Pointer to the Derived component, or nullptr if not found.

The documentation for this class was generated from the following file: