From 2ba951d1c65b0b64cb90143ad24142fe6f817db7 Mon Sep 17 00:00:00 2001 From: lixianjing Date: Thu, 27 Jul 2023 18:22:34 +0800 Subject: [PATCH] improve rich text --- docs/changes.md | 1 + src/ext_widgets/rich_text/rich_text.c | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/docs/changes.md b/docs/changes.md index 5490d4132..fa3cea9f6 100644 --- a/docs/changes.md +++ b/docs/changes.md @@ -2,6 +2,7 @@ 2023/07/27 * 修改克隆label控件时没有拷贝ellipses属性的问题(感谢朝泽提供补丁) + * 修复克隆 rich_text 对象失败的问题(感谢智明提供补丁) 2023/07/26 * 修改Windows下路径带中文时fs\_os\_get\_exe的返回结果不是utf8的问题(感谢朝泽提供补丁) diff --git a/src/ext_widgets/rich_text/rich_text.c b/src/ext_widgets/rich_text/rich_text.c index 9d60bc8a2..5aaac9d75 100644 --- a/src/ext_widgets/rich_text/rich_text.c +++ b/src/ext_widgets/rich_text/rich_text.c @@ -513,12 +513,23 @@ static ret_t rich_text_on_event(widget_t* widget, event_t* e) { return ret; } +static ret_t rich_text_set_text_form_value(widget_t* widget, const value_t* v) { + rich_text_t* rich_text = RICH_TEXT(widget); + return_value_if_fail(rich_text != NULL, RET_BAD_PARAMS); + wstr_from_value(&(widget->text), v); + rich_text->need_reset = TRUE; + rich_text->line_gap = 5; + rich_text->margin = 2; + + return RET_OK; +} + static ret_t rich_text_set_prop(widget_t* widget, const char* name, const value_t* v) { rich_text_t* rich_text = RICH_TEXT(widget); return_value_if_fail(rich_text != NULL && name != NULL && v != NULL, RET_BAD_PARAMS); if (tk_str_eq(name, WIDGET_PROP_TEXT)) { - return rich_text_set_text(widget, value_str(v)); + return rich_text_set_text_form_value(widget, v); } else if (tk_str_eq(name, WIDGET_PROP_LINE_GAP)) { rich_text->line_gap = value_int(v); rich_text->need_reset = TRUE;