feat(observer): support simple int binding to label

This commit is contained in:
Gabor Kiss-Vamosi
2025-03-06 16:38:05 +01:00
parent 8eb583c7b7
commit c23636c130
4 changed files with 15 additions and 5 deletions
+4 -1
View File
@@ -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;
}
+3 -3
View File
@@ -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
View File
@@ -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>
+3
View File
@@ -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>