UI: multi-column toolbar support
authorCampbell Barton <ideasman42@gmail.com>
Fri, 27 Apr 2018 15:55:17 +0000 (17:55 +0200)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 27 Apr 2018 16:02:45 +0000 (18:02 +0200)
release/scripts/startup/bl_ui/space_toolsystem_common.py
release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
source/blender/editors/screen/screen_ops.c
source/blender/editors/space_view3d/space_view3d.c

index a4b306193c062cb0f4a5be3c7664f49ef485523b..8f9d1735e9fd63a340f536a5ad33e9fe61f60ce3 100644 (file)
@@ -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, ()))
 
index 1baf564b777eea03197363000861ea0466c95f59..24396e82ec33556456c3a092ee527562381c9a34 100644 (file)
@@ -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')),
index 847afb5f9f1acd55cebcddebbfd360fa20e72e84..5a231a24304da56db14fadec1730ad2a52d93b1e 100644 (file)
@@ -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;
index 1a23dd0feff7e6ae94c8800682cd6bf1e02124b6..5fcffc75693837e6fbf66a5cdead4641454dc337 100644 (file)
@@ -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;
 }