add combo_box_remove_option_by_index

This commit is contained in:
lixianjing 2023-06-29 11:23:26 +08:00
parent 112ba91bda
commit 9e76d8c30b
5 changed files with 111 additions and 5 deletions

View File

@ -2,6 +2,7 @@
2023/06/29
* 更新API文档。
* 增加函数combo\_box\_remove\_option\_by\_index。
2023/06/28
* 感谢朝泽提供以下补丁:

View File

@ -144,7 +144,8 @@ default](https://github.com/zlgopen/awtk/blob/master/design/default/styles/defau
| <a href="#combo_box_t_combo_box_get_value">combo\_box\_get\_value</a> | 获取combo_box的值。 |
| <a href="#combo_box_t_combo_box_get_widget_vtable">combo\_box\_get\_widget\_vtable</a> | 获取 combo_box 虚表。 |
| <a href="#combo_box_t_combo_box_has_option_text">combo\_box\_has\_option\_text</a> | 检查选项中是否存在指定的文本。 |
| <a href="#combo_box_t_combo_box_remove_option">combo\_box\_remove\_option</a> | 删除选项。 |
| <a href="#combo_box_t_combo_box_remove_option">combo\_box\_remove\_option</a> | 删除第一个值为value的选项。 |
| <a href="#combo_box_t_combo_box_remove_option_by_index">combo\_box\_remove\_option\_by\_index</a> | 删除指定序数的选项。 |
| <a href="#combo_box_t_combo_box_reset_options">combo\_box\_reset\_options</a> | 重置所有选项。 |
| <a href="#combo_box_t_combo_box_set_custom_open_popup">combo\_box\_set\_custom\_open\_popup</a> | 设置自定义的打开弹出窗口的函数。 |
| <a href="#combo_box_t_combo_box_set_item_height">combo\_box\_set\_item\_height</a> | 设置item高度。 |
@ -377,7 +378,7 @@ bool_t combo_box_has_option_text (widget_t* widget, const char* text);
* 函数功能:
> <p id="combo_box_t_combo_box_remove_option">删除选项。
> <p id="combo_box_t_combo_box_remove_option">删除第一个值为value的选项。
* 函数原型:
@ -391,7 +392,27 @@ ret_t combo_box_remove_option (widget_t* widget, int32_t value);
| -------- | ----- | --------- |
| 返回值 | ret\_t | 返回RET\_OK表示成功否则表示失败。 |
| widget | widget\_t* | combo\_box对象。 |
| value | int32\_t | 值。 |
| value | int32\_t | 选项的值。 |
#### combo\_box\_remove\_option\_by\_index 函数
-----------------------
* 函数功能:
> <p id="combo_box_t_combo_box_remove_option_by_index">删除指定序数的选项。
* 函数原型:
```
ret_t combo_box_remove_option_by_index (widget_t* widget, uint32_t index);
```
* 参数说明:
| 参数 | 类型 | 说明 |
| -------- | ----- | --------- |
| 返回值 | ret\_t | 返回RET\_OK表示成功否则表示失败。 |
| widget | widget\_t* | combo\_box对象。 |
| index | uint32\_t | 选项的序数(0表示第一个)。 |
#### combo\_box\_reset\_options 函数
-----------------------

View File

@ -795,6 +795,36 @@ widget_t* combo_box_create(widget_t* parent, xy_t x, xy_t y, wh_t w, wh_t h) {
return widget;
}
ret_t combo_box_remove_option_by_index(widget_t* widget, uint32_t index) {
uint32_t i = 0;
combo_box_option_t* iter = NULL;
combo_box_option_t* prev = NULL;
combo_box_t* combo_box = COMBO_BOX(widget);
return_value_if_fail(combo_box != NULL, RET_BAD_PARAMS);
iter = combo_box->option_items;
prev = combo_box->option_items;
while (iter != NULL) {
if (i == index) {
if (iter == combo_box->option_items) {
combo_box->option_items = iter->next;
} else {
prev->next = iter->next;
}
TKMEM_FREE(iter->text);
TKMEM_FREE(iter);
return RET_OK;
}
i++;
prev = iter;
iter = iter->next;
}
return RET_NOT_FOUND;
}
ret_t combo_box_remove_option(widget_t* widget, int32_t value) {
combo_box_option_t* iter = NULL;
combo_box_option_t* prev = NULL;

View File

@ -379,15 +379,26 @@ ret_t combo_box_append_option(widget_t* widget, int32_t value, const char* text)
/**
* @method combo_box_remove_option
*
* value的选
* @annotation ["scriptable"]
* @param {widget_t*} widget combo_box对象
* @param {int32_t} value
* @param {int32_t} value
*
* @return {ret_t} RET_OK表示成功
*/
ret_t combo_box_remove_option(widget_t* widget, int32_t value);
/**
* @method combo_box_remove_option_by_index
*
* @annotation ["scriptable"]
* @param {widget_t*} widget combo_box对象
* @param {uint32_t} index (0)
*
* @return {ret_t} RET_OK表示成功
*/
ret_t combo_box_remove_option_by_index(widget_t* widget, uint32_t index);
/**
* @method combo_box_set_options
*

View File

@ -324,6 +324,49 @@ TEST(ComboBox, events) {
widget_destroy(w);
}
TEST(ComboBox, remove_option_by_index) {
widget_t* w = combo_box_create(NULL, 10, 20, 30, 40);
ASSERT_EQ(combo_box_append_option(w, 10, "red"), RET_OK);
ASSERT_EQ(combo_box_append_option(w, 11, "green"), RET_OK);
ASSERT_EQ(combo_box_append_option(w, 12, "blue"), RET_OK);
ASSERT_EQ(combo_box_append_option(w, 13, "orange"), RET_OK);
ASSERT_EQ(combo_box_append_option(w, 14, "gold"), RET_OK);
ASSERT_EQ(combo_box_append_option(w, 15, "black"), RET_OK);
ASSERT_EQ(combo_box_count_options(w), 6);
ASSERT_EQ(combo_box_remove_option_by_index(w, 0), RET_OK);
ASSERT_EQ(combo_box_has_option_text(w, "red"), FALSE);
ASSERT_EQ(combo_box_count_options(w), 5);
ASSERT_EQ(combo_box_remove_option_by_index(w, 1), RET_OK);
ASSERT_EQ(combo_box_has_option_text(w, "blue"), FALSE);
ASSERT_EQ(combo_box_count_options(w), 4);
ASSERT_EQ(combo_box_remove_option_by_index(w, 3), RET_OK);
ASSERT_EQ(combo_box_has_option_text(w, "black"), FALSE);
ASSERT_EQ(combo_box_count_options(w), 3);
ASSERT_EQ(combo_box_remove_option_by_index(w, 3), RET_NOT_FOUND);
ASSERT_EQ(combo_box_remove_option_by_index(w, 2), RET_OK);
ASSERT_EQ(combo_box_has_option_text(w, "gold"), FALSE);
ASSERT_EQ(combo_box_count_options(w), 2);
ASSERT_EQ(combo_box_remove_option_by_index(w, 0), RET_OK);
ASSERT_EQ(combo_box_has_option_text(w, "green"), FALSE);
ASSERT_EQ(combo_box_count_options(w), 1);
ASSERT_EQ(combo_box_remove_option_by_index(w, 0), RET_OK);
ASSERT_EQ(combo_box_has_option_text(w, "orange"), FALSE);
ASSERT_EQ(combo_box_count_options(w), 0);
ASSERT_EQ(combo_box_remove_option_by_index(w, 0), RET_NOT_FOUND);
widget_destroy(w);
}
TEST(ComboBox, remove_option) {
widget_t* w = combo_box_create(NULL, 10, 20, 30, 40);