UI: Support right aligned non-shortcut hints in widgets

Widget drawing code already supported drawing right-aligned, grayed out
shortcut strings. This patch generalizes things a bit so this can also
be used to draw other hints in the same way. There have been a few
instances in the past where this would've been useful, D11046 being the
latest one.

Note that besides some manual regression testing, I didn't check if this
works yet, as there is no code actually using it (other than the
shortcuts). Can be checked as part of further development for D11046.

A possible further improvement would be providing a way to define how
clipping should be done. E.g. sometimes the right-aligned text should be
clipped first (because it's just a hint), in other cases it should be
left untouched (like current code explicitly does it for shortcuts).

Removes the `UI_BUT_HAS_SHORTCUT` flag, which isn't needed anymore.
This commit is contained in:
2021-06-15 18:53:32 +02:00
parent fcc844f8fb
commit a4f840e15b
5 changed files with 31 additions and 34 deletions

View File

@@ -2131,14 +2131,15 @@ static void widget_draw_text(const uiFontStyle *fstyle,
transopts = ui_translate_buttons();
#endif
bool use_drawstr_right_as_hint = false;
/* cut string in 2 parts - only for menu entries */
if ((but->drawflag & UI_BUT_HAS_SHORTCUT) && (but->editstr == NULL)) {
if (but->flag & UI_BUT_HAS_SEP_CHAR) {
drawstr_right = strrchr(drawstr, UI_SEP_CHAR);
if (drawstr_right) {
drawstr_left_len = (drawstr_right - drawstr);
drawstr_right++;
}
if (but->flag & UI_BUT_HAS_SEP_CHAR && (but->editstr == NULL)) {
drawstr_right = strrchr(drawstr, UI_SEP_CHAR);
if (drawstr_right) {
use_drawstr_right_as_hint = true;
drawstr_left_len = (drawstr_right - drawstr);
drawstr_right++;
}
}
@@ -2243,7 +2244,7 @@ static void widget_draw_text(const uiFontStyle *fstyle,
if (drawstr_right) {
uchar col[4];
copy_v4_v4_uchar(col, wcol->text);
if (but->drawflag & UI_BUT_HAS_SHORTCUT) {
if (use_drawstr_right_as_hint) {
col[3] *= 0.5f;
}