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. Implemented as part of #104831. Pull Request: https://projects.blender.org/blender/blender/pulls/109027
This commit is contained in:
committed by
Julian Eisel
parent
bbcdf88f82
commit
248b322896
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user