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 @@
-
+
@@ -24,4 +24,8 @@
+
+
+
+
diff --git a/docs/changes.md b/docs/changes.md
index a48f3d3e7..e55033c11 100644
--- a/docs/changes.md
+++ b/docs/changes.md
@@ -1,5 +1,8 @@
# 最新动态
+2024/11/26
+ * 增加tab_button_group删除tab_button和对应page的函数(感谢智明提供补丁)
+
2024/11/22
* 修复 mledit编译警告(感谢泽武提供补丁)
diff --git a/res/assets/default/inc/ui/tab_remove.data b/res/assets/default/inc/ui/tab_remove.data
index 7f18c1e6a..1b081b8cf 100644
--- a/res/assets/default/inc/ui/tab_remove.data
+++ b/res/assets/default/inc/ui/tab_remove.data
@@ -1,5 +1,5 @@
TK_CONST_DATA_ALIGN(const unsigned char ui_tab_remove_default[]) = {
-0x04,0x00,0x01,0x01,0x7c,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x74,0x61,0x62,0x5f,0x72,0x65,0x6d,0x6f,
+0x04,0x00,0x01,0x01,0x98,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x74,0x61,0x62,0x5f,0x72,0x65,0x6d,0x6f,
0x76,0x65,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x12,0x12,0x22,0x11,0x77,0x69,0x6e,0x64,0x6f,0x77,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
@@ -45,9 +45,9 @@ TK_CONST_DATA_ALIGN(const unsigned char ui_tab_remove_default[]) = {
0x76,0x65,0x5f,0x74,0x61,0x62,0x00,0x74,0x72,0x5f,0x74,0x65,0x78,0x74,0x00,0x78,0x00,0x00,0x00,0x00,
0x00,0x70,0x61,0x67,0x65,0x73,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x2a,0x00,0x00,
-0x00,0x5a,0x00,0x00,0x00,0xc4,0xff,0xff,0xff,0x73,0x65,0x6c,0x66,0x5f,0x6c,0x61,0x79,0x6f,0x75,0x74,
+0x00,0x5a,0x00,0x00,0x00,0x5e,0x01,0x00,0x00,0x73,0x65,0x6c,0x66,0x5f,0x6c,0x61,0x79,0x6f,0x75,0x74,
0x00,0x64,0x65,0x66,0x61,0x75,0x6c,0x74,0x28,0x78,0x3d,0x63,0x2c,0x79,0x3d,0x34,0x32,0x2c,0x77,0x3d,
-0x39,0x30,0x25,0x2c,0x68,0x3d,0x2d,0x36,0x30,0x29,0x00,0x76,0x61,0x6c,0x75,0x65,0x00,0x31,0x00,0x00,
+0x39,0x30,0x25,0x2c,0x68,0x3d,0x33,0x35,0x30,0x29,0x00,0x76,0x61,0x6c,0x75,0x65,0x00,0x31,0x00,0x00,
0x76,0x69,0x65,0x77,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x64,0x00,0x00,0x00,0x64,0x00,0x00,0x00,0x73,0x65,0x6c,0x66,0x5f,0x6c,0x61,0x79,0x6f,0x75,0x74,0x00,
@@ -96,5 +96,19 @@ TK_CONST_DATA_ALIGN(const unsigned char ui_tab_remove_default[]) = {
0x6c,0x66,0x5f,0x6c,0x61,0x79,0x6f,0x75,0x74,0x00,0x64,0x65,0x66,0x61,0x75,0x6c,0x74,0x28,0x78,0x3d,
0x63,0x2c,0x79,0x3d,0x62,0x6f,0x74,0x74,0x6f,0x6d,0x3a,0x31,0x30,0x30,0x2c,0x77,0x3d,0x38,0x30,0x2c,
0x68,0x3d,0x34,0x30,0x29,0x00,0x6e,0x61,0x6d,0x65,0x00,0x63,0x6c,0x6f,0x6e,0x65,0x5f,0x74,0x61,0x62,
-0x00,0x74,0x72,0x5f,0x74,0x65,0x78,0x74,0x00,0x43,0x6c,0x6f,0x6e,0x65,0x00,0x00,0x00,0x00,0x00,0x00,
-0x00,0x00,0x00,0x00,};/*1964*/
+0x00,0x74,0x72,0x5f,0x74,0x65,0x78,0x74,0x00,0x43,0x6c,0x6f,0x6e,0x65,0x00,0x00,0x00,0x00,0x00,0x76,
+0x69,0x65,0x77,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x90,0x01,0x00,0x00,0x5a,
+0x00,0x00,0x00,0x28,0x00,0x00,0x00,0x73,0x65,0x6c,0x66,0x5f,0x6c,0x61,0x79,0x6f,0x75,0x74,0x00,0x64,
+0x65,0x66,0x61,0x75,0x6c,0x74,0x28,0x78,0x3d,0x63,0x2c,0x79,0x3d,0x34,0x30,0x30,0x2c,0x77,0x3d,0x39,
+0x30,0x25,0x2c,0x68,0x3d,0x34,0x30,0x29,0x00,0x00,0x65,0x64,0x69,0x74,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x50,0x00,0x00,0x00,0x28,0x00,0x00,0x00,0x69,0x6e,
+0x70,0x75,0x74,0x5f,0x74,0x79,0x70,0x65,0x00,0x75,0x69,0x6e,0x74,0x00,0x6e,0x61,0x6d,0x65,0x00,0x72,
+0x65,0x6d,0x6f,0x76,0x65,0x5f,0x74,0x61,0x62,0x5f,0x69,0x6e,0x64,0x65,0x78,0x00,0x73,0x74,0x65,0x70,
+0x00,0x31,0x00,0x74,0x65,0x78,0x74,0x00,0x30,0x00,0x00,0x00,0x62,0x75,0x74,0x74,0x6f,0x6e,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x64,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x50,0x00,0x00,0x00,0x28,0x00,0x00,0x00,
+0x6e,0x61,0x6d,0x65,0x00,0x72,0x65,0x6d,0x6f,0x76,0x65,0x5f,0x74,0x61,0x62,0x5f,0x62,0x79,0x5f,0x69,
+0x6e,0x64,0x65,0x78,0x00,0x74,0x72,0x5f,0x74,0x65,0x78,0x74,0x00,0x52,0x65,0x6d,0x6f,0x76,0x65,0x00,
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,};/*2248*/
diff --git a/res/assets/default/raw/ui/tab_remove.bin b/res/assets/default/raw/ui/tab_remove.bin
index e6aea188e..1a00741cb 100644
Binary files a/res/assets/default/raw/ui/tab_remove.bin and b/res/assets/default/raw/ui/tab_remove.bin differ
diff --git a/src/widgets/tab_button_group.c b/src/widgets/tab_button_group.c
index 7940e6927..9fdc53333 100644
--- a/src/widgets/tab_button_group.c
+++ b/src/widgets/tab_button_group.c
@@ -425,6 +425,18 @@ ret_t tab_button_group_set_drag_child(widget_t* widget, bool_t drag_child) {
return RET_OK;
}
+ret_t tab_button_group_remove_index(widget_t* widget, uint32_t index) {
+ widget_t* pages = NULL;
+ tab_button_group_t* tab_button_group = TAB_BUTTON_GROUP(widget);
+ return_value_if_fail(tab_button_group != NULL && index < widget_count_children(widget), RET_BAD_PARAMS);
+
+ pages = widget_lookup_by_type(widget->parent, WIDGET_TYPE_PAGES, TRUE);
+
+ widget_destroy(widget_get_child(pages, index));
+ widget_destroy(widget_get_child(widget, index));
+
+ return RET_OK;
+}
static ret_t tab_button_group_on_destroy(widget_t* widget) {
tab_button_group_t* tab_button_group = TAB_BUTTON_GROUP(widget);
diff --git a/src/widgets/tab_button_group.h b/src/widgets/tab_button_group.h
index 17ef603cf..52a249bdb 100644
--- a/src/widgets/tab_button_group.h
+++ b/src/widgets/tab_button_group.h
@@ -160,6 +160,17 @@ ret_t tab_button_group_set_scrollable(widget_t* widget, bool_t scrollable);
*/
ret_t tab_button_group_set_drag_child(widget_t* widget, bool_t drag_child);
+/**
+ * @method tab_button_group_remove_index
+ * 设置删除 tab_button_group 控件中的 tab_button 控件和对应页。
+ * @annotation ["scriptable"]
+ * @param {widget_t*} widget 控件对象。
+ * @param {uint32_t} index tab_button 的序号。
+ *
+ * @return {ret_t} 返回RET_OK表示成功,否则表示失败。
+ */
+ret_t tab_button_group_remove_index(widget_t* widget, uint32_t index);
+
/**
* @method tab_button_group_cast
* 转换tab_button_group对象(供脚本语言使用)。