UI: Add extra padding to menus to draw sub-menu triangles in

Shortcut strings would be offset to the left to make space for the triangles,
breaking the alignment with other shortcut strings. Now this alignment is kept
by making menus slightly wider if there's a sub-menu triangle visible, making
room for the triangle.
This commit is contained in:
Julian Eisel
2018-07-06 19:26:12 +02:00
parent 2a199f5093
commit 29b8adec61
4 changed files with 34 additions and 10 deletions

View File

@@ -3454,6 +3454,12 @@ static void ui_def_but_rna__menu(bContext *UNUSED(C), uiLayout *layout, void *bu
block->flag |= UI_BLOCK_IS_FLIP;
}
static void ui_but_submenu_enable(uiBlock *block, uiBut *but)
{
but->flag |= UI_BUT_ICON_SUBMENU;
block->content_hints |= BLOCK_CONTAINS_SUBMENU_BUT;
}
/**
* ui_def_but_rna_propname and ui_def_but_rna
* both take the same args except for propname vs prop, this is done so we can
@@ -3589,7 +3595,7 @@ static uiBut *ui_def_but_rna(
}
if ((type == UI_BTYPE_MENU) && (but->dt == UI_EMBOSS_PULLDOWN)) {
but->flag |= UI_BUT_ICON_SUBMENU;
ui_but_submenu_enable(block, but);
}
const char *info;
@@ -4328,7 +4334,7 @@ uiBut *uiDefIconTextMenuBut(uiBlock *block, uiMenuCreateFunc func, void *arg, in
ui_def_but_icon(but, icon, UI_HAS_ICON);
but->drawflag |= UI_BUT_ICON_LEFT;
but->flag |= UI_BUT_ICON_SUBMENU;
ui_but_submenu_enable(block, but);
but->menu_create_func = func;
ui_but_update(but);
@@ -4360,7 +4366,7 @@ uiBut *uiDefIconTextBlockBut(uiBlock *block, uiBlockCreateFunc func, void *arg,
but->drawflag |= UI_BUT_ICON_LEFT;
}
but->flag |= UI_HAS_ICON;
but->flag |= UI_BUT_ICON_SUBMENU;
ui_but_submenu_enable(block, but);
but->block_create_func = func;
ui_but_update(but);

View File

@@ -105,7 +105,8 @@ typedef enum {
UI_WTYPE_PROGRESSBAR,
} uiWidgetTypeEnum;
#define UI_MENU_WIDTH_MIN (UI_UNIT_Y * 9)
#define UI_MENU_WIDTH_MIN (UI_UNIT_Y * 9)
#define UI_MENU_SUBMENU_PADDING (6 * UI_DPI_FAC) /* some extra padding added to menus containing submenu icons */
/* menu scrolling */
#define UI_MENU_SCROLL_ARROW 12
@@ -349,6 +350,13 @@ struct PieMenuData {
float alphafac;
};
/* uiBlock.content_hints */
enum eBlockContentHints {
/* In a menu block, if there is a single sub-menu button, we add some
* padding to the right to put nicely aligned triangle icons there. */
BLOCK_CONTAINS_SUBMENU_BUT = (1 << 0),
};
struct uiBlock {
uiBlock *next, *prev;
@@ -395,11 +403,15 @@ struct uiBlock {
int flag;
short alignnr;
/* Hints about the buttons of this block. Used to avoid iterating over
* buttons to find out if some criteria is met by any. Instead, check this
* criteria when adding the button and set a flag here if it's met. */
short content_hints; /* eBlockContentHints */
char direction;
char dt; /* drawtype: UI_EMBOSS, UI_EMBOSS_NONE ... etc, copied to buttons */
bool auto_open;
char _pad[7];
char _pad[5];
double auto_open_last;
const char *lockstr;

View File

@@ -116,6 +116,9 @@ static void ui_popup_block_position(wmWindow *window, ARegion *butregion, uiBut
BLI_rctf_init_minmax(&block->rect);
for (uiBut *bt = block->buttons.first; bt; bt = bt->next) {
if (block->content_hints & BLOCK_CONTAINS_SUBMENU_BUT) {
bt->rect.xmax += UI_MENU_SUBMENU_PADDING;
}
BLI_rctf_union(&block->rect, &bt->rect);
}
}

View File

@@ -1359,7 +1359,7 @@ static void widget_draw_submenu_tria(const uiBut *but, const rcti *rect, const u
const float aspect = but->block->aspect / UI_DPI_FAC;
const int tria_height = (int)(ICON_DEFAULT_HEIGHT / aspect);
const int tria_width = (int)(ICON_DEFAULT_WIDTH / aspect) - 2 * U.pixelsize;
const int xs = rect->xmax - UI_DPI_ICON_SIZE - aspect;
const int xs = rect->xmax - tria_width;
const int ys = (rect->ymin + rect->ymax - tria_height) / 2.0f;
float col[4];
rctf tria_rect;
@@ -2088,6 +2088,7 @@ static void widget_draw_text_icon(uiFontStyle *fstyle, uiWidgetColors *wcol, uiB
widget_draw_icon(but, icon, alpha, rect);
if (show_menu_icon) {
BLI_assert(but->block->content_hints & BLOCK_CONTAINS_SUBMENU_BUT);
widget_draw_submenu_tria(but, rect, wcol);
}
@@ -2096,10 +2097,6 @@ static void widget_draw_text_icon(uiFontStyle *fstyle, uiWidgetColors *wcol, uiB
#endif
rect->xmin += icon_size;
/* without this menu keybindings will overlap the arrow icon [#38083] */
if (show_menu_icon) {
rect->xmax -= icon_size / 2.0f;
}
}
if (but->editstr || (but->drawflag & UI_BUT_TEXT_LEFT)) {
@@ -2109,6 +2106,12 @@ static void widget_draw_text_icon(uiFontStyle *fstyle, uiWidgetColors *wcol, uiB
rect->xmax -= (UI_TEXT_MARGIN_X * U.widget_unit) / but->block->aspect;
}
/* Menu contains sub-menu items with triangle icon on their right. Shortcut
* strings should be drawn with some padding to the right then. */
if (ui_block_is_menu(but->block) && (but->block->content_hints & BLOCK_CONTAINS_SUBMENU_BUT)) {
rect->xmax -= UI_MENU_SUBMENU_PADDING;
}
/* extra icons, e.g. 'x' icon to clear text or icon for eyedropper */
if (extra_icon_type != UI_BUT_ICONEXTRA_NONE) {
rcti temp = *rect;