improve tr_text/tr_tips

This commit is contained in:
lixianjing 2022-04-16 16:42:30 +08:00
parent 165b3822f7
commit b6e7802b87
7 changed files with 35 additions and 0 deletions

View File

@ -1,7 +1,9 @@
# 最新动态
2022/04/16
* 增加函数tk\_socket\_bind\_ex
* 增加函数tk\_iostream\_udp\_create\_client\_ex
* tr\_text/tr\_tips 为空字符串时当作空指针处理。
2022/04/15
* 解决在linux-fb鼠标移动且无按压时界面上的鼠标指针没有跟着移动的问题感谢兆坤提供补丁)。

View File

@ -572,6 +572,11 @@ ret_t widget_set_tr_text(widget_t* widget, const char* text) {
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);
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);

View File

@ -102,6 +102,11 @@ ret_t mledit_set_tr_tips(widget_t* widget, const char* tr_tips) {
widget_t* win = widget_get_window(widget);
return_value_if_fail(mledit != NULL && tr_tips != NULL, RET_BAD_PARAMS);
if (*tr_tips == '\0') {
TKMEM_FREE(mledit->tr_tips);
return RET_OK;
}
mledit->tr_tips = tk_str_copy(mledit->tr_tips, tr_tips);
if (win != NULL) {
tr_tips = locale_info_tr(widget_get_locale_info(widget), tr_tips);

View File

@ -1126,6 +1126,11 @@ ret_t edit_set_tr_tips(widget_t* widget, const char* tr_tips) {
widget_t* win = widget_get_window(widget);
return_value_if_fail(edit != NULL && tr_tips != NULL, RET_BAD_PARAMS);
if (*tr_tips == '\0') {
TKMEM_FREE(edit->tr_tips);
return RET_OK;
}
edit->tr_tips = tk_str_copy(edit->tr_tips, tr_tips);
if (win != NULL) {
tr_tips = locale_info_tr(widget_get_locale_info(widget), tr_tips);

View File

@ -192,3 +192,15 @@ TEST(Button, to_xml) {
str_reset(&str);
}
TEST(Button, tr_text) {
widget_t* w1 = button_create(NULL, 10, 20, 30, 40);
widget_set_tr_text(w1, "abc");
ASSERT_STREQ(w1->tr_text, "abc");
widget_set_tr_text(w1, "");
ASSERT_EQ(w1->tr_text == NULL, true);
widget_destroy(w1);
}

View File

@ -57,6 +57,9 @@ TEST(Edit, tips) {
ASSERT_EQ(widget_set_prop_str(b, WIDGET_PROP_TR_TIPS, "tr_tips"), RET_OK);
ASSERT_STREQ(EDIT(b)->tr_tips, "tr_tips");
ASSERT_EQ(widget_set_prop_str(b, WIDGET_PROP_TR_TIPS, ""), RET_OK);
ASSERT_EQ(EDIT(b)->tr_tips == NULL, true);
widget_destroy(b);
}

View File

@ -57,6 +57,9 @@ TEST(MLEdit, tips) {
ASSERT_EQ(widget_set_prop_str(b, WIDGET_PROP_TR_TIPS, "tr_tips"), RET_OK);
ASSERT_STREQ(MLEDIT(b)->tr_tips, "tr_tips");
ASSERT_EQ(widget_set_prop_str(b, WIDGET_PROP_TR_TIPS, ""), RET_OK);
ASSERT_EQ(MLEDIT(b)->tr_tips == NULL, true);
widget_destroy(b);
}