diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-07-24 21:04:20 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-07-24 21:04:20 +0300 |
commit | a9f42435aa4b1bb559771548895328668b396ee3 (patch) | |
tree | 2c52011ea486c7ec1130dbfb1d41b63f37f580ee /src | |
parent | 673ef41425fc6f35aa539ff32f40d0ae5b8e63de (diff) |
LabelWidget: Fixed wrapped content positioning
Diffstat (limited to 'src')
-rw-r--r-- | src/ui/labelwidget.c | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/src/ui/labelwidget.c b/src/ui/labelwidget.c index 7d6bac67..a9a2d033 100644 --- a/src/ui/labelwidget.c +++ b/src/ui/labelwidget.c | |||
@@ -263,6 +263,14 @@ iLocalDef int iconPadding_LabelWidget_(const iLabelWidget *d) { | |||
263 | return d->icon ? iRound(lineHeight_Text(d->font) * amount) : 0; | 263 | return d->icon ? iRound(lineHeight_Text(d->font) * amount) : 0; |
264 | } | 264 | } |
265 | 265 | ||
266 | static iRect contentBounds_LabelWidget_(const iLabelWidget *d) { | ||
267 | iRect content = adjusted_Rect(bounds_Widget(constAs_Widget(d)), | ||
268 | padding_LabelWidget_(d, 0), | ||
269 | neg_I2(padding_LabelWidget_(d, 2))); | ||
270 | adjustEdges_Rect(&content, 0, 0, 0, iconPadding_LabelWidget_(d)); | ||
271 | return content; | ||
272 | } | ||
273 | |||
266 | static void draw_LabelWidget_(const iLabelWidget *d) { | 274 | static void draw_LabelWidget_(const iLabelWidget *d) { |
267 | const iWidget *w = constAs_Widget(d); | 275 | const iWidget *w = constAs_Widget(d); |
268 | draw_Widget(w); | 276 | draw_Widget(w); |
@@ -319,9 +327,9 @@ static void draw_LabelWidget_(const iLabelWidget *d) { | |||
319 | deinit_String(&str); | 327 | deinit_String(&str); |
320 | } | 328 | } |
321 | if (d->flags.wrap) { | 329 | if (d->flags.wrap) { |
322 | const iRect inner = adjusted_Rect(innerBounds_Widget(w), init_I2(iconPad, 0), zero_I2()); | 330 | const iRect cont = contentBounds_LabelWidget_(d); //djusted_Rect(innerBounds_Widget(w), init_I2(iconPad, 0), zero_I2()); |
323 | const int wrap = inner.size.x; | 331 | drawWrapRange_Text( |
324 | drawWrapRange_Text(d->font, topLeft_Rect(inner), wrap, fg, range_String(&d->label)); | 332 | d->font, topLeft_Rect(cont), width_Rect(cont), fg, range_String(&d->label)); |
325 | } | 333 | } |
326 | else if (flags & alignLeft_WidgetFlag) { | 334 | else if (flags & alignLeft_WidgetFlag) { |
327 | draw_Text(d->font, add_I2(bounds.pos, addX_I2(padding_LabelWidget_(d, 0), iconPad)), | 335 | draw_Text(d->font, add_I2(bounds.pos, addX_I2(padding_LabelWidget_(d, 0), iconPad)), |
@@ -376,9 +384,11 @@ static void sizeChanged_LabelWidget_(iLabelWidget *d) { | |||
376 | if (d->flags.wrap) { | 384 | if (d->flags.wrap) { |
377 | if (flags_Widget(w) & fixedHeight_WidgetFlag) { | 385 | if (flags_Widget(w) & fixedHeight_WidgetFlag) { |
378 | /* Calculate a new height based on the wrapping. */ | 386 | /* Calculate a new height based on the wrapping. */ |
379 | w->rect.size.y = measureWrapRange_Text( | 387 | const iRect cont = contentBounds_LabelWidget_(d); |
380 | d->font, innerBounds_Widget(w).size.x, range_String(&d->label)) | 388 | w->rect.size.y = |
381 | .bounds.size.y; | 389 | measureWrapRange_Text(d->font, width_Rect(cont), range_String(&d->label)) |
390 | .bounds.size.y + | ||
391 | padding_LabelWidget_(d, 0).y + padding_LabelWidget_(d, 2).y; | ||
382 | } | 392 | } |
383 | } | 393 | } |
384 | } | 394 | } |
@@ -473,6 +483,9 @@ void setTextColor_LabelWidget(iLabelWidget *d, int color) { | |||
473 | void setText_LabelWidget(iLabelWidget *d, const iString *text) { | 483 | void setText_LabelWidget(iLabelWidget *d, const iString *text) { |
474 | updateText_LabelWidget(d, text); | 484 | updateText_LabelWidget(d, text); |
475 | updateSize_LabelWidget(d); | 485 | updateSize_LabelWidget(d); |
486 | if (isWrapped_LabelWidget(d)) { | ||
487 | sizeChanged_LabelWidget_(d); | ||
488 | } | ||
476 | } | 489 | } |
477 | 490 | ||
478 | void setAlignVisually_LabelWidget(iLabelWidget *d, iBool alignVisual) { | 491 | void setAlignVisually_LabelWidget(iLabelWidget *d, iBool alignVisual) { |