[Bf-blender-cvs] [ac7eb710890] master: UI: Improve toolbar width snapping
Harley Acheson
noreply at git.blender.org
Fri Jan 3 05:40:43 CET 2020
Commit: ac7eb7108907ff20681ce8fe71723f7fa06dcdf4
Author: Harley Acheson
Date: Fri Jan 3 15:37:35 2020 +1100
Branches: master
https://developer.blender.org/rBac7eb7108907ff20681ce8fe71723f7fa06dcdf4
UI: Improve toolbar width snapping
Allow narrower toolbar before snapping to two column layout.
===================================================================
M source/blender/editors/screen/area_utils.c
===================================================================
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;
More information about the Bf-blender-cvs
mailing list