lv_observer.h
API reference for lv_observer.h
Functions
lv_subject_set_external_data
Attaches external user data to an integer Subject with lifecycle management.
Associates arbitrary user-defined data with an LVGL observer and registers a destructor callback that will be automatically invoked when the observer is deleted. This enables:
- Safe resource cleanup through the destructor mechanism
- Contextual data storage for observer callbacks
- Proper memory management for observer-related resources
void lv_subject_set_external_data(lv_subject_t *subject, void *data, void(*free_cb)(void *data))| Name | Type | Description |
|---|---|---|
subject | lv_subject_t * | pointer to Subject |
data | void * | User-defined data pointer to associate |
free_cb | void(*)(void *data) | Cleanup function called when: - Observer is explicitly deleted - Observed object is deleted - New data replaces current association NULL indicates no cleanup required |
lv_subject_set_int
Set value of an integer Subject and notify Observers.
void lv_subject_set_int(lv_subject_t *subject, int32_t value)| Name | Type | Description |
|---|---|---|
subject | lv_subject_t * | pointer to Subject |
value | int32_t | new value |
lv_subject_set_min_value_int
Set a minimum value for an integer subject
void lv_subject_set_min_value_int(lv_subject_t *subject, int32_t min_value)| Name | Type | Description |
|---|---|---|
subject | lv_subject_t * | pointer to Subject |
min_value | int32_t | the minimum value |
lv_subject_set_max_value_int
Set a maximum value for an integer subject
void lv_subject_set_max_value_int(lv_subject_t *subject, int32_t max_value)| Name | Type | Description |
|---|---|---|
subject | lv_subject_t * | pointer to Subject |
max_value | int32_t | the maximum value |
lv_subject_set_float
Set value of an float Subject and notify Observers.
void lv_subject_set_float(lv_subject_t *subject, float value)| Name | Type | Description |
|---|---|---|
subject | lv_subject_t * | pointer to Subject |
value | float | new value |
lv_subject_set_min_value_float
Set a minimum value for a float subject
void lv_subject_set_min_value_float(lv_subject_t *subject, float min_value)| Name | Type | Description |
|---|---|---|
subject | lv_subject_t * | pointer to Subject |
min_value | float | the minimum value |
lv_subject_set_max_value_float
Set a maximum value for a float subject
void lv_subject_set_max_value_float(lv_subject_t *subject, float max_value)| Name | Type | Description |
|---|---|---|
subject | lv_subject_t * | pointer to Subject |
max_value | float | the maximum value |
lv_subject_set_pointer
Set value of a pointer Subject and notify Observers (regardless of whether it changed).
void lv_subject_set_pointer(lv_subject_t *subject, void *ptr)| Name | Type | Description |
|---|---|---|
subject | lv_subject_t * | pointer to Subject |
ptr | void * | new value |
lv_subject_set_color
Set value of a color Subject and notify Observers if it changed.
void lv_subject_set_color(lv_subject_t *subject, lv_color_t color)| Name | Type | Description |
|---|---|---|
subject | lv_subject_t * | pointer to Subject |
color | lv_color_t | new value |
lv_obj_set_subject_increment_event_min_value
Set the minimum subject value to set by the event
void lv_obj_set_subject_increment_event_min_value(lv_obj_t *obj, lv_subject_increment_dsc_t *dsc, int32_t min_value)| Name | Type | Description |
|---|---|---|
obj | lv_obj_t * | pointer to the Widget to which the event is attached |
dsc | lv_subject_increment_dsc_t * | pointer to the descriptor returned by lv_obj_add_subject_increment_event() |
min_value | int32_t | the minimum value to set |
lv_obj_set_subject_increment_event_max_value
Set the maximum subject value to set by the event
void lv_obj_set_subject_increment_event_max_value(lv_obj_t *obj, lv_subject_increment_dsc_t *dsc, int32_t max_value)| Name | Type | Description |
|---|---|---|
obj | lv_obj_t * | pointer to the Widget to which the event is attached |
dsc | lv_subject_increment_dsc_t * | pointer to the descriptor returned by lv_obj_add_subject_increment_event() |
max_value | int32_t | the maximum value to set |
lv_obj_set_subject_increment_event_rollover
Set what to do when the min/max value is crossed.
void lv_obj_set_subject_increment_event_rollover(lv_obj_t *obj, lv_subject_increment_dsc_t *dsc, bool rollover)| Name | Type | Description |
|---|---|---|
obj | lv_obj_t * | pointer to the Widget to which the event is attached |
dsc | lv_subject_increment_dsc_t * | pointer to the descriptor returned by lv_obj_add_subject_increment_event() |
rollover | bool | false: stop at the min/max value; true: jump to the other end |
the subject also can have min/max values and always the smaller range will be considered
lv_obj_add_subject_set_int_event
Set the value of an integer subject.
void lv_obj_add_subject_set_int_event(lv_obj_t *obj, lv_subject_t *subject, lv_event_code_t trigger, int32_t value)| Name | Type | Description |
|---|---|---|
obj | lv_obj_t * | pointer to a widget |
subject | lv_subject_t * | pointer to a subject to change |
trigger | lv_event_code_t | the trigger on which the subject should be changed |
value | int32_t | the value to set |
lv_obj_add_subject_set_float_event
Set the value of a float subject.
void lv_obj_add_subject_set_float_event(lv_obj_t *obj, lv_subject_t *subject, lv_event_code_t trigger, float value)| Name | Type | Description |
|---|---|---|
obj | lv_obj_t * | pointer to a widget |
subject | lv_subject_t * | pointer to a subject to change |
trigger | lv_event_code_t | the trigger on which the subject should be changed |
value | float | the value to set |
lv_obj_add_subject_set_string_event
Set the value of a string subject.
void lv_obj_add_subject_set_string_event(lv_obj_t *obj, lv_subject_t *subject, lv_event_code_t trigger, const char *value)| Name | Type | Description |
|---|---|---|
obj | lv_obj_t * | pointer to a widget |
subject | lv_subject_t * | pointer to a subject to change |
trigger | lv_event_code_t | the trigger on which the subject should be changed |
value | const char * | the value to set |
Enums
lv_subject_type_t
Values for lv_subject_t's type field
| Name | Value | Description |
|---|---|---|
LV_SUBJECT_TYPE_INVALID | 0 | indicates Subject not initialized yet |
LV_SUBJECT_TYPE_NONE | 1 | a null value like None or NILt |
LV_SUBJECT_TYPE_INT | 2 | an int32_t |
LV_SUBJECT_TYPE_FLOAT | 3 | a float, requires LV_USE_FLOAT 1 |
LV_SUBJECT_TYPE_POINTER | 4 | a void pointer |
LV_SUBJECT_TYPE_COLOR | 5 | an lv_color_t |
LV_SUBJECT_TYPE_GROUP | 6 | an array of Subjects |
LV_SUBJECT_TYPE_STRING | 7 | a char pointer |
Structs
lv_subject_value_t
A common type to handle all the various observable types in the same way
| Member | Type | Description |
|---|---|---|
num | int32_t | Integer number (opacity, enums, booleans or "normal" numbers) |
pointer | const void * | Constant pointer (string buffer, format string, font, cone text, etc.) |
color | lv_color_t | Color |
float_v | float | Floating point value |
_lv_subject_t
The Subject (an observable value)
| Member | Type | Description |
|---|---|---|
ext_data | lv_ext_data_t | |
subs_ll | lv_ll_t | Subscribers |
value | lv_subject_value_t | Current value |
prev_value | lv_subject_value_t | Previous value |
min_value | lv_subject_value_t | Minimum value for min. int or float |
max_value | lv_subject_value_t | Maximum value for max. int or float |
user_data | void * | Additional parameter, can be used freely by user |
type | uint32_t | One of the LV_SUBJECT_TYPE_... values |
size | uint32_t | String buffer size or group length |
notify_restart_query | uint32_t | If an Observer was deleted during notification, start notifying from the beginning. |
Typedefs
lv_observer_cb_t
typedef void(* lv_observer_cb_t) (lv_observer_t *observer, lv_subject_t *subject)Callback called to notify Observer that Subject's value has changed
Used by 3 functions
lv_subject_add_observer— paramobserver_cblv_subject_add_observer_obj— paramobserver_cblv_subject_add_observer_with_target— paramobserver_cb
Dependencies
Indirect dependencies
lv_anim.hlv_area.hlv_array.hlv_assert.hlv_bidi.hlv_color.hlv_color_op.hlv_conf_internal.hlv_conf_kconfig.hlv_display.hlv_draw.hlv_draw_arc.hlv_draw_blur.hlv_draw_buf.hlv_draw_image.hlv_draw_label.hlv_draw_line.hlv_draw_rect.hlv_draw_triangle.hlv_event.hlv_flex.hlv_font.hlv_fs.hlv_grad.hlv_grid.hlv_group.hlv_image_decoder.hlv_image_dsc.hlv_indev.hlv_layout.hlv_ll.hlv_log.hlv_math.hlv_matrix.hlv_mem.hlv_obj_class.hlv_obj_draw.hlv_obj_event.hlv_obj_pos.hlv_obj_property.hlv_obj_property_names.hlv_obj_scroll.hlv_obj_style.hlv_obj_style_gen.hlv_obj_tree.hlv_palette.hlv_profiler.hlv_profiler_builtin.hlv_sprintf.hlv_string.hlv_style.hlv_style_gen.hlv_style_properties.hlv_symbol_def.hlv_text.hlv_tick.hlv_timer.hlv_types.h
How is this guide?
Last updated on