From 94e8db1e869d8209599f1a40b0e1a25c056d077a Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Thu, 25 Nov 2021 15:51:03 +0100 Subject: Fix T92278: Small size of previews in the shading popover Don't use the side padding for menu item contents when displaying previews or icons in a row or grid layout. This can cause problems for the preview drawing and doesn't make sense to draw there anyway. This not only fixes the mentioned issue, but also too small heighlight for the collection color tag in the Outliner context menu. Alternative to and similar to D13125. --- .../blender/editors/interface/interface_widgets.c | 40 ++++++++++++++++++++-- 1 file changed, 37 insertions(+), 3 deletions(-) (limited to 'source/blender/editors/interface') diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index 8faafd92b6e..8a73039f029 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -101,6 +101,10 @@ typedef enum { UI_WTYPE_PULLDOWN, UI_WTYPE_MENU_ITEM, + /* Same as #UI_WTYPE_MENU_ITEM, but doesn't add padding to sides for text & icon inside the + * widget. To be used when multiple menu items should be displayed close to each other + * horizontally. */ + UI_WTYPE_MENU_ITEM_UNPADDED, UI_WTYPE_MENU_ITEM_RADIAL, UI_WTYPE_MENU_BACK, @@ -4090,6 +4094,27 @@ static void widget_menu_itembut(uiWidgetColors *wcol, widgetbase_draw(&wtb, wcol); } +static void widget_menu_itembut_unpadded(uiWidgetColors *wcol, + rcti *rect, + int UNUSED(state), + int UNUSED(roundboxalign), + const float zoom) +{ + /* This function is used for menu items placed close to each other horizontally, e.g. the matcap + * preview popup or the row of collection color icons in the Outliner context menu. Don't use + * padding on the sides like the normal menu item. */ + + uiWidgetBase wtb; + widget_init(&wtb); + + /* No outline. */ + wtb.draw_outline = false; + const float rad = widget_radius_from_zoom(zoom, wcol); + round_box_edges(&wtb, UI_CNR_ALL, rect, rad); + + widgetbase_draw(&wtb, wcol); +} + static void widget_menu_radial_itembut(uiBut *but, uiWidgetColors *wcol, rcti *rect, @@ -4495,6 +4520,12 @@ static uiWidgetType *widget_type(uiWidgetTypeEnum type) wt.state = widget_state_menu_item; break; + case UI_WTYPE_MENU_ITEM_UNPADDED: + wt.wcol_theme = &btheme->tui.wcol_menu_item; + wt.draw = widget_menu_itembut_unpadded; + wt.state = widget_state_menu_item; + break; + case UI_WTYPE_MENU_BACK: wt.wcol_theme = &btheme->tui.wcol_menu_back; wt.draw = widget_menu_back; @@ -4660,9 +4691,12 @@ void ui_draw_but(const bContext *C, struct ARegion *region, uiStyle *style, uiBu case UI_BTYPE_SEPR_LINE: ui_draw_separator(rect, &tui->wcol_menu_item); break; - default: - wt = widget_type(UI_WTYPE_MENU_ITEM); + default: { + const bool use_unpadded = (but->flag & UI_BUT_ICON_PREVIEW) || + ((but->flag & UI_HAS_ICON) && !but->drawstr[0]); + wt = widget_type(use_unpadded ? UI_WTYPE_MENU_ITEM_UNPADDED : UI_WTYPE_MENU_ITEM); break; + } } } else if (ELEM(but->emboss, UI_EMBOSS_NONE, UI_EMBOSS_NONE_OR_STATUS)) { @@ -5543,7 +5577,7 @@ void ui_draw_preview_item(const uiFontStyle *fstyle, int state, eFontStyle_Align text_align) { - uiWidgetType *wt = widget_type(UI_WTYPE_MENU_ITEM); + uiWidgetType *wt = widget_type(UI_WTYPE_MENU_ITEM_UNPADDED); /* drawing button background */ wt->state(wt, state, 0, UI_EMBOSS_UNDEFINED); -- cgit v1.2.3 From 5514ca58a4d4e03d9062bc479488faca7e577677 Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Thu, 25 Nov 2021 16:53:44 +0100 Subject: Fix T92313: Heading of redo panel is not aligned properly This corrects some alignments issues through new margins introduced in 93544b641bd6. Basic idea of this fix is to only add the new margins when drawing a panel with background. These margins were added specifically for the background boxes, so that makes sense. Alternative fix to D13199. This also fixes some margings added unintentionally in mentioned commit. There is a little jump of the toolbar and the tabs in the Properties when comparing the UI without this fix to 2.93: {F12158085} {F12158039} The jump is gone with this fix applied (compare to the 2.93 screenshot): {F12158064} While not a serious issue, this confirms that this fix actually tackles the root of the issue. --- source/blender/editors/interface/interface.c | 15 +---------- source/blender/editors/interface/interface_panel.c | 31 +++++++++++++++++++--- 2 files changed, 29 insertions(+), 17 deletions(-) (limited to 'source/blender/editors/interface') diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index 6ad0ef9de18..c5ccdbaac3b 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -2075,24 +2075,11 @@ void UI_block_draw(const bContext *C, uiBlock *block) ui_draw_menu_back(&style, block, &rect); } else if (block->panel) { - bool show_background = region->alignment != RGN_ALIGN_FLOAT; - if (show_background) { - if (block->panel->type && (block->panel->type->flag & PANEL_TYPE_NO_HEADER)) { - if (region->regiontype == RGN_TYPE_TOOLS) { - /* We never want a background around active tools. */ - show_background = false; - } - else { - /* Without a header there is no background except for region overlap. */ - show_background = region->overlap != 0; - } - } - } ui_draw_aligned_panel(&style, block, &rect, UI_panel_category_is_visible(region), - show_background, + UI_panel_should_show_background(region, block->panel->type), region->flag & RGN_FLAG_SEARCH_FILTER_ACTIVE); } diff --git a/source/blender/editors/interface/interface_panel.c b/source/blender/editors/interface/interface_panel.c index 6aa4c5bb4a7..d1daf5b48bf 100644 --- a/source/blender/editors/interface/interface_panel.c +++ b/source/blender/editors/interface/interface_panel.c @@ -1334,6 +1334,26 @@ void ui_draw_aligned_panel(const uiStyle *style, } } +bool UI_panel_should_show_background(const ARegion *region, const PanelType *panel_type) +{ + if (region->alignment == RGN_ALIGN_FLOAT) { + return false; + } + + if (panel_type && panel_type->flag & PANEL_TYPE_NO_HEADER) { + if (region->regiontype == RGN_TYPE_TOOLS) { + /* We never want a background around active tools. */ + return false; + } + else { + /* Without a header there is no background except for region overlap. */ + return region->overlap != 0; + } + } + + return true; +} + /** \} */ /* -------------------------------------------------------------------- */ @@ -1746,17 +1766,22 @@ static bool uiAlignPanelStep(ARegion *region, const float factor, const bool dra const int region_offset_x = panel_region_offset_x_get(region); for (int i = 0; i < active_panels_len; i++) { PanelSort *ps = &panel_sort[i]; - const bool no_header = ps->panel->type->flag & PANEL_TYPE_NO_HEADER; + const bool show_background = UI_panel_should_show_background(region, ps->panel->type); ps->panel->runtime.region_ofsx = region_offset_x; - ps->new_offset_x = region_offset_x + (no_header ? 0 : UI_PANEL_MARGIN_X); + ps->new_offset_x = region_offset_x + (show_background ? UI_PANEL_MARGIN_X : 0); } /* Y offset. */ for (int i = 0, y = 0; i < active_panels_len; i++) { PanelSort *ps = &panel_sort[i]; + const bool show_background = UI_panel_should_show_background(region, ps->panel->type); + y -= get_panel_real_size_y(ps->panel); - y -= UI_PANEL_MARGIN_Y; + /* Separate panel boxes a bit further (if they are drawn). */ + if (show_background) { + y -= UI_PANEL_MARGIN_Y; + } ps->new_offset_y = y; /* The header still draws offset by the size of closed panels, so apply the offset here. */ if (UI_panel_is_closed(ps->panel)) { -- cgit v1.2.3 From 5a11c6e558c6581cc07d2a1d67db460241255f09 Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Thu, 25 Nov 2021 17:15:48 +0100 Subject: Fix missing margin below panels A minor cosmetic fix. When the view was scrolled all the way to the bottom, the lowest panel would end right on the view edge. The scrollable view should get the same margin at the bottom as used at the top. --- source/blender/editors/interface/interface_panel.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'source/blender/editors/interface') diff --git a/source/blender/editors/interface/interface_panel.c b/source/blender/editors/interface/interface_panel.c index d1daf5b48bf..06edf46fab7 100644 --- a/source/blender/editors/interface/interface_panel.c +++ b/source/blender/editors/interface/interface_panel.c @@ -1827,6 +1827,7 @@ static void ui_panels_size(ARegion *region, int *r_x, int *r_y) { int sizex = 0; int sizey = 0; + bool has_panel_with_background = false; /* Compute size taken up by panels, for setting in view2d. */ LISTBASE_FOREACH (Panel *, panel, ®ion->panels) { @@ -1836,6 +1837,9 @@ static void ui_panels_size(ARegion *region, int *r_x, int *r_y) sizex = max_ii(sizex, pa_sizex); sizey = min_ii(sizey, pa_sizey); + if (UI_panel_should_show_background(region, panel->type)) { + has_panel_with_background = true; + } } } @@ -1845,6 +1849,11 @@ static void ui_panels_size(ARegion *region, int *r_x, int *r_y) if (sizey == 0) { sizey = -UI_PANEL_WIDTH; } + /* Extra margin after the list so the view scrolls a few pixels further than the panel border. + * Also makes the bottom match the top margin. */ + if (has_panel_with_background) { + sizey -= UI_PANEL_MARGIN_Y; + } *r_x = sizex; *r_y = sizey; -- cgit v1.2.3