summaryrefslogtreecommitdiff
path: root/src/ui/labelwidget.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/labelwidget.c')
-rw-r--r--src/ui/labelwidget.c57
1 files changed, 43 insertions, 14 deletions
diff --git a/src/ui/labelwidget.c b/src/ui/labelwidget.c
index 95f281be..b68ab793 100644
--- a/src/ui/labelwidget.c
+++ b/src/ui/labelwidget.c
@@ -44,6 +44,9 @@ struct Impl_LabelWidget {
44 struct { 44 struct {
45 uint8_t alignVisual : 1; /* align according to visible bounds, not font metrics */ 45 uint8_t alignVisual : 1; /* align according to visible bounds, not font metrics */
46 uint8_t noAutoMinHeight : 1; /* minimum height is not set automatically */ 46 uint8_t noAutoMinHeight : 1; /* minimum height is not set automatically */
47 uint8_t drawAsOutline : 1; /* draw as outline, filled with background color */
48 uint8_t noTopFrame : 1;
49 uint8_t wrap : 1;
47 } flags; 50 } flags;
48}; 51};
49 52
@@ -206,7 +209,7 @@ static void getColors_LabelWidget_(const iLabelWidget *d, int *bg, int *fg, int
206 } 209 }
207 } 210 }
208 int colorEscape = none_ColorId; 211 int colorEscape = none_ColorId;
209 if (startsWith_String(&d->label, "\r")) { 212 if (startsWith_String(&d->label, "\v")) {
210 colorEscape = cstr_String(&d->label)[1] - asciiBase_ColorEscape; /* TODO: can be two bytes long */ 213 colorEscape = cstr_String(&d->label)[1] - asciiBase_ColorEscape; /* TODO: can be two bytes long */
211 } 214 }
212 if (isHover_LabelWidget_(d)) { 215 if (isHover_LabelWidget_(d)) {
@@ -289,7 +292,7 @@ static void draw_LabelWidget_(const iLabelWidget *d) {
289 }; 292 };
290 drawLines_Paint(&p, points + 2, 3, frame2); 293 drawLines_Paint(&p, points + 2, 3, frame2);
291 drawLines_Paint( 294 drawLines_Paint(
292 &p, points, !isHover && flags & noTopFrame_WidgetFlag ? 2 : 3, frame); 295 &p, points, !isHover && flags & d->flags.noTopFrame ? 2 : 3, frame);
293 } 296 }
294 } 297 }
295 setClip_Paint(&p, rect); 298 setClip_Paint(&p, rect);
@@ -315,7 +318,7 @@ static void draw_LabelWidget_(const iLabelWidget *d) {
315 cstr_String(&str)); 318 cstr_String(&str));
316 deinit_String(&str); 319 deinit_String(&str);
317 } 320 }
318 if (flags & wrapText_WidgetFlag) { 321 if (d->flags.wrap) {
319 const iRect inner = adjusted_Rect(innerBounds_Widget(w), init_I2(iconPad, 0), zero_I2()); 322 const iRect inner = adjusted_Rect(innerBounds_Widget(w), init_I2(iconPad, 0), zero_I2());
320 const int wrap = inner.size.x; 323 const int wrap = inner.size.x;
321 drawWrapRange_Text(d->font, topLeft_Rect(inner), wrap, fg, range_String(&d->label)); 324 drawWrapRange_Text(d->font, topLeft_Rect(inner), wrap, fg, range_String(&d->label));
@@ -348,14 +351,14 @@ static void draw_LabelWidget_(const iLabelWidget *d) {
348 cstr_String(&d->label)); 351 cstr_String(&d->label));
349 } 352 }
350 else { 353 else {
351 drawCentered_Text(d->font, 354 drawCenteredOutline_Text(
352 adjusted_Rect(bounds, 355 d->font,
353 add_I2(zero_I2(), init_I2(iconPad, 0)), 356 adjusted_Rect(bounds, add_I2(zero_I2(), init_I2(iconPad, 0)), neg_I2(zero_I2())),
354 neg_I2(zero_I2())), 357 d->flags.alignVisual,
355 d->flags.alignVisual, 358 d->flags.drawAsOutline ? fg : none_ColorId,
356 fg, 359 d->flags.drawAsOutline ? d->widget.bgColor : fg,
357 "%s", 360 "%s",
358 cstr_String(&d->label)); 361 cstr_String(&d->label));
359 } 362 }
360 if (flags & chevron_WidgetFlag) { 363 if (flags & chevron_WidgetFlag) {
361 const iRect chRect = rect; 364 const iRect chRect = rect;
@@ -370,7 +373,7 @@ static void draw_LabelWidget_(const iLabelWidget *d) {
370 373
371static void sizeChanged_LabelWidget_(iLabelWidget *d) { 374static void sizeChanged_LabelWidget_(iLabelWidget *d) {
372 iWidget *w = as_Widget(d); 375 iWidget *w = as_Widget(d);
373 if (flags_Widget(w) & wrapText_WidgetFlag) { 376 if (d->flags.wrap) {
374 if (flags_Widget(w) & fixedHeight_WidgetFlag) { 377 if (flags_Widget(w) & fixedHeight_WidgetFlag) {
375 /* Calculate a new height based on the wrapping. */ 378 /* Calculate a new height based on the wrapping. */
376 w->rect.size.y = advanceWrapRange_Text( 379 w->rect.size.y = advanceWrapRange_Text(
@@ -408,7 +411,7 @@ void updateSize_LabelWidget(iLabelWidget *d) {
408 w->minSize.y = size.y; /* vertically text must remain visible */ 411 w->minSize.y = size.y; /* vertically text must remain visible */
409 } 412 }
410 /* Wrapped text implies that width must be defined by arrangement. */ 413 /* Wrapped text implies that width must be defined by arrangement. */
411 if (!(flags & (fixedWidth_WidgetFlag | wrapText_WidgetFlag))) { 414 if (~flags & fixedWidth_WidgetFlag && !d->flags.wrap) {
412 w->rect.size.x = size.x; 415 w->rect.size.x = size.x;
413 } 416 }
414 if (~flags & fixedHeight_WidgetFlag) { 417 if (~flags & fixedHeight_WidgetFlag) {
@@ -440,8 +443,11 @@ void init_LabelWidget(iLabelWidget *d, const char *label, const char *cmd) {
440 d->kmods = 0; 443 d->kmods = 0;
441 init_Click(&d->click, d, !isEmpty_String(&d->command) ? SDL_BUTTON_LEFT : 0); 444 init_Click(&d->click, d, !isEmpty_String(&d->command) ? SDL_BUTTON_LEFT : 0);
442 setFlags_Widget(w, hover_WidgetFlag, d->click.button != 0); 445 setFlags_Widget(w, hover_WidgetFlag, d->click.button != 0);
443 d->flags.alignVisual = iFalse; 446 d->flags.alignVisual = iFalse;
444 d->flags.noAutoMinHeight = iFalse; 447 d->flags.noAutoMinHeight = iFalse;
448 d->flags.drawAsOutline = iFalse;
449 d->flags.noTopFrame = iFalse;
450 d->flags.wrap = iFalse;
445 updateSize_LabelWidget(d); 451 updateSize_LabelWidget(d);
446 updateKey_LabelWidget_(d); /* could be bound to another key */ 452 updateKey_LabelWidget_(d); /* could be bound to another key */
447} 453}
@@ -481,6 +487,20 @@ void setNoAutoMinHeight_LabelWidget(iLabelWidget *d, iBool noAutoMinHeight) {
481 } 487 }
482} 488}
483 489
490void setNoTopFrame_LabelWidget(iLabelWidget *d, iBool noTopFrame) {
491 d->flags.noTopFrame = noTopFrame;
492}
493
494void setWrap_LabelWidget(iLabelWidget *d, iBool wrap) {
495 d->flags.wrap = wrap;
496}
497
498void setOutline_LabelWidget(iLabelWidget *d, iBool drawAsOutline) {
499 if (d) {
500 d->flags.drawAsOutline = drawAsOutline;
501 }
502}
503
484void updateText_LabelWidget(iLabelWidget *d, const iString *text) { 504void updateText_LabelWidget(iLabelWidget *d, const iString *text) {
485 set_String(&d->label, text); 505 set_String(&d->label, text);
486 set_String(&d->srcLabel, text); 506 set_String(&d->srcLabel, text);
@@ -495,6 +515,11 @@ void updateTextCStr_LabelWidget(iLabelWidget *d, const char *text) {
495 refresh_Widget(&d->widget); 515 refresh_Widget(&d->widget);
496} 516}
497 517
518void updateTextAndResizeWidthCStr_LabelWidget(iLabelWidget *d, const char *text) {
519 updateTextCStr_LabelWidget(d, text);
520 d->widget.rect.size.x = defaultSize_LabelWidget(d).x;
521}
522
498void setTextCStr_LabelWidget(iLabelWidget *d, const char *text) { 523void setTextCStr_LabelWidget(iLabelWidget *d, const char *text) {
499 setCStr_String(&d->label, text); 524 setCStr_String(&d->label, text);
500 set_String(&d->srcLabel, &d->label); 525 set_String(&d->srcLabel, &d->label);
@@ -537,6 +562,10 @@ iChar icon_LabelWidget(const iLabelWidget *d) {
537 return d->icon; 562 return d->icon;
538} 563}
539 564
565iBool isWrapped_LabelWidget(const iLabelWidget *d) {
566 return d->flags.wrap;
567}
568
540const iString *text_LabelWidget(const iLabelWidget *d) { 569const iString *text_LabelWidget(const iLabelWidget *d) {
541 if (!d) return collectNew_String(); 570 if (!d) return collectNew_String();
542 return &d->label; 571 return &d->label;