UI: Correct default width of toolbars #108292

Merged
Harley Acheson merged 1 commits from lone_noel/blender:fix-toolbar-default-width into blender-v3.6-release 2023-06-08 18:28:05 +02:00
Member

Correct default initial widths of toolbars


The width of the toolbar adjusts incrementally to match the width of a
single or two columns of tool icons before allowing free width
adjustment once the region is wide enough to display labels.

The default width of the toolbar now matches the width it snaps when
displaying one column of icons.
This fixes an issue where the toolbar was slightly too wide when
opening a new editor or resetting to factory defaults.


Comparison

Blender 3.6 Pull Request
default-toolbar-width_360.png default-toolbar-width_fix.png

Issue
The issue can most easily be seen when loading the factory settings
and then adjusting the width of the toolbar in the 3D viewport. The
toolbar will immediately snap to a width slightly narrower than the
default.

Video demonstration by @pablovazquez :

>

Alternative

The width of the toolbar for one column of icons works out to
exactly 56, which is why the current default of 58 is a bit too
wide.

Simply changing all the hard-coded values from 56 to 58 is enough to
fix the issue, but I tried to make some additional changes to hopefully
avoid these values going out of sync with the actual toolbar width in
the future.

Correct default initial widths of toolbars --- The width of the toolbar adjusts incrementally to match the width of a single or two columns of tool icons before allowing free width adjustment once the region is wide enough to display labels. The default width of the toolbar now matches the width it snaps when displaying one column of icons. This fixes an issue where the toolbar was slightly too wide when opening a new editor or resetting to factory defaults. --- **Comparison** |Blender 3.6|Pull Request| |---|---| |![default-toolbar-width_360.png](https://projects.blender.org/attachments/d0677dda-2540-4564-9239-020b4073086f)|![default-toolbar-width_fix.png](https://projects.blender.org/attachments/d8c59cd3-022f-4df9-b599-8aa00715c82d)| **Issue** The issue can most easily be seen when loading the factory settings and then adjusting the width of the toolbar in the 3D viewport. The toolbar will immediately snap to a width slightly narrower than the default. Video demonstration by @pablovazquez : <video controls src=/attachments/68c539ac-f0fd-4048-b485-175715952a82> <</video>> **Alternative** The width of the toolbar for one column of icons works out to exactly `56`, which is why the current default of `58` is a bit too wide. Simply changing all the hard-coded values from `56` to `58` is enough to fix the issue, but I tried to make some additional changes to hopefully avoid these values going out of sync with the actual toolbar width in the future.
Leon Schittek added the
Module
User Interface
label 2023-05-25 21:57:17 +02:00
Leon Schittek added this to the User Interface project 2023-05-25 22:03:19 +02:00
Member

Thanks for working on this!

The changes in the editor region prefsizex assignments from "58" to your function returning 56 is an awesome fix.

But I worry about this new define UI_TOOLBAR_WIDTH being not the width of the toolbar, but also including the left margin. This could possibly lead to errors, and I think it does so in this PR:

Currently the snap_units are 56, 96, 124, so margin (16) plus a column (40), plus another column (40), then plus a bit more (28).

But since your UI_TOOLBAR_WIDTH includes the left margin, your snap_units are 56, 112, 151.191. The best way to see this is to drag the toolbar to two columns and then move your mouse until the cursor indicates the width of the region. Or turn off Region Overlap and you will see the region is wider than you intend.

I wonder if it might make sense to remove the UI_TOOLBAR_WIDTH define and use ED_region_toolbar_size_x() in its place. Then add a columns or column_number argument to that function. The regions would be initiated with 1 column but you could use the function in the calculation of snap positions.

Thanks for working on this! The changes in the editor region prefsizex assignments from "58" to your function returning 56 is an **awesome fix**. But I worry about this new define UI_TOOLBAR_WIDTH being not the width of the toolbar, but also including the left margin. This could possibly lead to errors, and I think it does so in this PR: Currently the snap_units are 56, 96, 124, so margin (16) plus a column (40), plus another column (40), then plus a bit more (28). But since your UI_TOOLBAR_WIDTH includes the left margin, your snap_units are 56, 112, 151.191. The best way to see this is to drag the toolbar to two columns and then move your mouse until the cursor indicates the width of the region. Or turn off Region Overlap and you will see the region is wider than you intend. I wonder if it might make sense to remove the UI_TOOLBAR_WIDTH define and use ED_region_toolbar_size_x() in its place. Then add a columns or column_number argument to that function. The regions would be initiated with 1 column but you could use the function in the calculation of snap positions.
Author
Member

Currently the snap_units are 56, 96, 124, so margin (16) plus a column (40), plus another column (40), then plus a bit more (28).

But since your UI_TOOLBAR_WIDTH includes the left margin, your snap_units are 56, 112, 151.191.

Oh shoot. I missed that factoring out the column number changed the resulting width. Fixed it as suggested. thanks.

I wonder if it might make sense to remove the UI_TOOLBAR_WIDTH define and use ED_region_toolbar_size_x() in its place. Then add a columns or column_number argument to that function. The regions would be initiated with 1 column but you could use the function in the calculation of snap positions.

Now that I see it, I think this is indeed nicer without the macro. It also allows to easily and exlicitly set the width to two columns of icons with ED_region_toolbar_size_x(2.0f) in case we ever want that.

Thanks for checking this out!

> Currently the snap_units are 56, 96, 124, so margin (16) plus a column (40), plus another column (40), then plus a bit more (28). > > But since your UI_TOOLBAR_WIDTH includes the left margin, your snap_units are 56, 112, 151.191. Oh shoot. I missed that factoring out the column number changed the resulting width. Fixed it as suggested. thanks. > I wonder if it might make sense to remove the UI_TOOLBAR_WIDTH define and use ED_region_toolbar_size_x() in its place. Then add a columns or column_number argument to that function. The regions would be initiated with 1 column but you could use the function in the calculation of snap positions. Now that I see it, I think this is indeed nicer without the macro. It also allows to easily and exlicitly set the width to two columns of icons with `ED_region_toolbar_size_x(2.0f)` in case we ever want that. Thanks for checking this out!
Member

@lone_noel

Hey, I realize that I am the one who suggested trying it, but I keep staring at that ED_region_toolbar_size_x function and keep thinking it will confuse my "Future Self" no matter how well we document it.

What do you think of something like the following? It seems to hit the points you want and looks straight-forward. And yes, does seem close to your first version. Although I should point out that the following contains both (int)UI_TOOLBAR_WIDTH and int(UI_TOOLBAR_WIDTH) because of our differing style for casts between C and C++

diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index 845a04c2f03..8a8087656b5 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -263,6 +263,13 @@ enum {
 #define UI_NAVIGATION_REGION_WIDTH UI_COMPACT_PANEL_WIDTH
 #define UI_NARROW_NAVIGATION_REGION_WIDTH 100
 
+/* The width of one icon column of the Toolbar. */
+#define UI_TOOLBAR_COLUMN (1.25f * ICON_DEFAULT_HEIGHT_TOOLBAR)
+/* The space between the Toolbar and the area's edge. */
+#define UI_TOOLBAR_MARGIN (0.5f * ICON_DEFAULT_HEIGHT_TOOLBAR)
+/* Total width of Toolbar showing one icon column. */
+#define UI_TOOLBAR_WIDTH UI_TOOLBAR_MARGIN + UI_TOOLBAR_COLUMN
+
 #define UI_PANEL_CATEGORY_MARGIN_WIDTH (U.widget_unit * 1.0f)
 
 /* Both these margins should be ignored if the panel doesn't show a background (check
diff --git a/source/blender/editors/screen/area_utils.c b/source/blender/editors/screen/area_utils.c
index 043b36306fe..960b36cb773 100644
--- a/source/blender/editors/screen/area_utils.c
+++ b/source/blender/editors/screen/area_utils.c
@@ -22,6 +22,7 @@
 
 #include "ED_screen.h"
 
+#include "UI_interface.h"
 #include "UI_interface_icons.h"
 
 /* -------------------------------------------------------------------- */
@@ -48,12 +49,10 @@ int ED_region_generic_tools_region_snap_size(const ARegion *region, int size, in
     const float aspect = BLI_rctf_size_y(&region->v2d.cur) /
                          (BLI_rcti_size_y(&region->v2d.mask) + 1);
     const float 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,
+        UI_TOOLBAR_COLUMN + UI_TOOLBAR_MARGIN,
+        (2.0f * UI_TOOLBAR_COLUMN) + UI_TOOLBAR_MARGIN,
+        (2.7f * UI_TOOLBAR_COLUMN) + UI_TOOLBAR_MARGIN,
     };
     int best_diff = INT_MAX;
     int best_size = size;
diff --git a/source/blender/editors/space_image/space_image.c b/source/blender/editors/space_image/space_image.c
index 1ae450c79ef..ff75f1e5458 100644
--- a/source/blender/editors/space_image/space_image.c
+++ b/source/blender/editors/space_image/space_image.c
@@ -1135,7 +1135,7 @@ void ED_spacetype_image(void)
   /* regions: tool(bar) */
   art = MEM_callocN(sizeof(ARegionType), "spacetype image region");
   art->regionid = RGN_TYPE_TOOLS;
-  art->prefsizex = 58; /* XXX */
+  art->prefsizex = (int)UI_TOOLBAR_WIDTH;
   art->prefsizey = 50; /* XXX */
   art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_FRAMES;
   art->listener = image_tools_region_listener;
diff --git a/source/blender/editors/space_node/space_node.cc b/source/blender/editors/space_node/space_node.cc
index 37c7c5a129c..be939871b3c 100644
--- a/source/blender/editors/space_node/space_node.cc
+++ b/source/blender/editors/space_node/space_node.cc
@@ -1185,7 +1185,7 @@ void ED_spacetype_node()
   /* regions: toolbar */
   art = MEM_cnew<ARegionType>("spacetype view3d tools region");
   art->regionid = RGN_TYPE_TOOLS;
-  art->prefsizex = 58; /* XXX */
+  art->prefsizex = int(UI_TOOLBAR_WIDTH);
   art->prefsizey = 50; /* XXX */
   art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_FRAMES;
   art->listener = node_region_listener;
diff --git a/source/blender/editors/space_sequencer/space_sequencer.c b/source/blender/editors/space_sequencer/space_sequencer.c
index 3c4a051ff92..7806fb4f3eb 100644
--- a/source/blender/editors/space_sequencer/space_sequencer.c
+++ b/source/blender/editors/space_sequencer/space_sequencer.c
@@ -1064,7 +1064,7 @@ void ED_spacetype_sequencer(void)
   /* Toolbar. */
   art = MEM_callocN(sizeof(ARegionType), "spacetype sequencer tools region");
   art->regionid = RGN_TYPE_TOOLS;
-  art->prefsizex = 58; /* XXX */
+  art->prefsizex = (int)UI_TOOLBAR_WIDTH;
   art->prefsizey = 50; /* XXX */
   art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_FRAMES;
   art->message_subscribe = ED_region_generic_tools_region_message_subscribe;
diff --git a/source/blender/editors/space_view3d/space_view3d.cc b/source/blender/editors/space_view3d/space_view3d.cc
index 17a37e05934..74399637e7b 100644
--- a/source/blender/editors/space_view3d/space_view3d.cc
+++ b/source/blender/editors/space_view3d/space_view3d.cc
@@ -2172,7 +2172,7 @@ void ED_spacetype_view3d()
   /* regions: tool(bar) */
   art = MEM_cnew<ARegionType>("spacetype view3d tools region");
   art->regionid = RGN_TYPE_TOOLS;
-  art->prefsizex = 58; /* XXX */
+  art->prefsizex = int(UI_TOOLBAR_WIDTH);
   art->prefsizey = 50; /* XXX */
   art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_FRAMES;
   art->listener = view3d_buttons_region_listener;

@lone_noel Hey, I realize that I am the one who suggested trying it, but I keep staring at that `ED_region_toolbar_size_x` function and keep thinking it will confuse my "Future Self" no matter how well we document it. What do you think of something like the following? It seems to hit the points you want and looks straight-forward. And yes, does seem close to your first version. Although I should point out that the following contains both `(int)UI_TOOLBAR_WIDTH` and `int(UI_TOOLBAR_WIDTH)` because of our differing style for casts between C and C++ ```Diff diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index 845a04c2f03..8a8087656b5 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -263,6 +263,13 @@ enum { #define UI_NAVIGATION_REGION_WIDTH UI_COMPACT_PANEL_WIDTH #define UI_NARROW_NAVIGATION_REGION_WIDTH 100 +/* The width of one icon column of the Toolbar. */ +#define UI_TOOLBAR_COLUMN (1.25f * ICON_DEFAULT_HEIGHT_TOOLBAR) +/* The space between the Toolbar and the area's edge. */ +#define UI_TOOLBAR_MARGIN (0.5f * ICON_DEFAULT_HEIGHT_TOOLBAR) +/* Total width of Toolbar showing one icon column. */ +#define UI_TOOLBAR_WIDTH UI_TOOLBAR_MARGIN + UI_TOOLBAR_COLUMN + #define UI_PANEL_CATEGORY_MARGIN_WIDTH (U.widget_unit * 1.0f) /* Both these margins should be ignored if the panel doesn't show a background (check diff --git a/source/blender/editors/screen/area_utils.c b/source/blender/editors/screen/area_utils.c index 043b36306fe..960b36cb773 100644 --- a/source/blender/editors/screen/area_utils.c +++ b/source/blender/editors/screen/area_utils.c @@ -22,6 +22,7 @@ #include "ED_screen.h" +#include "UI_interface.h" #include "UI_interface_icons.h" /* -------------------------------------------------------------------- */ @@ -48,12 +49,10 @@ int ED_region_generic_tools_region_snap_size(const ARegion *region, int size, in const float aspect = BLI_rctf_size_y(&region->v2d.cur) / (BLI_rcti_size_y(&region->v2d.mask) + 1); const float 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, + UI_TOOLBAR_COLUMN + UI_TOOLBAR_MARGIN, + (2.0f * UI_TOOLBAR_COLUMN) + UI_TOOLBAR_MARGIN, + (2.7f * UI_TOOLBAR_COLUMN) + UI_TOOLBAR_MARGIN, }; int best_diff = INT_MAX; int best_size = size; diff --git a/source/blender/editors/space_image/space_image.c b/source/blender/editors/space_image/space_image.c index 1ae450c79ef..ff75f1e5458 100644 --- a/source/blender/editors/space_image/space_image.c +++ b/source/blender/editors/space_image/space_image.c @@ -1135,7 +1135,7 @@ void ED_spacetype_image(void) /* regions: tool(bar) */ art = MEM_callocN(sizeof(ARegionType), "spacetype image region"); art->regionid = RGN_TYPE_TOOLS; - art->prefsizex = 58; /* XXX */ + art->prefsizex = (int)UI_TOOLBAR_WIDTH; art->prefsizey = 50; /* XXX */ art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_FRAMES; art->listener = image_tools_region_listener; diff --git a/source/blender/editors/space_node/space_node.cc b/source/blender/editors/space_node/space_node.cc index 37c7c5a129c..be939871b3c 100644 --- a/source/blender/editors/space_node/space_node.cc +++ b/source/blender/editors/space_node/space_node.cc @@ -1185,7 +1185,7 @@ void ED_spacetype_node() /* regions: toolbar */ art = MEM_cnew<ARegionType>("spacetype view3d tools region"); art->regionid = RGN_TYPE_TOOLS; - art->prefsizex = 58; /* XXX */ + art->prefsizex = int(UI_TOOLBAR_WIDTH); art->prefsizey = 50; /* XXX */ art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_FRAMES; art->listener = node_region_listener; diff --git a/source/blender/editors/space_sequencer/space_sequencer.c b/source/blender/editors/space_sequencer/space_sequencer.c index 3c4a051ff92..7806fb4f3eb 100644 --- a/source/blender/editors/space_sequencer/space_sequencer.c +++ b/source/blender/editors/space_sequencer/space_sequencer.c @@ -1064,7 +1064,7 @@ void ED_spacetype_sequencer(void) /* Toolbar. */ art = MEM_callocN(sizeof(ARegionType), "spacetype sequencer tools region"); art->regionid = RGN_TYPE_TOOLS; - art->prefsizex = 58; /* XXX */ + art->prefsizex = (int)UI_TOOLBAR_WIDTH; art->prefsizey = 50; /* XXX */ art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_FRAMES; art->message_subscribe = ED_region_generic_tools_region_message_subscribe; diff --git a/source/blender/editors/space_view3d/space_view3d.cc b/source/blender/editors/space_view3d/space_view3d.cc index 17a37e05934..74399637e7b 100644 --- a/source/blender/editors/space_view3d/space_view3d.cc +++ b/source/blender/editors/space_view3d/space_view3d.cc @@ -2172,7 +2172,7 @@ void ED_spacetype_view3d() /* regions: tool(bar) */ art = MEM_cnew<ARegionType>("spacetype view3d tools region"); art->regionid = RGN_TYPE_TOOLS; - art->prefsizex = 58; /* XXX */ + art->prefsizex = int(UI_TOOLBAR_WIDTH); art->prefsizey = 50; /* XXX */ art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_FRAMES; art->listener = view3d_buttons_region_listener; ```
Harley Acheson requested review from Harley Acheson 2023-06-07 02:50:53 +02:00
Harley Acheson changed title from Fix: Correct default width of toolbar to UI: Correct default width of toolbars 2023-06-07 02:52:46 +02:00
Leon Schittek force-pushed fix-toolbar-default-width from 087a785ec0 to 1c3dd7ebd8 2023-06-07 22:25:13 +02:00 Compare
Author
Member

I keep staring at that ED_region_toolbar_size_x function and keep thinking it will confuse my "Future Self" no matter how well we document it.

I think I understand what you mean. It wasn't the most intuitive and making things more clear is great!

What do you think of something like the following? It seems to hit the points you want and looks straight-forward.

I like it a lot! Thanks for even providing the patch.

I pretty much kept it as is, but put the aspect back in the calculation of the snap_units since otherwise it created some issues when zooming the toolbar (see attached screenshot).

> I keep staring at that `ED_region_toolbar_size_x` function and keep thinking it will confuse my "Future Self" no matter how well we document it. I think I understand what you mean. It wasn't the most intuitive and making things more clear is great! > What do you think of something like the following? It seems to hit the points you want and looks straight-forward. I like it a lot! Thanks for even providing the patch. I pretty much kept it as is, but put the `aspect` back in the calculation of the `snap_units` since otherwise it created some issues when zooming the toolbar (see attached screenshot).
Member

I pretty much kept it as is, but put the aspect back in the calculation of the snap_units since otherwise it created some issues when zooming the toolbar (see attached screenshot).

Ouch, sorry about that mistake. Glad you tested it. LOL

@pablovazquez - Is this something we can put in 3.6 since it is a fix? It's not a very noticeable thing though, more like an "off by two pixels" issue, so we can put it only in main if you think that best.

> I pretty much kept it as is, but put the `aspect` back in the calculation of the `snap_units` since otherwise it created some issues when zooming the toolbar (see attached screenshot). Ouch, sorry about that mistake. Glad you tested it. LOL @pablovazquez - Is this something we can put in 3.6 since it is a fix? It's not a very noticeable thing though, more like an "off by two pixels" issue, so we can put it only in main if you think that best.
Member

@pablovazquez - Is this something we can put in 3.6 since it is a fix?

3.6 being an LTS release I think it'd be great to get this fixed, or we will continue seeing screenshots with this issue for the next two years.

> @pablovazquez - Is this something we can put in 3.6 since it is a fix? 3.6 being an LTS release I think it'd be great to get this fixed, or we will continue seeing screenshots with this issue for the next two years.
Harley Acheson approved these changes 2023-06-08 18:01:49 +02:00
Harley Acheson merged commit 16c9eacf41 into blender-v3.6-release 2023-06-08 18:28:05 +02:00
Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#108292
No description provided.