[Bf-blender-cvs] [eb4c60124cc] blender2.8: UI: multi-column toolbar support

Campbell Barton noreply at git.blender.org
Fri Apr 27 18:02:47 CEST 2018


Commit: eb4c60124cc2b3aeba5eeb3090bea92543f066a9
Author: Campbell Barton
Date:   Fri Apr 27 17:55:17 2018 +0200
Branches: blender2.8
https://developer.blender.org/rBeb4c60124cc2b3aeba5eeb3090bea92543f066a9

UI: multi-column toolbar support

===================================================================

M	release/scripts/startup/bl_ui/space_toolsystem_common.py
M	release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
M	source/blender/editors/screen/screen_ops.c
M	source/blender/editors/space_view3d/space_view3d.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/space_toolsystem_common.py b/release/scripts/startup/bl_ui/space_toolsystem_common.py
index a4b306193c0..8f9d1735e9f 100644
--- a/release/scripts/startup/bl_ui/space_toolsystem_common.py
+++ b/release/scripts/startup/bl_ui/space_toolsystem_common.py
@@ -248,17 +248,39 @@ class ToolSelectPanelHelper:
             view2d.region_to_view(1.0, 0.0)[0] -
             view2d.region_to_view(0.0, 0.0)[0]
         )
-        show_text = (context.region.width / ui_scale) > 100.0
+        width_scale = context.region.width * ui_scale
         del view2d, ui_scale
 
+        empty_text = ""
+        if width_scale > 200.0:
+            show_text = True
+            use_columns = False
+        else:
+            show_text = False
+            if width_scale > 120.0:
+                column_count = 3
+                use_columns = True
+                empty_text = " "  # needed for alignment, grr
+            elif width_scale > 80.0:
+                column_count = 2
+                use_columns = True
+                empty_text = " "  # needed for alignment, grr
+            else:
+                use_columns = False
+
+        # Could support 3x columns.
+        column_index = 0
+
         for tool_items in self.tools_from_context(context):
             if tool_items:
                 col = layout.column(align=True)
-                col.scale_y = scale_y
+                if not use_columns:
+                    col.scale_y = scale_y
                 for item in tool_items:
                     if item is None:
                         col = layout.column(align=True)
-                        col.scale_y = scale_y
+                        if not use_columns:
+                            col.scale_y = scale_y
                         continue
 
                     if type(item) is tuple:
@@ -289,26 +311,41 @@ class ToolSelectPanelHelper:
                     tool_def, icon_name = self._tool_vars_from_def(item, context_mode)
                     is_active = (tool_def == tool_def_active)
                     icon_value = ToolSelectPanelHelper._icon_value_from_icon_handle(icon_name)
+
+                    if use_columns:
+                        col.scale_y = scale_y
+                        if column_index == 0:
+                            row = col.row(align=True)
+                            row.scale_y = scale_y
+                        sub = row
+                    else:
+                        sub = col
+
                     if use_menu:
-                        props = col.operator_menu_hold(
+                        props = sub.operator_menu_hold(
                             "wm.tool_set",
-                            text=item.text if show_text else "",
+                            text=item.text if show_text else empty_text,
                             depress=is_active,
                             menu="WM_MT_toolsystem_submenu",
                             icon_value=icon_value,
                         )
                     else:
-                        props = col.operator(
+                        props = sub.operator(
                             "wm.tool_set",
-                            text=item.text if show_text else "",
+                            text=item.text if show_text else empty_text,
                             depress=is_active,
                             icon_value=icon_value,
                         )
-
                     props.keymap = tool_def[0] or ""
                     props.manipulator_group = tool_def[1] or ""
                     props.index = index
 
+                    if use_columns:
+                        col.scale_y = 1.0
+                        column_index += 1
+                        if column_index == column_count:
+                            column_index = 0
+
     def tools_from_context(cls, context):
         return (cls._tools[None], cls._tools.get(context.mode, ()))
 
diff --git a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
index 1baf564b777..24396e82ec3 100644
--- a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
@@ -337,7 +337,7 @@ class _defs_edit_mesh:
 
     class extrude_cursor(ToolDef):
         text = "Extrude Cursor"
-        icon = None
+        icon = "ops.mesh.bisect"  # placeholder
         widget = None
         keymap = (
             ("mesh.dupli_extrude_cursor", dict(), dict(type='ACTIONMOUSE', value='PRESS')),
diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c
index 847afb5f9f1..5a231a24304 100644
--- a/source/blender/editors/screen/screen_ops.c
+++ b/source/blender/editors/screen/screen_ops.c
@@ -2157,7 +2157,8 @@ static int region_scale_modal(bContext *C, wmOperator *op, const wmEvent *event)
 	switch (event->type) {
 		case MOUSEMOVE:
 		{
-			const int snap_size_threshold = U.widget_unit * 3;
+			const float aspect = BLI_rctf_size_x(&rmd->ar->v2d.cur) / (BLI_rcti_size_x(&rmd->ar->v2d.mask) + 1);
+			const int snap_size_threshold = (U.widget_unit * 3) / aspect;
 			if (rmd->edge == AE_LEFT_TO_TOPRIGHT || rmd->edge == AE_RIGHT_TO_TOPLEFT) {
 				delta = event->x - rmd->origx;
 				if (rmd->edge == AE_LEFT_TO_TOPRIGHT) delta = -delta;
diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c
index 1a23dd0feff..5fcffc75693 100644
--- a/source/blender/editors/space_view3d/space_view3d.c
+++ b/source/blender/editors/space_view3d/space_view3d.c
@@ -1268,10 +1268,19 @@ static int view3d_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 = 3.25f;
+		const float snap_units[3] = {3 + 0.25f, 5 + 0.25, 7 + 0.25};
 		const float aspect = BLI_rctf_size_x(&ar->v2d.cur) / (BLI_rcti_size_x(&ar->v2d.mask) + 1);
-		const int snap_size = (snap_units * U.widget_unit) / aspect;
-		return snap_size;
+		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) / aspect;
+			const int test_diff = ABS(test_size - size);
+			if (test_diff < best_diff) {
+				best_size = test_size;
+				best_diff = test_diff;
+			}
+		}
+		return best_size;
 	}
 	return size;
 }



More information about the Bf-blender-cvs mailing list