From c87d05b23608ad1cebf6d9122b5300e6ed505bdb Mon Sep 17 00:00:00 2001 From: guishe Date: Wed, 22 Mar 2023 13:33:52 -0600 Subject: [PATCH] UI: Fix Scrollbar overlaps sidebar on zoom When zooming into an area with a sidebar, the vertical scroll bar may overlay the sidebar. To address this issue, the proposed patch adjusts the offset of the scrollbar, so now it scales with the zoom of the region. --- source/blender/editors/include/UI_interface.h | 6 ++++ .../editors/interface/views/interface_view.cc | 12 +++++++ source/blender/editors/screen/area.cc | 35 +++++++++++++++---- 3 files changed, 46 insertions(+), 7 deletions(-) diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index 6c6fbc9b058..06e6f101808 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -3291,6 +3291,12 @@ uiViewHandle *UI_region_view_find_at(const struct ARegion *region, const int xy[ uiViewItemHandle *UI_region_views_find_item_at(const struct ARegion *region, const int xy[2]) ATTR_NONNULL(); uiViewItemHandle *UI_region_views_find_active_item(const struct ARegion *region); +/** + * \return the width in pixels of the sidebar when it exists and is aligned to the right within the + * region. + * \return 0 if there is no sidebar in the region. + */ +float UI_panel_region_right_sidebar_width_get(const struct ARegion *region); #ifdef __cplusplus } diff --git a/source/blender/editors/interface/views/interface_view.cc b/source/blender/editors/interface/views/interface_view.cc index 4c6fd59361a..60eace6e74c 100644 --- a/source/blender/editors/interface/views/interface_view.cc +++ b/source/blender/editors/interface/views/interface_view.cc @@ -301,3 +301,15 @@ uiButViewItem *ui_block_view_find_matching_view_item_but_in_old_block( return nullptr; } + +float UI_panel_region_right_sidebar_width_get(const ARegion *region) +{ + if (UI_panel_category_is_visible(region) && + RGN_ALIGN_ENUM_FROM_MASK(region->alignment) == RGN_ALIGN_RIGHT && region->uiblocks.first) + { + const float aspect = ((uiBlock *)region->uiblocks.first)->aspect; + const float zoom = 1.0f / aspect; + return round_fl_to_int(UI_PANEL_CATEGORY_MARGIN_WIDTH * zoom); + } + return 0.0f; +} diff --git a/source/blender/editors/screen/area.cc b/source/blender/editors/screen/area.cc index e8374c8c6df..a98af7daa92 100644 --- a/source/blender/editors/screen/area.cc +++ b/source/blender/editors/screen/area.cc @@ -57,6 +57,8 @@ #include "screen_intern.h" +#include "../interface/view2d_intern.hh" + enum RegionEmbossSide { REGION_EMBOSS_LEFT = (1 << 0), REGION_EMBOSS_TOP = (1 << 1), @@ -1056,6 +1058,26 @@ static void region_azone_edge_init(ScrArea *area, } } +void apply_sidebar_offset_scrollbar_azone(ScrArea *area, ARegion *region) +{ + if (!UI_panel_category_is_visible(region)) { + return; + } + LISTBASE_FOREACH (AZone *, az, &area->actionzones) { + if (!(az->region == region && az->type == AZONE_REGION_SCROLL)) { + continue; + } + rcti scroller_vert = region->v2d.vert; + BLI_rcti_translate(&scroller_vert, region->winrct.xmin, region->winrct.ymin); + + const float hide_width = V2D_SCROLL_HIDE_HEIGHT; + az->x1 = scroller_vert.xmin - hide_width; + az->x2 = scroller_vert.xmax + hide_width; + BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2); + break; + } +} + static void region_azone_scrollbar_init(ScrArea *area, ARegion *region, AZScrollDirection direction) @@ -3126,15 +3148,13 @@ void ED_region_panels_draw(const bContext *C, ARegion *region) if (region->runtime.category) { UI_panel_category_draw_all(region, region->runtime.category); } - /* scrollers */ - bool use_mask = false; - rcti mask; - if (region->runtime.category && (RGN_ALIGN_ENUM_FROM_MASK(region->alignment) == RGN_ALIGN_RIGHT)) - { - use_mask = true; + rcti mask{}; + float mask_offset = UI_panel_region_right_sidebar_width_get(region); + bool use_mask = mask_offset != 0; + if (use_mask) { UI_view2d_mask_from_win(v2d, &mask); - mask.xmax -= UI_PANEL_CATEGORY_MARGIN_WIDTH; + mask.xmax = mask.xmax - mask_offset; } bool use_full_hide = false; if (region->overlap) { @@ -3142,6 +3162,7 @@ void ED_region_panels_draw(const bContext *C, ARegion *region) use_full_hide = true; } UI_view2d_scrollers_draw_ex(v2d, use_mask ? &mask : nullptr, use_full_hide); + apply_sidebar_offset_scrollbar_azone(CTX_wm_area(C), region); } void ED_region_panels_ex(const bContext *C, ARegion *region, const char *contexts[]) -- 2.30.2