mirror of
https://gitee.com/zlgopen/awtk.git
synced 2024-12-02 03:58:33 +08:00
add combo_box_remove_option
This commit is contained in:
parent
37fa4eacde
commit
b29ac810f2
@ -1,5 +1,8 @@
|
||||
# 最新动态
|
||||
|
||||
2021/08/04
|
||||
* 增加函数combo\_box\_remove\_option。
|
||||
|
||||
2021/08/03
|
||||
* 键盘支持跟随编辑(指定floating=true即可)
|
||||
* 更新文档。
|
||||
|
@ -576,6 +576,34 @@ 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(widget_t* widget, int32_t value) {
|
||||
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 (iter->value == value) {
|
||||
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;
|
||||
}
|
||||
prev = iter;
|
||||
iter = iter->next;
|
||||
}
|
||||
|
||||
return RET_NOT_FOUND;
|
||||
}
|
||||
|
||||
ret_t combo_box_reset_options(widget_t* widget) {
|
||||
combo_box_option_t* iter = NULL;
|
||||
combo_box_option_t* next = NULL;
|
||||
|
@ -326,6 +326,17 @@ ret_t combo_box_set_item_height(widget_t* widget, uint32_t item_height);
|
||||
*/
|
||||
ret_t combo_box_append_option(widget_t* widget, int32_t value, const char* text);
|
||||
|
||||
/**
|
||||
* @method combo_box_remove_option
|
||||
* 删除选项。
|
||||
* @annotation ["scriptable"]
|
||||
* @param {widget_t*} widget combo_box对象。
|
||||
* @param {int32_t} value 值。
|
||||
*
|
||||
* @return {ret_t} 返回RET_OK表示成功,否则表示失败。
|
||||
*/
|
||||
ret_t combo_box_remove_option(widget_t* widget, int32_t value);
|
||||
|
||||
/**
|
||||
* @method combo_box_set_options
|
||||
* 设置选项。
|
||||
|
@ -288,3 +288,26 @@ TEST(ComboBox, events) {
|
||||
|
||||
widget_destroy(w);
|
||||
}
|
||||
|
||||
TEST(ComboBox, remove_option) {
|
||||
widget_t* w = combo_box_create(NULL, 10, 20, 30, 40);
|
||||
|
||||
ASSERT_EQ(combo_box_append_option(w, 1, "red"), RET_OK);
|
||||
ASSERT_EQ(combo_box_append_option(w, 2, "green"), RET_OK);
|
||||
ASSERT_EQ(combo_box_append_option(w, 3, "blue"), RET_OK);
|
||||
ASSERT_EQ(combo_box_count_options(w), 3);
|
||||
|
||||
ASSERT_EQ(combo_box_remove_option(w, 1), RET_OK);
|
||||
ASSERT_EQ(combo_box_count_options(w), 2);
|
||||
|
||||
ASSERT_EQ(combo_box_remove_option(w, 1), RET_NOT_FOUND);
|
||||
ASSERT_EQ(combo_box_count_options(w), 2);
|
||||
|
||||
ASSERT_EQ(combo_box_remove_option(w, 3), RET_OK);
|
||||
ASSERT_EQ(combo_box_count_options(w), 1);
|
||||
|
||||
ASSERT_EQ(combo_box_remove_option(w, 2), RET_OK);
|
||||
ASSERT_EQ(combo_box_count_options(w), 0);
|
||||
|
||||
widget_destroy(w);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user