UI: Highlight Selected Item in View3D Mode Menu #112058
No reviewers
Labels
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
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#112058
Loading…
Reference in New Issue
No description provided.
Delete Branch "Harley/blender:SetModeSelected"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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.
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);
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.
@ -2778,2 +2782,3 @@
const EnumPropertyItem *item_array,
int totitem);
int totitem,
int selected_item = -1);
selected
should probably beactive
here and above, since it only references one item. Plus it just seems a bit clearer.@ -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)) {
I don't think
i
can ever be 0 in this loop, so theselected_item != -1
check seems redundant.@ -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);
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 thatbut->str
gets set to the active item's string.@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.
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) {
Switch this null check and return early to avoid indenting the rest of the function.
@ -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);
Maybe pass the context from the caller to avoid using
evil_C
?@ -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);
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'm not seeing this code hit by anything, except for the mode switch and for "Add Object Constraint"
It definitely would do that.
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.@ -2806,2 +2806,4 @@
const char *name,
int icon);
/* Create list of enum items. active is optional item to highlight. */
. active
->. Active
fbef676e0d
to3c5c81f3e2
UI: Highlight Selected Item in View3D Mode Menuto UI: Highlight Selected Item in View3D Mode Menu@blender-bot build