improve widget_get_style

This commit is contained in:
lixianjing 2023-06-20 17:58:48 +08:00
parent 8d507028e5
commit 9be54a8395
3 changed files with 15 additions and 4 deletions

View File

@ -1,5 +1,8 @@
# 最新动态
2023/06/20
* 修复 widget\_get\_style 获取非当前状态的 mutable 风格失败的问题(感谢智明提供补丁)
2023/06/19
* 完善预览可设置是否打开控制台窗口及可自定义设置资源路径(感谢培煌提供补丁)

View File

@ -4635,6 +4635,7 @@ ret_t widget_get_style(widget_t* widget, const char* state_and_name, value_t* va
char state[64];
const char* name = NULL;
const char* p_state = NULL;
ret_t ret = RET_NOT_FOUND;
return_value_if_fail(widget != NULL && state_and_name != NULL && *state_and_name != '\0' && value != NULL, RET_BAD_PARAMS);
memset(state, 0x0, sizeof(state));
@ -4651,16 +4652,18 @@ ret_t widget_get_style(widget_t* widget, const char* state_and_name, value_t* va
name = name + 1;
}
if (tk_str_eq(p_state, widget_get_prop_str(widget, WIDGET_PROP_STATE_FOR_STYLE, NULL))) {
return style_get(widget->astyle, p_state, name, value);
} else {
if (style_is_mutable(widget->astyle) || tk_str_eq(p_state, widget_get_prop_str(widget, WIDGET_PROP_STATE_FOR_STYLE, NULL))) {
ret = style_get(widget->astyle, p_state, name, value);
}
if (ret != RET_OK) {
const char* style_name = (widget->style != NULL && *widget->style != '\0') ? widget->style : TK_DEFAULT_STYLE;
const void* data = widget_get_const_style_data_for_state(widget, style_name, p_state);
if (data == NULL && !tk_str_eq(p_state, WIDGET_STATE_NORMAL)) {
data = widget_get_const_style_data_for_state(widget, style_name, WIDGET_STATE_NORMAL);
}
return style_data_get_value((uint8_t*)data, name, value);
ret = style_data_get_value((uint8_t*)data, name, value);
}
return ret;
}
ret_t widget_set_style(widget_t* widget, const char* state_and_name, const value_t* value) {

View File

@ -1157,6 +1157,11 @@ TEST(Widget, get_style) {
ASSERT_EQ(widget_get_style(b, "text_color", &v1), RET_OK);
ASSERT_EQ(red.color, value_uint32(&v1));
value_set_int(&v, 321);
ASSERT_EQ(widget_set_style(b, "pressed:margin", &v), RET_OK);
ASSERT_EQ(widget_get_style(b, "pressed:margin", &v1), RET_OK);
ASSERT_EQ(value_int(&v), value_int(&v1));
ASSERT_EQ(widget_get_style(b, "pressed:x_offset", &v1), RET_OK);
ASSERT_EQ(1, value_uint32(&v1));