From 82bfbfc1600a400dd9cf50b584db714202a573ed Mon Sep 17 00:00:00 2001 From: lixianjing Date: Wed, 27 Nov 2024 10:37:20 +0800 Subject: [PATCH] add tab_button_group_remove_index --- demos/demo_ui_old_app.c | 18 +++++++++++++++- design/default/ui/tab_remove.xml | 6 +++++- docs/changes.md | 3 +++ res/assets/default/inc/ui/tab_remove.data | 24 +++++++++++++++++----- res/assets/default/raw/ui/tab_remove.bin | Bin 1916 -> 2200 bytes src/widgets/tab_button_group.c | 12 +++++++++++ src/widgets/tab_button_group.h | 11 ++++++++++ 7 files changed, 67 insertions(+), 7 deletions(-) diff --git a/demos/demo_ui_old_app.c b/demos/demo_ui_old_app.c index badfb6df5..84449708d 100644 --- a/demos/demo_ui_old_app.c +++ b/demos/demo_ui_old_app.c @@ -639,6 +639,19 @@ static ret_t on_clone_view(void* ctx, event_t* e) { return RET_FAIL; } +static ret_t on_remove_tab_by_index(void* ctx, event_t* e) { + char buff[MAX_PATH] = {0}; + widget_t* iter = WIDGET(e->target); + widget_t* win = widget_get_window(iter); + widget_t* edit = widget_lookup(win, "remove_tab_index", TRUE); + widget_t* tab_button_group = widget_lookup_by_type(win, WIDGET_TYPE_TAB_BUTTON_GROUP, FALSE); + + if (edit != NULL && widget_get_text_utf8(edit, buff, sizeof(buff)) == RET_OK) { + return tab_button_group_remove_index(tab_button_group, tk_atoi(buff)); + } + return RET_FAIL; +} + static ret_t on_remove_tab_idle(const idle_info_t* idle) { widget_t* iter = WIDGET(idle->ctx); int32_t remove_index = widget_index_of(iter); @@ -1134,7 +1147,10 @@ static ret_t install_one(void* ctx, const void* iter) { } else { widget_on(widget, EVT_CLICK, on_remove_tab, widget); } - } else if (tk_str_eq(name, "remove_self")) { + } else if (tk_str_eq(name, "remove_tab_by_index")) { + widget_on(widget, EVT_CLICK, on_remove_tab_by_index, widget); + } + else if (tk_str_eq(name, "remove_self")) { widget_on(widget, EVT_CLICK, on_remove_self, widget); } else if (tk_str_eq(name, "remove_view")) { widget_on(widget, EVT_CLICK, on_remove_view, widget); diff --git a/design/default/ui/tab_remove.xml b/design/default/ui/tab_remove.xml index a1b8c8d70..dbe3eeeaa 100644 --- a/design/default/ui/tab_remove.xml +++ b/design/default/ui/tab_remove.xml @@ -10,7 +10,7 @@