Fix width of compact buttons with icons, e.g. layout.menu().

As mentioned in the comment, the icon width computation relies on
big enough margins; however in compact mode they aren't big enough
and the label gets truncated.
This commit is contained in:
Alexander Gavrilov 2019-05-03 16:15:11 +03:00
parent 1006767678
commit e185a6afa3
1 changed files with 8 additions and 4 deletions

View File

@ -304,10 +304,14 @@ static int ui_text_icon_width(uiLayout *layout, const char *name, int icon, bool
layout->item.flag |= UI_ITEM_MIN;
}
const uiFontStyle *fstyle = UI_FSTYLE_WIDGET;
/* it may seem odd that the icon only adds (unit_x / 4)
* but taking margins into account its fine */
return (UI_fontstyle_string_width(fstyle, name) +
(unit_x * ((compact ? 1.25f : 1.50f) + (icon ? 0.25f : 0.0f))));
float margin = compact ? 1.25 : 1.50;
if (icon) {
/* It may seem odd that the icon only adds (unit_x / 4)
* but taking margins into account its fine, except
* in compact mode a bit more margin is required. */
margin += compact ? 0.35 : 0.25;
}
return UI_fontstyle_string_width(fstyle, name) + (unit_x * margin);
}
else {
return unit_x * 10;