mirror of
https://github.com/lvgl/lvgl.git
synced 2026-05-23 07:46:36 +08:00
feat(observer): support simple int binding to label
This commit is contained in:
@@ -556,7 +556,10 @@ lv_observer_t * lv_label_bind_text(lv_obj_t * obj, lv_subject_t * subject, const
|
||||
LV_ASSERT_NULL(obj);
|
||||
|
||||
if(fmt == NULL) {
|
||||
if(subject->type != LV_SUBJECT_TYPE_STRING && subject->type != LV_SUBJECT_TYPE_POINTER) {
|
||||
if(subject->type == LV_SUBJECT_TYPE_INT) {
|
||||
fmt = "%d";
|
||||
}
|
||||
else if(subject->type != LV_SUBJECT_TYPE_STRING && subject->type != LV_SUBJECT_TYPE_POINTER) {
|
||||
LV_LOG_WARN("Incompatible subject type: %d", subject->type);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -663,11 +663,11 @@ void test_observer_label_text_normal(void)
|
||||
observer = lv_label_bind_text(obj, &subject_color, NULL);
|
||||
TEST_ASSERT_EQUAL_PTR(NULL, observer);
|
||||
|
||||
/*Cannot bind int*/
|
||||
/*Bind it with "%d" if NULL is passed*/
|
||||
static lv_subject_t subject_int;
|
||||
lv_subject_init_int(&subject_int, 0);
|
||||
lv_subject_init_int(&subject_int, 10);
|
||||
observer = lv_label_bind_text(obj, &subject_int, NULL);
|
||||
TEST_ASSERT_EQUAL_PTR(NULL, observer);
|
||||
TEST_ASSERT_EQUAL_STRING("10", lv_label_get_text(obj));
|
||||
|
||||
/*Bind to string*/
|
||||
static char buf[32];
|
||||
|
||||
+5
-1
@@ -23,5 +23,9 @@ Example
|
||||
<prop name="long_mode">
|
||||
<param name="mode" type="enum:lv_label_long_mode" />
|
||||
</prop>
|
||||
<prop name="bind_text">
|
||||
<param name="subject" type="subject" />
|
||||
<param name="string" type="fmt" default="NULL"/>
|
||||
</prop>
|
||||
</api>
|
||||
</widget>
|
||||
</widget>
|
||||
|
||||
@@ -28,5 +28,8 @@ Example
|
||||
<prop name="mode" type="enum:lv_slider_mode">
|
||||
<param name="range_min" type="int"/>
|
||||
</prop>
|
||||
<prop name="bind_value">
|
||||
<param name="subject" type="subject" />
|
||||
</prop>
|
||||
</api>
|
||||
</widget>
|
||||
Reference in New Issue
Block a user