Skip to content

Conversation

@kaascevich
Copy link
Contributor

This PR adds support for using Toggles in menus. It's currently implemented in AppKitBackend, UIKitBackend, and WinUIBackend (the latter is untested at the moment because I don't have any Windows machines on hand).

It's possible to implement these in GtkBackend (and probably Gtk3Backend) as well, but I'm not nearly comfortable enough with those frameworks to do that myself right now.

Copy link
Owner

@stackotter stackotter left a comment

Choose a reason for hiding this comment

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

I'll give this a try locally. Have you tested on macOS and iPadOS?

@kaascevich
Copy link
Contributor Author

Have you tested on macOS and iPadOS?

macOS yes, iPadOS not specifically (I did test it on iOS, so it should work fine).

@stackotter
Copy link
Owner

It works on macOS in both the app menu and menu buttons.

I haven't tested iPadOS command menus, but it crashes on iOS when used in a menu button;

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Action is immutable because it is a child of a menu'
*** First throw call stack:
(0x187f640c0 0x1853fdabc 0x187261670 0x18b832bf0 0x104fb23ac 0x18ad696b4 0x18b832604 0x18bd7700c 0x18ba53ccc 0x18b87442c 0x18afff244 0x18afff4e8 0x18afff174 0x18b873f18 0x18a755060 0x18a8ffb0c 0x18bd76594 0x18ba53d4c 0x18bb11450 0x18afd9f80 0x18afd805c 0x18afd8528 0x18a7b015c 0x18a7affcc 0x18a7afd9c 0x18a7af690 0x18a74de94 0x18a79b27c 0x18a79b104 0x18a79ac18 0x18a7a7508 0x18a7589a0 0x18a757be4 0x18a7514e4 0x18a751404 0x18a750ab4 0x18a74c1e4 0x187e5992c 0x187e59744 0x187e595a0 0x187e59f20 0x187e5badc 0x1d4c81454 0x18a87d274 0x18a848a28 0x104fcbb88 0x104fccaf8 0x104de4fb4 0x104b4eb74 0x104b49764 0x104b49a5c 0x1ae8edf08)
libc++abi: terminating due to uncaught exception of type NSException
App terminated due to signal 6.

I tested it in a menu button with this code in WindowingExample;

Menu("Open") {
    Toggle("Enabled?", active: $toggle)
}

This patch fixes things on my end;

fix.patch

@kaascevich
Copy link
Contributor Author

I haven't tested iPadOS command menus, but it crashes on iOS when used in a menu button

That's... new. I'll apply that patch, thanks!

Copy link
Owner

@stackotter stackotter left a comment

Choose a reason for hiding this comment

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

Thanks for fixing those issues. Looks good now. I'll just test out the Windows implementation before merging

@stackotter
Copy link
Owner

I've just merged #312, please apply that approach to the logging you added to GtkBackend and Gtk3Backend so that it's consistent once merged

@stackotter stackotter merged commit 5d86aee into stackotter:main Jan 6, 2026
11 checks passed
@kaascevich kaascevich deleted the menu-toggles branch January 6, 2026 03:09
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