diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-07-25 14:44:57 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-07-25 14:44:57 +0300 |
commit | 3dee6c5d167044fae4159e6e657ce547ab32f854 (patch) | |
tree | 9b0ac2986bb7dd695f4e61c19b85f61289c97df2 /src/ui | |
parent | b5eef5cbddab73c7bdcd5be00e8228377b0a4ef1 (diff) |
Right/center-aligned text; fixed menu shortcuts
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/labelwidget.c | 12 | ||||
-rw-r--r-- | src/ui/text.c | 27 | ||||
-rw-r--r-- | src/ui/text.h | 11 | ||||
-rw-r--r-- | src/ui/util.c | 2 | ||||
-rw-r--r-- | src/ui/widget.c | 2 |
5 files changed, 36 insertions, 18 deletions
diff --git a/src/ui/labelwidget.c b/src/ui/labelwidget.c index f24e2573..c9ac0b60 100644 --- a/src/ui/labelwidget.c +++ b/src/ui/labelwidget.c | |||
@@ -193,16 +193,20 @@ static void draw_LabelWidget_(const iLabelWidget *d) { | |||
193 | iString str; | 193 | iString str; |
194 | init_String(&str); | 194 | init_String(&str); |
195 | keyStr_LabelWidget_(d, &str); | 195 | keyStr_LabelWidget_(d, &str); |
196 | draw_Text(uiShortcuts_FontId, negX_I2(add_I2(topRight_Rect(bounds), negX_I2(padding_()))), | 196 | drawAlign_Text(uiShortcuts_FontId, |
197 | flags & pressed_WidgetFlag ? fg : cyan_ColorId, cstr_String(&str)); | 197 | add_I2(topRight_Rect(bounds), negX_I2(padding_())), |
198 | flags & pressed_WidgetFlag ? fg : cyan_ColorId, | ||
199 | right_Alignment, | ||
200 | cstr_String(&str)); | ||
198 | deinit_String(&str); | 201 | deinit_String(&str); |
199 | } | 202 | } |
200 | } | 203 | } |
201 | else if (flags & alignRight_WidgetFlag) { | 204 | else if (flags & alignRight_WidgetFlag) { |
202 | draw_Text( | 205 | drawAlign_Text( |
203 | d->font, | 206 | d->font, |
204 | mul_I2(init_I2(-1, 1), add_I2(topRight_Rect(bounds), negX_I2(padding_()))), | 207 | add_I2(topRight_Rect(bounds), negX_I2(padding_())), |
205 | fg, | 208 | fg, |
209 | right_Alignment, | ||
206 | cstr_String(&d->label)); | 210 | cstr_String(&d->label)); |
207 | } | 211 | } |
208 | else { | 212 | else { |
diff --git a/src/ui/text.c b/src/ui/text.c index dd8b4323..26bb9599 100644 --- a/src/ui/text.c +++ b/src/ui/text.c | |||
@@ -574,7 +574,7 @@ static void draw_Text_(int fontId, iInt2 pos, int color, iRangecc text) { | |||
574 | NULL); | 574 | NULL); |
575 | } | 575 | } |
576 | 576 | ||
577 | void draw_Text(int fontId, iInt2 pos, int color, const char *text, ...) { | 577 | void drawAlign_Text(int fontId, iInt2 pos, int color, enum iAlignment align, const char *text, ...) { |
578 | iBlock chars; | 578 | iBlock chars; |
579 | init_Block(&chars, 0); { | 579 | init_Block(&chars, 0); { |
580 | va_list args; | 580 | va_list args; |
@@ -582,17 +582,24 @@ void draw_Text(int fontId, iInt2 pos, int color, const char *text, ...) { | |||
582 | vprintf_Block(&chars, text, args); | 582 | vprintf_Block(&chars, text, args); |
583 | va_end(args); | 583 | va_end(args); |
584 | } | 584 | } |
585 | #if 0 | 585 | if (align == center_Alignment) { |
586 | /* BUG: A long text string may have a negative X but still be meant to the left-aligned. */ | 586 | pos.x -= measure_Text(fontId, cstr_Block(&chars)).x / 2; |
587 | if (pos.x < 0) { | ||
588 | /* Right-aligned. */ | ||
589 | pos.x = -pos.x - measure_Text(fontId, cstr_Block(&chars)).x; | ||
590 | } | 587 | } |
591 | if (pos.y < 0) { | 588 | else if (align == right_Alignment) { |
592 | /* Bottom-aligned. */ | 589 | pos.x -= measure_Text(fontId, cstr_Block(&chars)).x; |
593 | pos.y = -pos.y - lineHeight_Text(fontId); | 590 | } |
591 | draw_Text_(fontId, pos, color, (iRangecc){ constBegin_Block(&chars), constEnd_Block(&chars) }); | ||
592 | deinit_Block(&chars); | ||
593 | } | ||
594 | |||
595 | void draw_Text(int fontId, iInt2 pos, int color, const char *text, ...) { | ||
596 | iBlock chars; | ||
597 | init_Block(&chars, 0); { | ||
598 | va_list args; | ||
599 | va_start(args, text); | ||
600 | vprintf_Block(&chars, text, args); | ||
601 | va_end(args); | ||
594 | } | 602 | } |
595 | #endif | ||
596 | draw_Text_(fontId, pos, color, (iRangecc){ constBegin_Block(&chars), constEnd_Block(&chars) }); | 603 | draw_Text_(fontId, pos, color, (iRangecc){ constBegin_Block(&chars), constEnd_Block(&chars) }); |
597 | deinit_Block(&chars); | 604 | deinit_Block(&chars); |
598 | } | 605 | } |
diff --git a/src/ui/text.h b/src/ui/text.h index be95e948..982218eb 100644 --- a/src/ui/text.h +++ b/src/ui/text.h | |||
@@ -49,9 +49,16 @@ iInt2 advanceN_Text (int fontId, const char *text, size_t n); /* `n` in | |||
49 | iInt2 advanceRange_Text (int fontId, iRangecc text); | 49 | iInt2 advanceRange_Text (int fontId, iRangecc text); |
50 | iInt2 tryAdvanceRange_Text(int fontId, iRangecc text, int width, const char **endPos); | 50 | iInt2 tryAdvanceRange_Text(int fontId, iRangecc text, int width, const char **endPos); |
51 | 51 | ||
52 | void draw_Text (int fontId, iInt2 pos, int color, const char *text, ...); /* negative pos to switch alignment */ | 52 | enum iAlignment { |
53 | void drawString_Text (int fontId, iInt2 pos, int color, const iString *text); | 53 | left_Alignment, |
54 | center_Alignment, | ||
55 | right_Alignment, | ||
56 | }; | ||
57 | |||
58 | void draw_Text (int fontId, iInt2 pos, int color, const char *text, ...); | ||
59 | void drawAlign_Text (int fontId, iInt2 pos, int color, enum iAlignment align, const char *text, ...); | ||
54 | void drawCentered_Text (int fontId, iRect rect, int color, const char *text, ...); | 60 | void drawCentered_Text (int fontId, iRect rect, int color, const char *text, ...); |
61 | void drawString_Text (int fontId, iInt2 pos, int color, const iString *text); | ||
55 | 62 | ||
56 | SDL_Texture * glyphCache_Text (void); | 63 | SDL_Texture * glyphCache_Text (void); |
57 | 64 | ||
diff --git a/src/ui/util.c b/src/ui/util.c index 8fc7f9e3..c468ba2b 100644 --- a/src/ui/util.c +++ b/src/ui/util.c | |||
@@ -175,7 +175,7 @@ iWidget *makeMenu_Widget(iWidget *parent, const iMenuItem *items, size_t n) { | |||
175 | const iMenuItem *item = &items[i]; | 175 | const iMenuItem *item = &items[i]; |
176 | if (equal_CStr(item->label, "---")) { | 176 | if (equal_CStr(item->label, "---")) { |
177 | iWidget *sep = addChild_Widget(menu, iClob(new_Widget())); | 177 | iWidget *sep = addChild_Widget(menu, iClob(new_Widget())); |
178 | setBackgroundColor_Widget(sep, gray50_ColorId); | 178 | setBackgroundColor_Widget(sep, black_ColorId); |
179 | sep->rect.size.y = gap_UI / 3; | 179 | sep->rect.size.y = gap_UI / 3; |
180 | setFlags_Widget(sep, hover_WidgetFlag | fixedHeight_WidgetFlag, iTrue); | 180 | setFlags_Widget(sep, hover_WidgetFlag | fixedHeight_WidgetFlag, iTrue); |
181 | } | 181 | } |
diff --git a/src/ui/widget.c b/src/ui/widget.c index e83532d4..bbd5f465 100644 --- a/src/ui/widget.c +++ b/src/ui/widget.c | |||
@@ -405,7 +405,7 @@ void draw_Widget(const iWidget *d) { | |||
405 | fillRect_Paint(&p, rect, d->bgColor); | 405 | fillRect_Paint(&p, rect, d->bgColor); |
406 | } | 406 | } |
407 | if (d->frameColor >= 0) { | 407 | if (d->frameColor >= 0) { |
408 | drawRect_Paint(&p, rect, d->frameColor); | 408 | drawRectThickness_Paint(&p, rect, gap_UI / 4, d->frameColor); |
409 | } | 409 | } |
410 | } | 410 | } |
411 | iConstForEach(ObjectList, i, d->children) { | 411 | iConstForEach(ObjectList, i, d->children) { |