UI: Improve how region size snapping respects the maximum size #109027

Merged
Julian Eisel merged 4 commits from JulianEisel/blender:temp-region-snap-maxsize into main 2023-07-03 13:06:45 +02:00
1 changed files with 16 additions and 4 deletions

View File

@ -2836,14 +2836,20 @@ static int region_scale_modal(bContext *C, wmOperator *op, const wmEvent *event)
const int size_no_snap = rmd->origval + delta;
rmd->region->sizex = size_no_snap;
/* Clamp before snapping, so the snapping doesn't use a size that's invalid anyway. It will
* check for and respect the max-width too. */
CLAMP(rmd->region->sizex, 0, rmd->maxsize);
if (rmd->region->type->snap_size) {
short sizex_test = rmd->region->type->snap_size(rmd->region, rmd->region->sizex, 0);
if (abs(rmd->region->sizex - sizex_test) < snap_size_threshold) {
if ((abs(rmd->region->sizex - sizex_test) < snap_size_threshold) &&
/* Don't snap to a new size if that would exceed the maximum width. */
sizex_test <= rmd->maxsize)
{
rmd->region->sizex = sizex_test;
}
}
CLAMP(rmd->region->sizex, 0, rmd->maxsize);
BLI_assert(rmd->region->sizex <= rmd->maxsize);
if (size_no_snap < UI_UNIT_X / aspect) {
rmd->region->sizex = rmd->origval;
@ -2869,14 +2875,20 @@ static int region_scale_modal(bContext *C, wmOperator *op, const wmEvent *event)
const int size_no_snap = rmd->origval + delta;
rmd->region->sizey = size_no_snap;
/* Clamp before snapping, so the snapping doesn't use a size that's invalid anyway. It will
* check for and respect the max-height too. */
CLAMP(rmd->region->sizey, 0, rmd->maxsize);
if (rmd->region->type->snap_size) {
short sizey_test = rmd->region->type->snap_size(rmd->region, rmd->region->sizey, 1);
if (abs(rmd->region->sizey - sizey_test) < snap_size_threshold) {
if ((abs(rmd->region->sizey - sizey_test) < snap_size_threshold) &&
/* Don't snap to a new size if that would exceed the maximum height. */
(sizey_test <= rmd->maxsize))
{
rmd->region->sizey = sizey_test;
}
}
CLAMP(rmd->region->sizey, 0, rmd->maxsize);
BLI_assert(rmd->region->sizey <= rmd->maxsize);
/* NOTE: `UI_UNIT_Y / 4` means you need to drag the footer and execute region
* almost all the way down for it to become hidden, this is done