From b9b678e2b08561ea56cdcad43faa0c257abb783f Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Thu, 15 Jun 2023 19:00:03 +0200 Subject: [PATCH 1/2] UI: Improve how region size snapping respects the maximum size Previously, a region that used size snapping could be dragged to a snapped size (say 3 times a column width), but then would be clamped to an unsnapped size (say 2.7 times a column width) to make it fit the available space. Instead clamp the size before snapping, so that snapping respects the available width/height (resulting in 2 times a column width for example). Put differently, the region will not be made taller if there's not enough space to fit the region up to the next snapping point. --- source/blender/editors/screen/screen_ops.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c index cb6e2fbd119..6f8215b9146 100644 --- a/source/blender/editors/screen/screen_ops.c +++ b/source/blender/editors/screen/screen_ops.c @@ -2817,14 +2817,16 @@ 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(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) && + 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; @@ -2850,14 +2852,16 @@ 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(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) && + (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 -- 2.30.2 From 1144ac6f4c848b102f4e29da011bec8e5d9aa1f6 Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Mon, 3 Jul 2023 13:04:33 +0200 Subject: [PATCH 2/2] From review: Add comments --- source/blender/editors/screen/screen_ops.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c index 10cfd440ce8..5af001b5321 100644 --- a/source/blender/editors/screen/screen_ops.c +++ b/source/blender/editors/screen/screen_ops.c @@ -2836,12 +2836,16 @@ 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) && - sizex_test <= rmd->maxsize) { + /* Don't snap to a new size if that would exceed the maximum width. */ + sizex_test <= rmd->maxsize) + { rmd->region->sizex = sizex_test; } } @@ -2871,12 +2875,16 @@ 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) && - (sizey_test <= rmd->maxsize)) { + /* Don't snap to a new size if that would exceed the maximum height. */ + (sizey_test <= rmd->maxsize)) + { rmd->region->sizey = sizey_test; } } -- 2.30.2