diff options
author | Harley Acheson <harley.acheson@gmail.com> | 2020-01-03 07:37:35 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2020-01-03 07:37:35 +0300 |
commit | ac7eb7108907ff20681ce8fe71723f7fa06dcdf4 (patch) | |
tree | cafdd915003609ef66a42f44dc3db346f4508064 /source/blender/editors/screen | |
parent | d8dc3101033dfc733fd5d1160660a770a35a01e4 (diff) |
UI: Improve toolbar width snapping
Allow narrower toolbar before snapping to two column layout.
Diffstat (limited to 'source/blender/editors/screen')
-rw-r--r-- | source/blender/editors/screen/area_utils.c | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/source/blender/editors/screen/area_utils.c b/source/blender/editors/screen/area_utils.c index 61fb9d5a3a8..fc76b3f7c09 100644 --- a/source/blender/editors/screen/area_utils.c +++ b/source/blender/editors/screen/area_utils.c @@ -33,6 +33,7 @@ #include "ED_screen.h" #include "UI_interface.h" +#include "UI_interface_icons.h" /* -------------------------------------------------------------------- */ /** \name Generic Tool System Region Callbacks @@ -63,17 +64,23 @@ void ED_region_generic_tools_region_message_subscribe(const struct bContext *UNU int ED_region_generic_tools_region_snap_size(const ARegion *ar, int size, int axis) { if (axis == 0) { - /* Note, this depends on the icon size: see #ICON_DEFAULT_HEIGHT_TOOLBAR. */ - const float snap_units[] = {2 + 0.8f, 4 + 0.8f}; const float aspect = BLI_rctf_size_x(&ar->v2d.cur) / (BLI_rcti_size_x(&ar->v2d.mask) + 1); + const int icon_size = ICON_DEFAULT_HEIGHT_TOOLBAR / aspect; + const float column = 1.25f * icon_size; + const float margin = 0.5f * icon_size; + const float snap_units[] = { + column + margin, (2.0f * column) + margin, (2.7f * column) + margin}; int best_diff = INT_MAX; int best_size = size; - for (uint i = 0; i < ARRAY_SIZE(snap_units); i += 1) { - const int test_size = (snap_units[i] * U.widget_unit) / (UI_DPI_FAC * aspect); - const int test_diff = ABS(test_size - size); - if (test_diff < best_diff) { - best_size = test_size; - best_diff = test_diff; + /* Only snap if less than last snap unit. */ + if (size <= snap_units[ARRAY_SIZE(snap_units) - 1]) { + for (uint i = 0; i < ARRAY_SIZE(snap_units); i += 1) { + const int test_size = snap_units[i]; + const int test_diff = ABS(test_size - size); + if (test_diff < best_diff) { + best_size = test_size; + best_diff = test_diff; + } } } return best_size; |