Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Eisel <eiseljulian@gmail.com>2018-07-06 20:26:12 +0300
committerJulian Eisel <eiseljulian@gmail.com>2018-07-06 20:33:13 +0300
commit29b8adec61b2c88a07d29b78b26aeca26658a166 (patch)
tree145479afe7116421b2128ec151dc160b21991528 /source/blender/editors/interface
parent2a199f5093cf6dc537047f9456adffa52b6aa005 (diff)
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.
Diffstat (limited to 'source/blender/editors/interface')
-rw-r--r--source/blender/editors/interface/interface.c12
-rw-r--r--source/blender/editors/interface/interface_intern.h16
-rw-r--r--source/blender/editors/interface/interface_region_popup.c3
-rw-r--r--source/blender/editors/interface/interface_widgets.c13
4 files changed, 34 insertions, 10 deletions
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index 427f5621177..20361bde16f 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -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);
diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h
index 10b4ff58224..0b76e311cc7 100644
--- a/source/blender/editors/interface/interface_intern.h
+++ b/source/blender/editors/interface/interface_intern.h
@@ -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;
diff --git a/source/blender/editors/interface/interface_region_popup.c b/source/blender/editors/interface/interface_region_popup.c
index 320ee1f4616..1bbf2242c5d 100644
--- a/source/blender/editors/interface/interface_region_popup.c
+++ b/source/blender/editors/interface/interface_region_popup.c
@@ -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);
}
}
diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c
index c70b9b72a07..4e15737c3e5 100644
--- a/source/blender/editors/interface/interface_widgets.c
+++ b/source/blender/editors/interface/interface_widgets.c
@@ -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;