lv_observer.h
Typedefs
-
typedef void (*lv_observer_cb_t)(lv_observer_t *observer, lv_subject_t *subject)
Callback called when the observed value changes
- Param observer:
pointer to the observer of the callback
- Param subject:
pointer to the subject of the observer
Enums
-
enum lv_subject_type_t
Values for lv_submect_t's
type
field.Values:
-
enumerator LV_SUBJECT_TYPE_INVALID
indicates subject not initialized yet
-
enumerator LV_SUBJECT_TYPE_NONE
a null value like None or NILt
-
enumerator LV_SUBJECT_TYPE_INT
an int32_t
-
enumerator LV_SUBJECT_TYPE_POINTER
a void pointer
-
enumerator LV_SUBJECT_TYPE_COLOR
an lv_color_t
-
enumerator LV_SUBJECT_TYPE_GROUP
an array of subjects
-
enumerator LV_SUBJECT_TYPE_STRING
a char pointer
-
enumerator LV_SUBJECT_TYPE_INVALID
Functions
-
void lv_subject_init_int(lv_subject_t *subject, int32_t value)
Initialize an integer type subject
- 参数:
subject -- pointer to the subject
value -- initial value
-
void lv_subject_set_int(lv_subject_t *subject, int32_t value)
Set the value of an integer subject. It will notify all the observers as well.
- 参数:
subject -- pointer to the subject
value -- the new value
-
int32_t lv_subject_get_int(lv_subject_t *subject)
Get the current value of an integer subject
- 参数:
subject -- pointer to the subject
- 返回:
the current value
-
int32_t lv_subject_get_previous_int(lv_subject_t *subject)
Get the previous value of an integer subject
- 参数:
subject -- pointer to the subject
- 返回:
the current value
-
void lv_subject_init_string(lv_subject_t *subject, char *buf, char *prev_buf, size_t size, const char *value)
Initialize a string type subject
备注
the string subject stores the whole string, not only a pointer
- 参数:
subject -- pointer to the subject
buf -- pointer to a buffer to store the string
prev_buf -- pointer to a buffer to store the previous string, can be NULL if not used
size -- size of the buffer
value -- initial value as a string, e.g. "hello"
-
void lv_subject_copy_string(lv_subject_t *subject, const char *buf)
Copy a string to a subject. It will notify all the observers as well.
- 参数:
subject -- pointer to the subject
buf -- the new string
-
const char *lv_subject_get_string(lv_subject_t *subject)
Get the current value of an string subject
- 参数:
subject -- pointer to the subject
- 返回:
pointer to the buffer containing the current value
-
const char *lv_subject_get_previous_string(lv_subject_t *subject)
Get the previous value of an string subject
备注
NULL will be returned if NULL was passed in
lv_subject_init_string()
asprev_buf
- 参数:
subject -- pointer to the subject
- 返回:
pointer to the buffer containing the current value
-
void lv_subject_init_pointer(lv_subject_t *subject, void *value)
Initialize an pointer type subject
- 参数:
subject -- pointer to the subject
value -- initial value
-
void lv_subject_set_pointer(lv_subject_t *subject, void *ptr)
Set the value of a pointer subject. It will notify all the observers as well.
- 参数:
subject -- pointer to the subject
ptr -- new value
-
const void *lv_subject_get_pointer(lv_subject_t *subject)
Get the current value of a pointer subject
- 参数:
subject -- pointer to the subject
- 返回:
current value
-
const void *lv_subject_get_previous_pointer(lv_subject_t *subject)
Get the previous value of a pointer subject
- 参数:
subject -- pointer to the subject
- 返回:
current value
-
void lv_subject_init_color(lv_subject_t *subject, lv_color_t color)
Initialize an color type subject
- 参数:
subject -- pointer to the subject
color -- initial value
-
void lv_subject_set_color(lv_subject_t *subject, lv_color_t color)
Set the value of a color subject. It will notify all the observers as well.
- 参数:
subject -- pointer to the subject
color -- new value
-
lv_color_t lv_subject_get_color(lv_subject_t *subject)
Get the current value of a color subject
- 参数:
subject -- pointer to the subject
- 返回:
current value
-
lv_color_t lv_subject_get_previous_color(lv_subject_t *subject)
Get the previous value of a color subject
- 参数:
subject -- pointer to the subject
- 返回:
current value
-
void lv_subject_init_group(lv_subject_t *subject, lv_subject_t *list[], uint32_t list_len)
Initialize a subject group
- 参数:
subject -- pointer to the subject
list -- list of other subject addresses, any of these changes
subject
will be notifiedlist_len -- number of elements in
list
-
void lv_subject_deinit(lv_subject_t *subject)
Remove all the observers from a subject and free all allocated memories in it
备注
objects added with
lv_subject_add_observer_obj
should be already deleted or removed manually.- 参数:
subject -- pointer to the subject
-
lv_subject_t *lv_subject_get_group_element(lv_subject_t *subject, int32_t index)
Get an element from the subject group's list
- 参数:
subject -- pointer to the subject
index -- index of the element to get
- 返回:
pointer a subject from the list, or NULL if the index is out of bounds
-
lv_observer_t *lv_subject_add_observer(lv_subject_t *subject, lv_observer_cb_t observer_cb, void *user_data)
Add an observer to a subject. When the subject changes
observer_cb
will be called.- 参数:
subject -- pointer to the subject
observer_cb -- callback to call
user_data -- optional user data
- 返回:
pointer to the created observer
-
lv_observer_t *lv_subject_add_observer_obj(lv_subject_t *subject, lv_observer_cb_t observer_cb, lv_obj_t *obj, void *user_data)
Add an observer to a subject for an object. When the object is deleted, it will be removed from the subject automatically.
- 参数:
subject -- pointer to the subject
observer_cb -- callback to call
obj -- pointer to an object
user_data -- optional user data
- 返回:
pointer to the created observer
-
lv_observer_t *lv_subject_add_observer_with_target(lv_subject_t *subject, lv_observer_cb_t observer_cb, void *target, void *user_data)
Add an observer to a subject and also save a target.
- 参数:
subject -- pointer to the subject
observer_cb -- callback to call
target -- pointer to any data
user_data -- optional user data
- 返回:
pointer to the created observer
-
void lv_observer_remove(lv_observer_t *observer)
Remove an observer from its subject
- 参数:
observer -- pointer to an observer
-
void lv_obj_remove_from_subject(lv_obj_t *obj, lv_subject_t *subject)
Remove the observers of an object from a subject or all subjects
备注
This function can be used e.g. when an object's subject(s) needs to be replaced by other subject(s)
- 参数:
obj -- the object whose observers should be removed
subject -- the subject to remove the object from, or
NULL
to remove from all subjects
-
void *lv_observer_get_target(lv_observer_t *observer)
Get the target of an observer
- 参数:
observer -- pointer to an observer
- 返回:
pointer to the saved target
-
lv_obj_t *lv_observer_get_target_obj(lv_observer_t *observer)
Get the target object of the observer. It's the same as
lv_observer_get_target
and added only for semantic reasons- 参数:
observer -- pointer to an observer
- 返回:
pointer to the saved object target
-
void *lv_observer_get_user_data(const lv_observer_t *observer)
Get the user data of the observer.
- 参数:
observer -- pointer to an observer
- 返回:
void pointer to the saved user data
-
void lv_subject_notify(lv_subject_t *subject)
Notify all observers of subject
- 参数:
subject -- pointer to a subject
-
lv_observer_t *lv_obj_bind_flag_if_eq(lv_obj_t *obj, lv_subject_t *subject, lv_obj_flag_t flag, int32_t ref_value)
Set an object flag if an integer subject's value is equal to a reference value, clear the flag otherwise
- 参数:
obj -- pointer to an object
subject -- pointer to a subject
flag -- flag to set or clear (e.g.
LV_OBJ_FLAG_HIDDEN
)ref_value -- reference value to compare the subject's value with
- 返回:
pointer to the created observer
-
lv_observer_t *lv_obj_bind_flag_if_not_eq(lv_obj_t *obj, lv_subject_t *subject, lv_obj_flag_t flag, int32_t ref_value)
Set an object flag if an integer subject's value is not equal to a reference value, clear the flag otherwise
- 参数:
obj -- pointer to an object
subject -- pointer to a subject
flag -- flag to set or clear (e.g.
LV_OBJ_FLAG_HIDDEN
)ref_value -- reference value to compare the subject's value with
- 返回:
pointer to the created observer
-
lv_observer_t *lv_obj_bind_state_if_eq(lv_obj_t *obj, lv_subject_t *subject, lv_state_t state, int32_t ref_value)
Set an object state if an integer subject's value is equal to a reference value, clear the flag otherwise
- 参数:
obj -- pointer to an object
subject -- pointer to a subject
state -- state to set or clear (e.g.
LV_STATE_CHECKED
)ref_value -- reference value to compare the subject's value with
- 返回:
pointer to the created observer
-
lv_observer_t *lv_obj_bind_state_if_not_eq(lv_obj_t *obj, lv_subject_t *subject, lv_state_t state, int32_t ref_value)
Set an object state if an integer subject's value is not equal to a reference value, clear the flag otherwise
- 参数:
obj -- pointer to an object
subject -- pointer to a subject
state -- state to set or clear (e.g.
LV_STATE_CHECKED
)ref_value -- reference value to compare the subject's value with
- 返回:
pointer to the created observer
-
lv_observer_t *lv_obj_bind_checked(lv_obj_t *obj, lv_subject_t *subject)
Set an integer subject to 1 when an object is checked and set it 0 when unchecked.
备注
Ensure the object's
LV_OBJ_FLAG_CHECKABLE
flag is set- 参数:
obj -- pointer to an object
subject -- pointer to a subject
- 返回:
pointer to the created observer
-
lv_observer_t *lv_label_bind_text(lv_obj_t *obj, lv_subject_t *subject, const char *fmt)
Bind an integer, string, or pointer subject to a label.
备注
fmt == NULL can be used only with string and pointer subjects.
备注
if the subject is a pointer must point to a
\0
terminated string.- 参数:
obj -- pointer to a label
subject -- pointer to a subject
fmt -- optional format string with 1 format specifier (e.g. "%d °C") or NULL to bind the value directly.
- 返回:
pointer to the created observer
-
lv_observer_t *lv_arc_bind_value(lv_obj_t *obj, lv_subject_t *subject)
Bind an integer subject to an arc's value
- 参数:
obj -- pointer to an arc
subject -- pointer to a subject
- 返回:
pointer to the created observer
-
lv_observer_t *lv_slider_bind_value(lv_obj_t *obj, lv_subject_t *subject)
Bind an integer subject to a slider's value
- 参数:
obj -- pointer to a slider
subject -- pointer to a subject
- 返回:
pointer to the created observer
-
lv_observer_t *lv_roller_bind_value(lv_obj_t *obj, lv_subject_t *subject)
Bind an integer subject to a roller's value
- 参数:
obj -- pointer to a roller
subject -- pointer to a subject
- 返回:
pointer to the created observer
-
lv_observer_t *lv_dropdown_bind_value(lv_obj_t *obj, lv_subject_t *subject)
Bind an integer subject to a dropdown's value
- 参数:
obj -- pointer to a drop down
subject -- pointer to a subject
- 返回:
pointer to the created observer
-
union lv_subject_value_t
- #include <lv_observer.h>
A common type to handle all the various observable types in the same way
Public Members
-
int32_t num
Integer number (opacity, enums, booleans or "normal" numbers)
-
const void *pointer
Constant pointer (string buffer, format string, font, cone text, etc)
-
lv_color_t color
Color
-
int32_t num
-
struct lv_subject_t
- #include <lv_observer.h>
The subject (an observable value)
Public Members
-
uint32_t type
-
uint32_t size
Might be used to store a size related to
type
-
lv_subject_value_t value
Actual value
-
lv_subject_value_t prev_value
Previous value
-
uint32_t notify_restart_query
If an observer deleted start notifying from the beginning.
-
void *user_data
Additional parameter, can be used freely by the user
-
uint32_t type