Skip to content

fix(context_menu): fix issue with overlay buttons always being disabled (issue #378)#415

Merged
genusistimelord merged 1 commit into
iced-rs:mainfrom
rokcej:fix/context-menu-button-status
Mar 19, 2026
Merged

fix(context_menu): fix issue with overlay buttons always being disabled (issue #378)#415
genusistimelord merged 1 commit into
iced-rs:mainfrom
rokcej:fix/context-menu-button-status

Conversation

@rokcej

@rokcej rokcej commented Mar 19, 2026

Copy link
Copy Markdown
Contributor

Issue

Buttons inside a context menu overlay always show up as disabled. This happens because context menu keeps recreating overlay widgets from a closure. Button stores visual state on the widget itself, so rebuilding the overlay each time prevents button status from correctly updating ==> buttons always get rendered as disabled.

This also fixes issue #378.

Reproduction steps

  1. Run examples/context_menu.rs.
  2. Open context menu.
  3. The buttons in the overlay are always rendered as disabled. This behavior is not correct.

Solution

The fix is to rebuild overlay widgets only when context menu becomes visible and cache them (overlay_instance). This allows us to reuse the cached overlay widgets and preserve their internal state while the context menu is open.

If you have any questions or see potential concerns, let's discuss them.

The old context_menu snapshot (tests/snapshots/context_menu_with_multiple_buttons_in_overlay-wgpu.png) has been updated because it incorrectly showed disabled buttons. All context_menu tests now pass.

While context menu overlay was visible, it kept recreating overlay widgets from a closure. Button stores visual state on the widget itself, so rebuilding the overlay caused buttons to incorrectly render as disabled.

This was fixed by rebuilding overlay widgets only when context menu becomes visible and caching them. This allows us to reuse the cached overlay widgets while the context menu is open.

The old context_menu snapshot has been updated because it incorrectly showed disabled buttons. All context_menu tests now pass.
Comment thread src/widget/context_menu.rs
Comment thread src/widget/context_menu.rs

@genusistimelord genusistimelord left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything looks good code wise and makes sense. Just need to get it to pass the marks then it can be merged.

@genusistimelord genusistimelord merged commit 887cd82 into iced-rs:main Mar 19, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants