UI: Configurable Layout Separators #117310

Merged
Harley Acheson merged 6 commits from Harley/blender:VerticalSeparator into main 2024-02-09 17:38:44 +01:00
Member

Ability to create vertical bar separators in horizontal layouts,
horizontal lines in popovers, and vertical (non-line) spacers in menus.


It was brought up in the UI Module meeting that we might want vertical bar section separators for horizontal layouts like headers. I've tried to make this as unobtrusive as possible. Current uses of layout.separator() continue to work exactly as they do now.

Currently the separator type is inferred from the button type. It makes a horizontal line if in a menu, or just horizontal space if not. To keep this behavior the same, I've added a type argument which has a default value of AUTO which retains this same behavior. So existing uses of separator are unchanged.

However, you can force a different separator if you wish, by using either SPACE or LINE. When using LINE the direction of the line is inferred from the layout direction. This works since I can't find a situation where this doesn't work.

image

Here are two useless examples of LINE, one on the TopBar and another on the 3D View header:

image

Following is a before and after comparison of the use of the horizontal rule as a separator between title and content on props dialogs:

image

The factor argument remains and works as you expect. For horizontal lines this still gives expanded or reduced vertical spacing. For vertical bars it does so for horizontal space, with the bar in the middle of it.

Ability to create vertical bar separators in horizontal layouts, horizontal lines in popovers, and vertical (non-line) spacers in menus. ---- It was brought up in the UI Module meeting that we might want vertical bar section separators for horizontal layouts like headers. I've tried to make this as unobtrusive as possible. Current uses of `layout.separator()` continue to work exactly as they do now. Currently the separator type is inferred from the button type. It makes a horizontal line if in a menu, or just horizontal space if not. To keep this behavior the same, I've added a `type` argument which has a default value of `AUTO` which retains this same behavior. So existing uses of separator are unchanged. However, you can force a different separator if you wish, by using either `SPACE` or `LINE`. When using `LINE` the direction of the line is inferred from the layout direction. This works since I can't find a situation where this doesn't work. ![image](/attachments/f1e65d40-1032-4dbc-ad6f-f3af2c552907) Here are two useless examples of `LINE`, one on the TopBar and another on the 3D View header: ![image](/attachments/b91508ff-85a7-46cc-8777-ec91d9504489) Following is a before and after comparison of the use of the horizontal rule as a separator between title and content on props dialogs: ![image](/attachments/65504ad1-9322-4132-ac50-cceb86a98f08) The `factor` argument remains and works as you expect. For horizontal lines this still gives expanded or reduced vertical spacing. For vertical bars it does so for horizontal space, with the bar in the middle of it.
Harley Acheson added 1 commit 2024-01-19 00:48:31 +01:00
106a183740 WIP: UI: Vertical Bar Separator
Ability to create vertical bar separators in horizontal layouts,
horizontal lines in popovers, and vertical (non-line) spacers in menus.
Harley Acheson added this to the User Interface project 2024-01-19 00:50:25 +01:00
Harley Acheson requested review from Pablo Vazquez 2024-01-19 00:50:32 +01:00
Harley Acheson requested review from Hans Goudey 2024-01-25 02:22:41 +01:00
Harley Acheson changed title from WIP: UI: Vertical Bar Separator to UI: Vertical Bar Separator 2024-01-28 22:54:45 +01:00
Hans Goudey requested changes 2024-01-30 04:14:30 +01:00
Hans Goudey left a comment
Member

This looks nice. I don't feel like I can answer where we would use this by default (maybe Pablo can!) but having the option seems reasonable.

One big picture question is whether we actually need LayoutSeparatorType. Maybe using the layout's direction would always be enough. That would definitely simplify some things.

This looks nice. I don't feel like I can answer where we would use this by default (maybe Pablo can!) but having the option seems reasonable. One big picture question is whether we actually need `LayoutSeparatorType`. Maybe using the layout's direction would always be enough. That would definitely simplify some things.
@ -1501,6 +1501,12 @@ enum eButProgressType {
UI_BUT_PROGRESS_TYPE_RING = 1,
};
enum eLayoutSeparatorType {
Member

How about this for some stronger type safety and prettier code?

enum class LayoutSeparatorType : int8_t{
  Auto,
  Space,
  Line,
};

Then you refer to it like LayoutSeparatorType::Space elsewhere, and it can be forward declared like enum class LayoutSeparatorType : int8_t;

I'd also try representing the "Auto" state with std::optional. But maybe that wouldn't be better

How about this for some stronger type safety and prettier code? ```cpp enum class LayoutSeparatorType : int8_t{ Auto, Space, Line, }; ``` Then you refer to it like `LayoutSeparatorType::Space` elsewhere, and it can be forward declared like `enum class LayoutSeparatorType : int8_t;` I'd also _try_ representing the "Auto" state with `std::optional`. But maybe that wouldn't be better
Harley marked this conversation as resolved
@ -3458,1 +3457,3 @@
space *= factor;
bool is_vertical = (layout->w > 0);
int width = (is_vertical) ? int(UI_UNIT_X) : int(0.3f * UI_UNIT_X * factor);
Member

Parentheses around is_vertical are unnecessary

Parentheses around `is_vertical` are unnecessary
Harley marked this conversation as resolved
@ -3459,0 +3460,4 @@
int height = (is_vertical) ? int(0.35f * UI_UNIT_X * factor) : int(UI_UNIT_Y);
eButType but_type = UI_BTYPE_SEPR;
if (type == UI_LAYOUT_SEPARATOR_LINE) {
Member

Can this be a switch statement?

Can this be a switch statement?
Harley marked this conversation as resolved
@ -3470,3 +3482,2 @@
0.0,
0.0,
0,
0.0, (is_vertical_bar) ? 1.0f : 0.0f,
Member

Clang format

Clang format
Harley marked this conversation as resolved
@ -3344,2 +3344,2 @@
/** Separator for menus. */
static void ui_draw_separator(const rcti *rect, const uiWidgetColors *wcol)
/** Separator line. */
static void ui_draw_separator(const rcti *rect, const uiWidgetColors *wcol, bool vertical)
Member

Got to say it feels weird to pass the combination of rect and `vertical here. I seems like we only end up needing two points. Maybe it would be clearer to pass those here.

Got to say it feels weird to pass the combination of `rect` and `vertical here. I seems like we only end up needing two points. Maybe it would be clearer to pass those here.
Harley marked this conversation as resolved
Harley Acheson added 2 commits 2024-02-01 04:17:14 +01:00
First-time contributor

First off, thank you so much for this! I can't tell you how much time I've tried creating hacky horizontal lines in my addons using repeating hyphens or asterisks.
Second, if done in a normal panel would it make a vertical line in a layout.row.separator(type="LINE") and a horizontal line in a layout.column.separator(type="OINE")? What about layout.grid?

First off, thank you so much for this! I can't tell you how much time I've tried creating hacky horizontal lines in my addons using repeating hyphens or asterisks. Second, if done in a normal panel would it make a vertical line in a `layout.row.separator(type="LINE")` and a horizontal line in a `layout.column.separator(type="OINE")`? What about `layout.grid`?
Author
Member

@Zeastin - What about layout.grid?

Are you able to give me a scenario to test? Maybe a sample script to run and describing the expected result? Or maybe describe a change to an existing script?

> @Zeastin - What about `layout.grid`? Are you able to give me a scenario to test? Maybe a sample script to run and describing the expected result? Or maybe describe a change to an existing script?
First-time contributor

Are you able to give me a scenario to test?

No, sorry I don't have anything in mind. I was mainly asking about the row/column thing and grid just popped in my mind and was curious.

> > Are you able to give me a scenario to test? > No, sorry I don't have anything in mind. I was mainly asking about the row/column thing and grid just popped in my mind and was curious.
Harley Acheson changed title from UI: Vertical Bar Separator to UI: Configurable Layout Separators 2024-02-08 17:51:25 +01:00
Author
Member

@HooglyBoogly - where we would use this by default (maybe Pablo can!) but having the option seems reasonable.

I don't think we'd need it often. But the following is an example where I would do so, with props dialogs to separate the title from the rest:

image

Maybe using the layout's direction would always be enough. That would definitely simplify some things.

I'm not sure that is possible, but maybe you are thinking of something that I have not considered correctly?

With a layout that has a vertical direction, like in dialogs and popups, we currently only have the option of a separator comprising only vertical space. But this PR would allow us to have both spacers and horizontal rules.

I think the only way to get rid of the need for LayoutSeparatorType would be replace all our current usages of layout.separator with a label when it is used to just used to make a vertical gap. Then we could change separator to always be a line for vertical layouts. But we use separator for vertical spaces all over the place and probably in many addons.

Or were you thinking of some other way or not needing LayoutSeparatorType ?

> @HooglyBoogly - where we would use this by default (maybe Pablo can!) but having the option seems reasonable. I don't think we'd need it often. But the following is an example where I would do so, with props dialogs to separate the title from the rest: ![image](/attachments/e12f6ab0-594a-4769-ae03-48b5641b1806) > Maybe using the layout's direction would always be enough. That would definitely simplify some things. I'm not sure that is possible, but maybe you are thinking of something that I have not considered correctly? With a layout that has a vertical direction, like in dialogs and popups, we currently only have the option of a separator comprising only vertical space. But this PR would allow us to have **both** spacers and horizontal rules. I _think_ the only way to get rid of the need for LayoutSeparatorType would be replace all our current usages of layout.separator with a label when it is used to just used to make a vertical gap. Then we could change separator to always be a line for vertical layouts. But we use separator for vertical spaces all over the place and probably in many addons. Or were you thinking of some other way or not needing LayoutSeparatorType ?
Author
Member

@pablovazquez

Can you look at the following image and consider the brightness of the horizontal rule on the right? It looks a bit too dim to me but I've been staring at it too long now and need a fresh opinion:

image

@pablovazquez Can you look at the following image and consider the brightness of the horizontal rule on the right? It looks a bit too dim to me but I've been staring at it too long now and need a fresh opinion: ![image](/attachments/e42d5a8b-3578-466a-a2fc-7bdef78307c5)
Hans Goudey approved these changes 2024-02-08 18:30:51 +01:00
Hans Goudey left a comment
Member

Ah, my bad, I misunderstood what LayoutSeparatorType was doing here. Somehow I thought it was controlling the vertical/horizontal choice. Maybe I was asleep. Anyway, this change looks good to me.

Ah, my bad, I misunderstood what `LayoutSeparatorType` was doing here. Somehow I thought it was controlling the vertical/horizontal choice. Maybe I was asleep. Anyway, this change looks good to me.
@ -3449,3 +3449,3 @@
}
void uiItemS_ex(uiLayout *layout, float factor)
void uiItemS_ex(uiLayout *layout, float factor, LayoutSeparatorType type)
Member

const LayoutSeparatorType

`const LayoutSeparatorType`
Harley Acheson added 2 commits 2024-02-08 19:06:47 +01:00
buildbot/vexp-code-patch-windows-amd64 Build done. Details
buildbot/vexp-code-patch-lint Build done. Details
buildbot/vexp-code-patch-linux-x86_64 Build done. Details
buildbot/vexp-code-patch-darwin-x86_64 Build done. Details
buildbot/vexp-code-patch-darwin-arm64 Build done. Details
buildbot/vexp-code-patch-coordinator Build done. Details
18028d6441
Review: Adding const to function parameter.
Author
Member

@blender-bot build

@blender-bot build
Harley Acheson added 1 commit 2024-02-09 17:36:39 +01:00
Author
Member

Need this into main early, to help with #117304

Need this into main early, to help with #117304
Harley Acheson merged commit 4c50e6992f into main 2024-02-09 17:38:44 +01:00
Harley Acheson deleted branch VerticalSeparator 2024-02-09 17:38:46 +01: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#117310
No description provided.