From 55bf1f7e765fa828b177e0526afb413aad2fa8ca Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Thu, 25 May 2023 13:58:03 -0700 Subject: [PATCH 1/7] UI: Fix Scrollbar overlaps sidebar on zoom When zooming an area with panel category tabs, the vertical scroll bar can be placed in a position that overlaps the tabs. --- source/blender/editors/screen/area.cc | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/source/blender/editors/screen/area.cc b/source/blender/editors/screen/area.cc index e8374c8c6df..16effaff0b4 100644 --- a/source/blender/editors/screen/area.cc +++ b/source/blender/editors/screen/area.cc @@ -3130,11 +3130,27 @@ void ED_region_panels_draw(const bContext *C, ARegion *region) /* scrollers */ bool use_mask = false; rcti mask; - if (region->runtime.category && (RGN_ALIGN_ENUM_FROM_MASK(region->alignment) == RGN_ALIGN_RIGHT)) + if (region->runtime.category && + (RGN_ALIGN_ENUM_FROM_MASK(region->alignment) == RGN_ALIGN_RIGHT) && + UI_panel_category_is_visible(region)) { use_mask = true; UI_view2d_mask_from_win(v2d, &mask); - mask.xmax -= UI_PANEL_CATEGORY_MARGIN_WIDTH; + const int category_tabs_width = round_fl_to_int(UI_view2d_scale_get_x(®ion->v2d) * + UI_PANEL_CATEGORY_MARGIN_WIDTH); + mask.xmax = mask.xmax - category_tabs_width; + BLI_rcti_translate(®ion->v2d.vert, -category_tabs_width, 0); + + /* Adjust the scroller's action zone. */ + LISTBASE_FOREACH (AZone *, az, &CTX_wm_area(C)->actionzones) { + if (!(az->region == region && az->type == AZONE_REGION_SCROLL)) { + continue; + } + az->x1 = region->v2d.vert.xmin + region->winrct.xmin - V2D_SCROLL_HIDE_WIDTH; + az->x2 = region->v2d.vert.xmax + region->winrct.xmin + V2D_SCROLL_HIDE_WIDTH; + BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2); + break; + } } bool use_full_hide = false; if (region->overlap) { -- 2.30.2 From 765d4589e516993be6fa0d2ae7131fae414db246 Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Fri, 26 May 2023 10:09:02 -0700 Subject: [PATCH 2/7] Updated to incorporate changes requested by review --- source/blender/editors/include/ED_screen.h | 5 +++++ source/blender/editors/screen/area.cc | 13 +++++-------- source/blender/editors/screen/screen_ops.c | 10 ++++++++++ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/source/blender/editors/include/ED_screen.h b/source/blender/editors/include/ED_screen.h index 88dee5e1265..6815320adb6 100644 --- a/source/blender/editors/include/ED_screen.h +++ b/source/blender/editors/include/ED_screen.h @@ -215,7 +215,12 @@ void ED_area_tag_refresh(ScrArea *area); * Only exported for WM. */ void ED_area_do_refresh(struct bContext *C, ScrArea *area); + +struct AZone *ED_area_actionzone_find_by_type(const struct ScrArea *area, + const struct ARegion *region, + int azone_type); struct AZone *ED_area_azones_update(ScrArea *area, const int mouse_xy[2]); + /** * Show the given text in the area's header, instead of its regular contents. * Use NULL to disable this and show the regular header contents again. diff --git a/source/blender/editors/screen/area.cc b/source/blender/editors/screen/area.cc index 16effaff0b4..6862a19ff96 100644 --- a/source/blender/editors/screen/area.cc +++ b/source/blender/editors/screen/area.cc @@ -3138,18 +3138,15 @@ void ED_region_panels_draw(const bContext *C, ARegion *region) UI_view2d_mask_from_win(v2d, &mask); const int category_tabs_width = round_fl_to_int(UI_view2d_scale_get_x(®ion->v2d) * UI_PANEL_CATEGORY_MARGIN_WIDTH); - mask.xmax = mask.xmax - category_tabs_width; + mask.xmax -= category_tabs_width; BLI_rcti_translate(®ion->v2d.vert, -category_tabs_width, 0); /* Adjust the scroller's action zone. */ - LISTBASE_FOREACH (AZone *, az, &CTX_wm_area(C)->actionzones) { - if (!(az->region == region && az->type == AZONE_REGION_SCROLL)) { - continue; - } - az->x1 = region->v2d.vert.xmin + region->winrct.xmin - V2D_SCROLL_HIDE_WIDTH; - az->x2 = region->v2d.vert.xmax + region->winrct.xmin + V2D_SCROLL_HIDE_WIDTH; + AZone *az = ED_area_actionzone_find_by_type(CTX_wm_area(C), region, AZONE_REGION_SCROLL); + if (az) { + az->x1 = region->winrct.xmin + region->v2d.vert.xmin - V2D_SCROLL_HIDE_WIDTH; + az->x2 = region->winrct.xmin + region->v2d.vert.xmax + V2D_SCROLL_HIDE_WIDTH; BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2); - break; } } bool use_full_hide = false; diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c index aa06a239e11..166e7293da4 100644 --- a/source/blender/editors/screen/screen_ops.c +++ b/source/blender/editors/screen/screen_ops.c @@ -997,6 +997,16 @@ AZone *ED_area_actionzone_find_xy(ScrArea *area, const int xy[2]) return area_actionzone_refresh_xy(area, xy, true); } +AZone *ED_area_actionzone_find_by_type(ScrArea *area, ARegion *region, int azone_type) +{ + LISTBASE_FOREACH (AZone *, az, &area->actionzones) { + if (az->region == region && az->type == azone_type) { + return az; + } + } + return NULL; +} + AZone *ED_area_azones_update(ScrArea *area, const int xy[2]) { return area_actionzone_refresh_xy(area, xy, false); -- 2.30.2 From b17bb6ae70d28ff7b00a78eff1b31eb872758b2f Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Tue, 20 Jun 2023 17:12:20 -0700 Subject: [PATCH 3/7] Do not move scroll action zones. Instead use scroller position rather than azone position. --- source/blender/editors/include/ED_screen.h | 4 --- source/blender/editors/screen/area.cc | 8 ----- source/blender/editors/screen/screen_ops.c | 40 ++++++++++++++-------- 3 files changed, 25 insertions(+), 27 deletions(-) diff --git a/source/blender/editors/include/ED_screen.h b/source/blender/editors/include/ED_screen.h index 6815320adb6..d95c77d5b7e 100644 --- a/source/blender/editors/include/ED_screen.h +++ b/source/blender/editors/include/ED_screen.h @@ -215,10 +215,6 @@ void ED_area_tag_refresh(ScrArea *area); * Only exported for WM. */ void ED_area_do_refresh(struct bContext *C, ScrArea *area); - -struct AZone *ED_area_actionzone_find_by_type(const struct ScrArea *area, - const struct ARegion *region, - int azone_type); struct AZone *ED_area_azones_update(ScrArea *area, const int mouse_xy[2]); /** diff --git a/source/blender/editors/screen/area.cc b/source/blender/editors/screen/area.cc index 6862a19ff96..4794af235c1 100644 --- a/source/blender/editors/screen/area.cc +++ b/source/blender/editors/screen/area.cc @@ -3140,14 +3140,6 @@ void ED_region_panels_draw(const bContext *C, ARegion *region) UI_PANEL_CATEGORY_MARGIN_WIDTH); mask.xmax -= category_tabs_width; BLI_rcti_translate(®ion->v2d.vert, -category_tabs_width, 0); - - /* Adjust the scroller's action zone. */ - AZone *az = ED_area_actionzone_find_by_type(CTX_wm_area(C), region, AZONE_REGION_SCROLL); - if (az) { - az->x1 = region->winrct.xmin + region->v2d.vert.xmin - V2D_SCROLL_HIDE_WIDTH; - az->x2 = region->winrct.xmin + region->v2d.vert.xmax + V2D_SCROLL_HIDE_WIDTH; - BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2); - } } bool use_full_hide = false; if (region->overlap) { diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c index 166e7293da4..5ebb89cb059 100644 --- a/source/blender/editors/screen/screen_ops.c +++ b/source/blender/editors/screen/screen_ops.c @@ -816,17 +816,37 @@ static bool azone_clipped_rect_calc(const AZone *az, rcti *r_rect_clip) return false; } +static void area_actionzone_get_rect(AZone *az, rcti *rect) +{ + if (az->type == AZONE_REGION_SCROLL) { + rcti scroller_vert = (az->direction == AZ_SCROLL_HOR) ? az->region->v2d.hor : + az->region->v2d.vert; + BLI_rcti_translate(&scroller_vert, az->region->winrct.xmin, az->region->winrct.ymin); + rect->xmin = scroller_vert.xmin - ((az->direction == AZ_SCROLL_VERT) ? V2D_SCROLL_HIDE_HEIGHT : 0); + rect->ymin = scroller_vert.ymin - + ((az->direction == AZ_SCROLL_HOR) ? V2D_SCROLL_HIDE_WIDTH : 0); + rect->xmax = scroller_vert.xmax + + ((az->direction == AZ_SCROLL_VERT) ? V2D_SCROLL_HIDE_HEIGHT : 0); + rect->ymax = scroller_vert.ymax + + ((az->direction == AZ_SCROLL_HOR) ? V2D_SCROLL_HIDE_WIDTH : 0); + } + else if (az->type == AZONE_REGION) { + azone_clipped_rect_calc(az, rect); + } + else { + *rect = az->rect; + } +} + static AZone *area_actionzone_refresh_xy(ScrArea *area, const int xy[2], const bool test_only) { AZone *az = NULL; for (az = area->actionzones.first; az; az = az->next) { - rcti az_rect_clip; - if (BLI_rcti_isect_pt_v(&az->rect, xy) && - /* Check clipping if this is clipped */ - (!azone_clipped_rect_calc(az, &az_rect_clip) || BLI_rcti_isect_pt_v(&az_rect_clip, xy))) + rcti az_rect; + area_actionzone_get_rect(az, &az_rect); + if (BLI_rcti_isect_pt_v(&az_rect, xy)) { - if (az->type == AZONE_AREA) { break; } @@ -997,16 +1017,6 @@ AZone *ED_area_actionzone_find_xy(ScrArea *area, const int xy[2]) return area_actionzone_refresh_xy(area, xy, true); } -AZone *ED_area_actionzone_find_by_type(ScrArea *area, ARegion *region, int azone_type) -{ - LISTBASE_FOREACH (AZone *, az, &area->actionzones) { - if (az->region == region && az->type == azone_type) { - return az; - } - } - return NULL; -} - AZone *ED_area_azones_update(ScrArea *area, const int xy[2]) { return area_actionzone_refresh_xy(area, xy, false); -- 2.30.2 From 7c1fb46f072a5fb5df43a49d959f46f931a81c14 Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Tue, 20 Jun 2023 17:45:19 -0700 Subject: [PATCH 4/7] Small changes, cleanup. --- source/blender/editors/include/ED_screen.h | 1 - source/blender/editors/screen/area.cc | 11 +---------- source/blender/editors/screen/screen_ops.c | 5 +++-- 3 files changed, 4 insertions(+), 13 deletions(-) diff --git a/source/blender/editors/include/ED_screen.h b/source/blender/editors/include/ED_screen.h index d95c77d5b7e..88dee5e1265 100644 --- a/source/blender/editors/include/ED_screen.h +++ b/source/blender/editors/include/ED_screen.h @@ -216,7 +216,6 @@ void ED_area_tag_refresh(ScrArea *area); */ void ED_area_do_refresh(struct bContext *C, ScrArea *area); struct AZone *ED_area_azones_update(ScrArea *area, const int mouse_xy[2]); - /** * Show the given text in the area's header, instead of its regular contents. * Use NULL to disable this and show the regular header contents again. diff --git a/source/blender/editors/screen/area.cc b/source/blender/editors/screen/area.cc index 4794af235c1..7359ce7ea86 100644 --- a/source/blender/editors/screen/area.cc +++ b/source/blender/editors/screen/area.cc @@ -1062,7 +1062,6 @@ static void region_azone_scrollbar_init(ScrArea *area, { rcti scroller_vert = (direction == AZ_SCROLL_VERT) ? region->v2d.vert : region->v2d.hor; AZone *az = static_cast(MEM_callocN(sizeof(*az), __func__)); - float hide_width; BLI_addtail(&area->actionzones, az); az->type = AZONE_REGION_SCROLL; @@ -1071,20 +1070,12 @@ static void region_azone_scrollbar_init(ScrArea *area, if (direction == AZ_SCROLL_VERT) { az->region->v2d.alpha_vert = 0; - hide_width = V2D_SCROLL_HIDE_HEIGHT; } else if (direction == AZ_SCROLL_HOR) { az->region->v2d.alpha_hor = 0; - hide_width = V2D_SCROLL_HIDE_WIDTH; } - BLI_rcti_translate(&scroller_vert, region->winrct.xmin, region->winrct.ymin); - az->x1 = scroller_vert.xmin - ((direction == AZ_SCROLL_VERT) ? hide_width : 0); - az->y1 = scroller_vert.ymin - ((direction == AZ_SCROLL_HOR) ? hide_width : 0); - az->x2 = scroller_vert.xmax + ((direction == AZ_SCROLL_VERT) ? hide_width : 0); - az->y2 = scroller_vert.ymax + ((direction == AZ_SCROLL_HOR) ? hide_width : 0); - - BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2); + /* No need to set az sizes. For intersection we'll use region's scroller rect instead. */ } static void region_azones_scrollbars_init(ScrArea *area, ARegion *region) diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c index 5ebb89cb059..db15588d0c6 100644 --- a/source/blender/editors/screen/screen_ops.c +++ b/source/blender/editors/screen/screen_ops.c @@ -847,6 +847,7 @@ static AZone *area_actionzone_refresh_xy(ScrArea *area, const int xy[2], const b area_actionzone_get_rect(az, &az_rect); if (BLI_rcti_isect_pt_v(&az_rect, xy)) { + if (az->type == AZONE_AREA) { break; } @@ -934,7 +935,7 @@ static AZone *area_actionzone_refresh_xy(ScrArea *area, const int xy[2], const b float dist_fac = 0.0f, alpha = 0.0f; if (az->direction == AZ_SCROLL_HOR) { - float hide_width = (az->y2 - az->y1) / 2.0f; + float hide_width = V2D_SCROLL_HIDE_WIDTH; dist_fac = BLI_rcti_length_y(&v2d->hor, local_xy[1]) / hide_width; CLAMP(dist_fac, 0.0f, 1.0f); alpha = 1.0f - dist_fac; @@ -942,7 +943,7 @@ static AZone *area_actionzone_refresh_xy(ScrArea *area, const int xy[2], const b v2d->alpha_hor = alpha * 255; } else if (az->direction == AZ_SCROLL_VERT) { - float hide_width = (az->x2 - az->x1) / 2.0f; + float hide_width = V2D_SCROLL_HIDE_HEIGHT; dist_fac = BLI_rcti_length_x(&v2d->vert, local_xy[0]) / hide_width; CLAMP(dist_fac, 0.0f, 1.0f); alpha = 1.0f - dist_fac; -- 2.30.2 From 2c5a5d96c71e02e2cc4fdd1f0f995156ecc377c7 Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Tue, 20 Jun 2023 17:54:46 -0700 Subject: [PATCH 5/7] simplification. --- source/blender/editors/screen/area.cc | 10 +++------- source/blender/editors/screen/screen_ops.c | 6 ++---- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/source/blender/editors/screen/area.cc b/source/blender/editors/screen/area.cc index 7359ce7ea86..34e0d216e4b 100644 --- a/source/blender/editors/screen/area.cc +++ b/source/blender/editors/screen/area.cc @@ -3121,16 +3121,12 @@ void ED_region_panels_draw(const bContext *C, ARegion *region) /* scrollers */ bool use_mask = false; rcti mask; - if (region->runtime.category && - (RGN_ALIGN_ENUM_FROM_MASK(region->alignment) == RGN_ALIGN_RIGHT) && - UI_panel_category_is_visible(region)) + if (region->runtime.category && (RGN_ALIGN_ENUM_FROM_MASK(region->alignment) == RGN_ALIGN_RIGHT)) { use_mask = true; UI_view2d_mask_from_win(v2d, &mask); - const int category_tabs_width = round_fl_to_int(UI_view2d_scale_get_x(®ion->v2d) * - UI_PANEL_CATEGORY_MARGIN_WIDTH); - mask.xmax -= category_tabs_width; - BLI_rcti_translate(®ion->v2d.vert, -category_tabs_width, 0); + mask.xmax -= round_fl_to_int(UI_view2d_scale_get_x(®ion->v2d) * + UI_PANEL_CATEGORY_MARGIN_WIDTH); } bool use_full_hide = false; if (region->overlap) { diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c index db15588d0c6..b1caa10af9f 100644 --- a/source/blender/editors/screen/screen_ops.c +++ b/source/blender/editors/screen/screen_ops.c @@ -935,16 +935,14 @@ static AZone *area_actionzone_refresh_xy(ScrArea *area, const int xy[2], const b float dist_fac = 0.0f, alpha = 0.0f; if (az->direction == AZ_SCROLL_HOR) { - float hide_width = V2D_SCROLL_HIDE_WIDTH; - dist_fac = BLI_rcti_length_y(&v2d->hor, local_xy[1]) / hide_width; + dist_fac = BLI_rcti_length_y(&v2d->hor, local_xy[1]) / V2D_SCROLL_HIDE_WIDTH; CLAMP(dist_fac, 0.0f, 1.0f); alpha = 1.0f - dist_fac; v2d->alpha_hor = alpha * 255; } else if (az->direction == AZ_SCROLL_VERT) { - float hide_width = V2D_SCROLL_HIDE_HEIGHT; - dist_fac = BLI_rcti_length_x(&v2d->vert, local_xy[0]) / hide_width; + dist_fac = BLI_rcti_length_x(&v2d->vert, local_xy[0]) / V2D_SCROLL_HIDE_HEIGHT; CLAMP(dist_fac, 0.0f, 1.0f); alpha = 1.0f - dist_fac; -- 2.30.2 From 7d6311a9854c80b830ee4c71dbc83438c69fba93 Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Wed, 21 Jun 2023 08:18:26 -0700 Subject: [PATCH 6/7] Comment changes, putting UI_panel_category_is_visible back in, etc --- source/blender/editors/screen/area.cc | 7 +++++-- source/blender/editors/screen/screen_ops.c | 7 +++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/source/blender/editors/screen/area.cc b/source/blender/editors/screen/area.cc index 34e0d216e4b..044e7f20265 100644 --- a/source/blender/editors/screen/area.cc +++ b/source/blender/editors/screen/area.cc @@ -1075,7 +1075,8 @@ static void region_azone_scrollbar_init(ScrArea *area, az->region->v2d.alpha_hor = 0; } - /* No need to set az sizes. For intersection we'll use region's scroller rect instead. */ + /* No need to specify rect for scrollbar az. For intersection we'll test against the area around + * the region's scroller instead, in `area_actionzone_get_rect`. */ } static void region_azones_scrollbars_init(ScrArea *area, ARegion *region) @@ -3121,7 +3122,9 @@ void ED_region_panels_draw(const bContext *C, ARegion *region) /* scrollers */ bool use_mask = false; rcti mask; - if (region->runtime.category && (RGN_ALIGN_ENUM_FROM_MASK(region->alignment) == RGN_ALIGN_RIGHT)) + if (region->runtime.category && + (RGN_ALIGN_ENUM_FROM_MASK(region->alignment) == RGN_ALIGN_RIGHT) && + UI_panel_category_is_visible(region)) { use_mask = true; UI_view2d_mask_from_win(v2d, &mask); diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c index b1caa10af9f..629ada40aa9 100644 --- a/source/blender/editors/screen/screen_ops.c +++ b/source/blender/editors/screen/screen_ops.c @@ -816,9 +816,11 @@ static bool azone_clipped_rect_calc(const AZone *az, rcti *r_rect_clip) return false; } +/* Return the azone's calculated rect. */ static void area_actionzone_get_rect(AZone *az, rcti *rect) { if (az->type == AZONE_REGION_SCROLL) { + /* For scroll azones use the area around the region's scrollbar location. */ rcti scroller_vert = (az->direction == AZ_SCROLL_HOR) ? az->region->v2d.hor : az->region->v2d.vert; BLI_rcti_translate(&scroller_vert, az->region->winrct.xmin, az->region->winrct.ymin); @@ -830,11 +832,8 @@ static void area_actionzone_get_rect(AZone *az, rcti *rect) rect->ymax = scroller_vert.ymax + ((az->direction == AZ_SCROLL_HOR) ? V2D_SCROLL_HIDE_WIDTH : 0); } - else if (az->type == AZONE_REGION) { - azone_clipped_rect_calc(az, rect); - } else { - *rect = az->rect; + azone_clipped_rect_calc(az, rect); } } -- 2.30.2 From 0a32002e1798bfe32dcf0a223b091070a0b1f508 Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Thu, 22 Jun 2023 09:32:08 -0700 Subject: [PATCH 7/7] Removing unused variable --- source/blender/editors/screen/area.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/source/blender/editors/screen/area.cc b/source/blender/editors/screen/area.cc index 044e7f20265..c2e734b3823 100644 --- a/source/blender/editors/screen/area.cc +++ b/source/blender/editors/screen/area.cc @@ -1060,7 +1060,6 @@ static void region_azone_scrollbar_init(ScrArea *area, ARegion *region, AZScrollDirection direction) { - rcti scroller_vert = (direction == AZ_SCROLL_VERT) ? region->v2d.vert : region->v2d.hor; AZone *az = static_cast(MEM_callocN(sizeof(*az), __func__)); BLI_addtail(&area->actionzones, az); -- 2.30.2