improve combobox set option

This commit is contained in:
lixianjing 2022-04-28 10:51:49 +08:00
parent 54da8e7256
commit befd79b844
3 changed files with 26 additions and 3 deletions

View File

@ -1,7 +1,10 @@
# 最新动态
2022/04/28
* 完善 combo\_box 在非加载时设置options后更新显示文本。
2022/04/27
* 修复combo_box_ex初始化时出现文本全选的问题感谢雨欣提供补丁
* 修复combo\_box\_ex初始化时出现文本全选的问题感谢雨欣提供补丁
2022/04/26
* 完善 stream serial 的文档(感谢智明提供补丁)。

View File

@ -240,7 +240,12 @@ ret_t combo_box_parse_options(widget_t* widget, const char* str) {
}
ret_t combo_box_set_options(widget_t* widget, const char* options) {
return combo_box_parse_options(widget, options);
combo_box_t* combo_box = COMBO_BOX(widget);
ret_t ret = combo_box_parse_options(widget, options);
if (!widget->loading) {
ret = combo_box_sync_index_to_value(widget, 0, FALSE);
}
return ret;
}
static ret_t combo_box_text_to_index(widget_t* widget, const char* text) {
@ -276,7 +281,7 @@ static ret_t combo_box_set_prop(widget_t* widget, const char* name, const value_
combo_box_set_localize_options(widget, value_bool(v));
return RET_OK;
} else if (tk_str_eq(name, WIDGET_PROP_OPTIONS)) {
combo_box_parse_options(widget, value_str(v));
combo_box_set_options(widget, value_str(v));
return RET_OK;
} else if (tk_str_eq(name, WIDGET_PROP_ITEM_HEIGHT)) {
combo_box_set_item_height(widget, value_uint32(v));

View File

@ -323,3 +323,18 @@ TEST(ComboBox, remove_option) {
widget_destroy(w);
}
TEST(ComboBox, set_options) {
char text[100];
widget_t* w = combo_box_create(NULL, 10, 20, 30, 40);
combo_box_set_options(w, "1:red;2:green;3:blue");
widget_get_text_utf8(w, text, sizeof(text)-1);
ASSERT_STREQ(text, "red");
combo_box_set_options(w, "aaa;bbb;ccc");
widget_get_text_utf8(w, text, sizeof(text)-1);
ASSERT_STREQ(text, "aaa");
widget_destroy(w);
}