From ba501cfe5fc9e127a91301d16a92c95b3eaf4315 Mon Sep 17 00:00:00 2001 From: xianjimli Date: Sat, 8 Jun 2019 12:13:28 +0800 Subject: [PATCH] fix tab_button_set_value --- src/widgets/tab_button.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/widgets/tab_button.c b/src/widgets/tab_button.c index 11ba8f7f4..23d78a8a0 100644 --- a/src/widgets/tab_button.c +++ b/src/widgets/tab_button.c @@ -88,6 +88,20 @@ static widget_t* tab_button_get_pages(widget_t* widget) { return pages; } +static ret_t tab_button_sync_pages(void* ctx, event_t* e) { + widget_t* widget = WIDGET(ctx); + + widget_t* pages = tab_button_get_pages(widget); + if (pages != NULL) { + uint32_t index = widget_index_of(widget); + widget_set_value(pages, index); + + return RET_REMOVE; + } else { + return RET_OK; + } +} + ret_t tab_button_set_value(widget_t* widget, bool_t value) { return_value_if_fail(widget != NULL, RET_BAD_PARAMS); @@ -108,6 +122,8 @@ ret_t tab_button_set_value(widget_t* widget, bool_t value) { if (pages != NULL) { index = widget_index_of(widget); widget_set_value(pages, index); + } else { + widget_on(widget, EVT_BEFORE_PAINT, tab_button_sync_pages, widget); } if (value) {