From f97fdfe2036d647bc8f19d5600f15e6a148c3542 Mon Sep 17 00:00:00 2001 From: xianjimli Date: Tue, 13 Oct 2020 18:05:33 +0800 Subject: [PATCH] improve label --- docs/changes.md | 1 + src/widgets/label.c | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/docs/changes.md b/docs/changes.md index f62695666..d86101509 100644 --- a/docs/changes.md +++ b/docs/changes.md @@ -4,6 +4,7 @@ * 增加plugin\_manager。 * label的line\_wrap属性,缺省改为FALSE。 * 将tkc编译成独立的动态库,给非GUI的库使用。 + * 完善label的line\_wrap处理(感谢朝泽提供补丁)。 * 增加属性 disallow\_children\_focusable(感谢智明提供补丁)。 2020/10/12 diff --git a/src/widgets/label.c b/src/widgets/label.c index 2a8caac3b..f4273155b 100644 --- a/src/widgets/label.c +++ b/src/widgets/label.c @@ -112,7 +112,11 @@ static ret_t label_line_parser_next(label_line_parser_t* parser) { if (parser->line_wrap) { char_w = canvas_measure_text(c, p, 1) + 1; if ((w + char_w) > parser->width) { - if (line_break_check(p[0], p[1]) == LINE_BREAK_NO) { + return_value_if_fail(p > parser->line, RET_FAIL); + + if (line_break_check(*(p - 1), *p) == LINE_BREAK_NO) { + return_value_if_fail(p != parser->line + 1, RET_FAIL); + if (p > parser->line) { p--; } @@ -141,8 +145,8 @@ static ret_t label_paint_text_mlines(widget_t* widget, canvas_t* c, label_line_p int32_t font_size = c->font_size; int32_t margin = style_get_int(style, STYLE_ID_MARGIN, 2); int32_t spacer = style_get_int(style, STYLE_ID_SPACER, 2); - align_v_t align_v = (align_v_t)style_get_int(style, STYLE_ID_TEXT_ALIGN_V, ALIGN_V_TOP); - align_h_t align_h = (align_h_t)style_get_int(style, STYLE_ID_TEXT_ALIGN_H, ALIGN_H_LEFT); + align_v_t align_v = (align_v_t)style_get_int(style, STYLE_ID_TEXT_ALIGN_V, ALIGN_V_MIDDLE); + align_h_t align_h = (align_h_t)style_get_int(style, STYLE_ID_TEXT_ALIGN_H, ALIGN_H_CENTER); int32_t line_height = font_size + spacer; x = margin;