UI: Improve region resize edge detection for transparent regions #109753

Merged
Julian Eisel merged 4 commits from JulianEisel/blender:temp-region-resize-edge-offset-fix into main 2023-07-10 12:53:48 +02:00
1 changed files with 33 additions and 5 deletions

View File

@ -930,13 +930,41 @@ static void fullscreen_azone_init(ScrArea *area, ARegion *region)
BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2);
}
/**
* Return true if the background color alpha is close to fully transparent. That is, a value of
* less than 50 on a [0-255] scale (rather arbitrary threshold). Assumes the region uses #TH_BACK
* for its background.
*/
static bool region_background_is_transparent(const ScrArea *area, const ARegion *region)
JulianEisel marked this conversation as resolved Outdated

Naming: region_back_is_barely_visible reads a bit strangely, something may be invisible because of it's size/placement.

region_background_is_transparent the doc-string can note that a threshold is used. Or the name could be expanded to include that but I don't think it's necessary.

Naming: `region_back_is_barely_visible` reads a bit strangely, something may be invisible because of it's size/placement. `region_background_is_transparent` the doc-string can note that a threshold is used. Or the name could be expanded to include that but I don't think it's necessary.
{
/* Ensure the right theme is active, may not be the case on startup, for example. */
bThemeState theme_state;
UI_Theme_Store(&theme_state);
UI_SetTheme(area->spacetype, region->regiontype);
uchar back[4];
UI_GetThemeColor4ubv(TH_BACK, back);
UI_Theme_Restore(&theme_state);
return back[3] < 50;
}
#define AZONEPAD_EDGE (0.1f * U.widget_unit)
#define AZONEPAD_ICON (0.45f * U.widget_unit)
static void region_azone_edge(AZone *az, ARegion *region)
static void region_azone_edge(const ScrArea *area, AZone *az, const ARegion *region)
{
/* If region is overlapped (transparent background), move #AZone to content.
* Note this is an arbitrary amount that matches nicely with numbers elsewhere. */
int overlap_padding = (region->overlap) ? int(0.4f * U.widget_unit) : 0;
/* If there is no visible region background, users typically expect the #AZone to be closer to
* the content, so move it a bit. */
const int overlap_padding =
/* Header-like regions are usually thin and there's not much padding around them,
* applying an offset would make the edge overlap buttons.*/
(!RGN_TYPE_IS_HEADER_ANY(region->regiontype) &&
/* Is the region background transparent? */
JulianEisel marked this conversation as resolved Outdated

picky would check !RGN_TYPE_IS_HEADER_ANY(region->regiontype) before region_back_is_barely_visible as UI_Theme_Store / UI_Theme_Restore is heavier than this check.

*picky* would check `!RGN_TYPE_IS_HEADER_ANY(region->regiontype)` before `region_back_is_barely_visible` as `UI_Theme_Store` / `UI_Theme_Restore` is heavier than this check.
region->overlap && region_background_is_transparent(area, region)) ?
/* Note that this is an arbitrary amount that matches nicely with numbers elsewhere. */
int(0.4f * U.widget_unit) :
0;
switch (az->edge) {
case AE_TOP_TO_BOTTOMRIGHT:
@ -1053,7 +1081,7 @@ static void region_azone_edge_init(ScrArea *area,
region_azone_tab_plus(area, az, region);
}
else {
region_azone_edge(az, region);
region_azone_edge(area, az, region);
}
}