Skip to content

Commit d42dc0b

Browse files
committed
add value refresh functionality also for SWITCH
1 parent 844b751 commit d42dc0b

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

lib/3rd_party_adapters/LVGL/Screen.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,23 @@ static void ScreenMenu_switch_cb(lv_event_t *e)
127127
IScreen_leave();
128128
}
129129
}
130+
else if ((code == LV_EVENT_REFRESH) && (item != nullptr))
131+
{
132+
bool *ptr = item->getPtrBool();
133+
if (ptr != nullptr)
134+
{
135+
/* if pointer to bool variable is valid, show it's state */
136+
if (*ptr)
137+
{
138+
lv_obj_add_state(obj, LV_STATE_CHECKED);
139+
}
140+
else
141+
{
142+
lv_obj_clear_state(obj, LV_STATE_CHECKED);
143+
}
144+
}
145+
146+
}
130147
}
131148

132149
/**
@@ -260,6 +277,7 @@ void ScreenMenu::draw()
260277
lv_obj_add_state(swth, (*ptr) ? LV_STATE_CHECKED : LV_STATE_DEFAULT);
261278
lv_obj_add_event_cb(swth, ScreenMenu_switch_cb, LV_EVENT_VALUE_CHANGED, (void *)item); /* assign the switch callback for event value change*/
262279
lv_obj_add_event_cb(swth, ScreenMenu_switch_cb, LV_EVENT_KEY, nullptr); /* assign the switch callback for event key press */
280+
lv_obj_add_event_cb(swth, ScreenMenu_switch_cb, LV_EVENT_REFRESH, (void *)item);
263281
}
264282
break;
265283
}

0 commit comments

Comments
 (0)