UI: Highlight Selected Item in View3D Mode Menu #112058

Merged
Harley Acheson merged 1 commits from Harley/blender:SetModeSelected into blender-v4.0-release 2023-10-11 19:27:09 +02:00
Member

Allow the View3D "Mode" menu to highlight the currently-selected mode.


An attempt at this, but not sure I am happy with it. It feels like it should be easier to get the currently-selected item here, and easier to pass it around.

But this does just work, and does so when non-English language is set.

ModeList.gif

Allow the View3D "Mode" menu to highlight the currently-selected mode. --- An attempt at this, but not sure I am happy with it. It feels like it should be easier to get the currently-selected item here, and easier to pass it around. But this does just work, and does so when non-English language is set. ![ModeList.gif](/attachments/4f26a35b-4960-4e0f-beba-8067ede1f2ef)
Harley Acheson added this to the User Interface project 2023-09-06 22:50:14 +02:00
Hans Goudey requested changes 2023-09-07 05:06:28 +02:00
Hans Goudey left a comment
Member

Thanks for looking into this! Nice to have this sort of thing working consistently. It might be nice to check some other places where menu_item_enum_opname_menu is used besides the mode toggle (if there are any).

Thanks for looking into this! Nice to have this sort of thing working consistently. It might be nice to check some other places where `menu_item_enum_opname_menu` is used besides the mode toggle (if there are any).
@ -2764,2 +2766,3 @@
wmOperatorCallContext context,
eUI_Item_Flag flag);
eUI_Item_Flag flag,
const char *selected = nullptr);
Member

If it's not complicated, it might be better to pass the active enum item integer value rather than its string identifier, just for performance reasons, and maybe for clarity.

If it's not complicated, it might be better to pass the active enum item integer value rather than its string identifier, just for performance reasons, and maybe for clarity.
Harley marked this conversation as resolved
@ -2778,2 +2782,3 @@
const EnumPropertyItem *item_array,
int totitem);
int totitem,
int selected_item = -1);
Member

selected should probably be active here and above, since it only references one item. Plus it just seems a bit clearer.

`selected` should probably be `active` here and above, since it only references one item. Plus it just seems a bit clearer.
Harley marked this conversation as resolved
@ -1551,1 +1552,3 @@
ui_but_tip_from_enum_item(static_cast<uiBut *>(block->buttons.last), item);
uiBut *but = static_cast<uiBut *>(block->buttons.last);
if (selected_item != -1 && selected_item == (i - 1)) {
Member

I don't think i can ever be 0 in this loop, so the selected_item != -1 check seems redundant.

I don't think `i` can ever be 0 in this loop, so the `selected_item != -1` check seems redundant.
Harley marked this conversation as resolved
@ -3559,2 +3573,3 @@
uiLayoutSetOperatorContext(layout, lvl->opcontext);
uiItemsFullEnumO(layout, lvl->opname, lvl->propname, op_props, lvl->opcontext, UI_ITEM_NONE);
uiItemsFullEnumO(
layout, lvl->opname, lvl->propname, op_props, lvl->opcontext, UI_ITEM_NONE, but->str);
Member

The most confusing part here is that it's hard to be sure what but->str points to, and it seems a bit non-obvious to rely on the fact that it has the same string as the active item in the enum. At least it deserves a comment maybe with some reference to the place that but->str gets set to the active item's string.

The most confusing part here is that it's hard to be sure what `but->str` points to, and it seems a bit non-obvious to rely on the fact that it has the same string as the active item in the enum. At least it deserves a comment maybe with some reference to the place that `but->str` gets set to the active item's string.
Harley marked this conversation as resolved
Author
Member

@HooglyBoogly

Thanks for taking a look. It now seems a little less janky. Still wish I could find an easier way of getting the active item though.

@HooglyBoogly Thanks for taking a look. It now seems a _little_ less janky. Still wish I could find an easier way of getting the active item though.
Pablo Vazquez added the
Module
User Interface
label 2023-09-11 17:24:13 +02:00
Hans Goudey reviewed 2023-09-19 14:02:47 +02:00
Hans Goudey left a comment
Member

Apart from my comments inline, I think it would be good to see a couple other examples of this affecting active active item drawing. This code path must be used elsewhere too.

On thing I'm curious about: If you change the "Add Object Constraint" button in the property editor's text to "Copy Location", does the "Copy Location" item in the menu then get highlighted?

Apart from my comments inline, I think it would be good to see a couple other examples of this affecting active active item drawing. This code path must be used elsewhere too. On thing I'm curious about: If you change the "Add Object Constraint" button in the property editor's text to "Copy Location", does the "Copy Location" item in the menu then get highlighted?
@ -3552,0 +3564,4 @@
wmOperatorType *ot = WM_operatortype_find(lvl->opname, true);
int active = -1;
if (ot) {
Member

Switch this null check and return early to avoid indenting the rest of the function.

Switch this null check and return early to avoid indenting the rest of the function.
Harley marked this conversation as resolved
@ -3552,0 +3574,4 @@
WM_operator_properties_sanitize(&ptr, false);
PropertyRNA *prop = RNA_struct_find_property(&ptr, lvl->propname);
RNA_property_enum_items_gettexted(
static_cast<bContext *>(but->block->evil_C), &ptr, prop, &item_array, &totitem, &free);
Member

Maybe pass the context from the caller to avoid using evil_C?

Maybe pass the context from the caller to avoid using `evil_C`?
Harley marked this conversation as resolved
@ -3552,0 +3575,4 @@
PropertyRNA *prop = RNA_struct_find_property(&ptr, lvl->propname);
RNA_property_enum_items_gettexted(
static_cast<bContext *>(but->block->evil_C), &ptr, prop, &item_array, &totitem, &free);
active = RNA_enum_from_name(item_array, but->str);
Member

I still think it's important to add comment here that describes at least briefly how but->str ends up becoming the name of the active item.

I still think it's important to add comment here that describes at least briefly how `but->str` ends up becoming the name of the active item.
Harley marked this conversation as resolved
Author
Member

@HooglyBoogly - ...couple other examples of this affecting active active item drawing. This code path must be used elsewhere too.

I'm not seeing this code hit by anything, except for the mode switch and for "Add Object Constraint"

If you change the "Add Object Constraint" button in the property editor's text to "Copy Location", does the "Copy Location" item in the menu then get highlighted?

It definitely would do that.

> @HooglyBoogly - ...couple other examples of this affecting active active item drawing. This code path must be used elsewhere too. I'm not seeing this code hit by anything, except for the mode switch and for "Add Object Constraint" > If you change the "Add Object Constraint" button in the property editor's text to "Copy Location", does the "Copy Location" item in the menu then get highlighted? It definitely would do that.
Member

Okay, at least it's clear how this works! Thanks for checking. I think this code will be hit with any call to layout.operator_enum. Obviously my example won't actually happen, but I wonder if that limitation of not using the same button text as one of the enum names will hit us ever though. I guess I'd be willing to risk it to keep the API simpler for now.

Okay, at least it's clear how this works! Thanks for checking. I _think_ this code will be hit with any call to `layout.operator_enum`. Obviously my example won't actually happen, but I wonder if that limitation of not using the same button text as one of the enum names will hit us ever though. I guess I'd be willing to risk it to keep the API simpler for now.
Pablo Vazquez requested review from Hans Goudey 2023-10-10 17:44:56 +02:00
Hans Goudey approved these changes 2023-10-11 10:29:26 +02:00
@ -2806,2 +2806,4 @@
const char *name,
int icon);
/* Create list of enum items. active is optional item to highlight. */
Member

. active -> . Active

`. active` -> `. Active`
Harley marked this conversation as resolved
Harley Acheson force-pushed SetModeSelected from fbef676e0d to 3c5c81f3e2 2023-10-11 18:57:12 +02:00 Compare
Harley Acheson changed title from UI: Highlight Selected Item in View3D Mode Menu to UI: Highlight Selected Item in View3D Mode Menu 2023-10-11 18:57:37 +02:00
Harley changed target branch from main to blender-v4.0-release 2023-10-11 18:57:39 +02:00
Author
Member

@blender-bot build

@blender-bot build
Harley Acheson merged commit d6a6c3e1fc into blender-v4.0-release 2023-10-11 19:27:09 +02:00
Harley Acheson deleted branch SetModeSelected 2023-10-11 19:27:11 +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
2 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#112058
No description provided.