improve widget_set_tr_text

This commit is contained in:
lixianjing 2022-05-20 15:57:59 +08:00
parent 940fda9675
commit 2a223fd250
3 changed files with 4 additions and 2 deletions

View File

@ -3,6 +3,7 @@
2022/05/20
* 增加EMITTER\_ENABLE/EMITTER\_DISABLE
* 完善text edit。
* 完善widget\_set\_tr\_text(感谢俊圣提供补丁)
2022/05/19
* 完善func\_str

View File

@ -550,20 +550,20 @@ static ret_t widget_apply_tr_text_before_paint(void* ctx, event_t* e) {
}
ret_t widget_set_tr_text(widget_t* widget, const char* text) {
value_t v;
const char* tr_text = NULL;
widget_t* win = widget_get_window(widget);
return_value_if_fail(widget != NULL && text != NULL, RET_OK);
if (*text == '\0') {
TKMEM_FREE(widget->tr_text);
widget_set_prop_str(widget, WIDGET_PROP_TEXT, text);
return RET_OK;
}
widget->tr_text = tk_str_copy(widget->tr_text, text);
if (win != NULL) {
tr_text = locale_info_tr(widget_get_locale_info(widget), text);
widget_set_prop(widget, WIDGET_PROP_TEXT, value_set_str(&v, tr_text));
widget_set_prop_str(widget, WIDGET_PROP_TEXT, tr_text);
} else {
widget_set_prop_str(widget, WIDGET_PROP_TEXT, text);
widget_on(widget, EVT_BEFORE_PAINT, widget_apply_tr_text_before_paint, widget);

View File

@ -201,6 +201,7 @@ TEST(Button, tr_text) {
widget_set_tr_text(w1, "");
ASSERT_EQ(w1->tr_text == NULL, true);
ASSERT_STREQ(w1->text.str, L"");
widget_destroy(w1);
}