From a41eb4471406e668b81c807be08022553bb02187 Mon Sep 17 00:00:00 2001 From: Jinhao Date: Mon, 17 Sep 2018 07:48:23 +0800 Subject: [PATCH] fix bug that label uses all ram when its width is zero. --- source/gui/widgets/label.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/source/gui/widgets/label.cpp b/source/gui/widgets/label.cpp index 569271e8..03b88215 100644 --- a/source/gui/widgets/label.cpp +++ b/source/gui/widgets/label.cpp @@ -311,7 +311,8 @@ namespace nana break; } - if (allowed_width_px < extent_size.width) + //The width is not restricted if the allowed_width_px is zero. + if (allowed_width_px && (allowed_width_px < extent_size.width)) extent_size.width = allowed_width_px; if (transient_.current_font != pre_font) @@ -445,6 +446,10 @@ namespace nana unsigned sub_text_px = 0; auto sub_text_len = _m_fit_text(graph, data->text().substr(text_begin), rs.allowed_width, sub_text_px); + //At least one character must be displayed no matter whether the width is enough or not. + if (0 == sub_text_len) + sub_text_len = 1; + if (text_begin + sub_text_len < data->text().size()) { //make a new visual line