Skip to content

Commit 73b6c0b

Browse files
committed
Fix width determination of non-trimmed, non-wrapped labels
In other words, exclude trimmable labels from the special logic used for non-wrapping ones, since they are not expected to dictate their width authoritatively.
1 parent aa6ec76 commit 73b6c0b

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

scene/gui/label.cpp

+9-7
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,14 @@ bool Label::_shape() {
139139
can_process_lines = true;
140140
lines_dirty = false;
141141
} else {
142-
// With autowrap on, we won't compute the minimum size until width is stable (two shape requests in a
143-
// row with the same width.) This avoids situations in which the initial width is very narrow and the label
144-
// would break text into many very short lines, causing a very tall label that can leave a deformed container.
145-
146-
can_process_lines = get_size().width == stable_width || autowrap_mode == TextServer::AUTOWRAP_OFF;
142+
// With autowrap on or off with trimming enabled, we won't compute the minimum size until width is stable
143+
// (two shape requests in a row with the same width.) This avoids situations in which the initial width is
144+
// very narrow and the label would break text into many very short lines, causing a very tall label that can
145+
// leave a deformed container. In the remaining case (namely, autowrap off and no trimming), the label is
146+
// free to dictate its own width, something that will be taken advtantage of.
147+
bool can_dictate_width = autowrap_mode == TextServer::AUTOWRAP_OFF && overrun_behavior == TextServer::OVERRUN_NO_TRIMMING;
148+
bool is_width_stable = get_size().width == stable_width;
149+
can_process_lines = can_dictate_width || is_width_stable;
147150
stable_width = get_size().width;
148151

149152
if (can_process_lines) {
@@ -171,14 +174,13 @@ bool Label::_shape() {
171174
}
172175
}
173176

174-
if (autowrap_mode == TextServer::AUTOWRAP_OFF) {
177+
if (can_dictate_width) {
175178
for (int i = 0; i < lines_rid.size(); i++) {
176179
if (minsize.width < TS->shaped_text_get_size(lines_rid[i]).x) {
177180
minsize.width = TS->shaped_text_get_size(lines_rid[i]).x;
178181
}
179182
}
180183

181-
// With autowrap off, by now we already know the width the label will take.
182184
width = (minsize.width - style->get_minimum_size().width);
183185
}
184186

0 commit comments

Comments
 (0)