diff --git a/docs/changes.md b/docs/changes.md index a62b4463c..92d8ccdfd 100644 --- a/docs/changes.md +++ b/docs/changes.md @@ -3,6 +3,7 @@ 2022/05/20 * 增加EMITTER\_ENABLE/EMITTER\_DISABLE * 完善text edit。 + * 完善widget\_set\_tr\_text(感谢俊圣提供补丁) 2022/05/19 * 完善func\_str diff --git a/src/base/widget.c b/src/base/widget.c index ecf2917d0..a087605f8 100644 --- a/src/base/widget.c +++ b/src/base/widget.c @@ -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); diff --git a/tests/button_test.cc b/tests/button_test.cc index 50163cb86..36c6e201b 100644 --- a/tests/button_test.cc +++ b/tests/button_test.cc @@ -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); }