mirror of
https://github.com/lvgl/lvgl.git
synced 2026-05-28 21:47:56 +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);
|
LV_ASSERT_NULL(obj);
|
||||||
|
|
||||||
if(fmt == NULL) {
|
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);
|
LV_LOG_WARN("Incompatible subject type: %d", subject->type);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -663,11 +663,11 @@ void test_observer_label_text_normal(void)
|
|||||||
observer = lv_label_bind_text(obj, &subject_color, NULL);
|
observer = lv_label_bind_text(obj, &subject_color, NULL);
|
||||||
TEST_ASSERT_EQUAL_PTR(NULL, observer);
|
TEST_ASSERT_EQUAL_PTR(NULL, observer);
|
||||||
|
|
||||||
/*Cannot bind int*/
|
/*Bind it with "%d" if NULL is passed*/
|
||||||
static lv_subject_t subject_int;
|
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);
|
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*/
|
/*Bind to string*/
|
||||||
static char buf[32];
|
static char buf[32];
|
||||||
|
|||||||
+5
-1
@@ -23,5 +23,9 @@ Example
|
|||||||
<prop name="long_mode">
|
<prop name="long_mode">
|
||||||
<param name="mode" type="enum:lv_label_long_mode" />
|
<param name="mode" type="enum:lv_label_long_mode" />
|
||||||
</prop>
|
</prop>
|
||||||
|
<prop name="bind_text">
|
||||||
|
<param name="subject" type="subject" />
|
||||||
|
<param name="string" type="fmt" default="NULL"/>
|
||||||
|
</prop>
|
||||||
</api>
|
</api>
|
||||||
</widget>
|
</widget>
|
||||||
|
|||||||
@@ -28,5 +28,8 @@ Example
|
|||||||
<prop name="mode" type="enum:lv_slider_mode">
|
<prop name="mode" type="enum:lv_slider_mode">
|
||||||
<param name="range_min" type="int"/>
|
<param name="range_min" type="int"/>
|
||||||
</prop>
|
</prop>
|
||||||
|
<prop name="bind_value">
|
||||||
|
<param name="subject" type="subject" />
|
||||||
|
</prop>
|
||||||
</api>
|
</api>
|
||||||
</widget>
|
</widget>
|
||||||
Reference in New Issue
Block a user