-
Notifications
You must be signed in to change notification settings - Fork 738
NOT FUNCTIONAL: Initial support for menus with checkmarks #9056
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This is an initial attempt to support menus with checkmarks. This initial support has the following caveats: - It doesn't work :-). It isn't clear to me how the state on `MenuItem` objects get sync'd with `MenuEntry` objects. I expected this to be happening within `MenuFromItemTree::update_shadow_tree()`, but that seems to not happen in practice. By contrast, `enabled` gets sync'd just fine. - The graphics for non-muda checkmarks is almost certainly insufficient. I anticipate strong opinions about what this should look like - `muda` seems to have distinct structs for menu items that support icons versus checkmarks. It isn't clear to me why this would be. This means that icons and checkmarks cannot be used at the same time when `muda` is used. - `muda` has some odd default behaviors for `CheckMenuItem`, like automatically toggling the checkmark. This behavior will likely need to be suppressed. Separately, I would also like to see accelerator support; I do see `key_sequence` commented out in `builtin_structs.rs`. I'm sure that some of the guidance rectifying the above issues will translate for accelerator support.
Thanks for the contributions. Note that we would need both a
Depending if the menu has slint/internal/compiler/passes/lower_menus.rs Line 745 in 351324a
Then priority to check mark.
Some work for that has started (eg in #8906) |
- Handling `checkable` and `checked` when copying into `MenuEntry` - Changing `muda` code to honor `checkable` and give it priority over `icon`
Is it ready to be reviewed? |
It's ready with the caveats acknowledged in the original PR. I think you provided feedback that allowed me to ddress the first and third. |
The only definite problem I'm aware about is the last problem; Relevant code on Windows: https://github.com/tauri-apps/muda/blob/ff2cecc76b69b54ed253fd526320f9c50ddb6236/src/platform_impl/windows/mod.rs#L1193 It isn't clear to me why |
I made a change in #9159 that is causing conflict but should simplify the implementation a bit |
Merged! |
Thanks! Could you please add documentation in contextmenuarea.mdx. Also maybe have a checkable entry in the gallery as an example.
I'm not exactly sure what behavior we want here.
some-item := MenuItem {
title: "Check me";
checkable: true;
}
// ... elsewhere, use the property in a binding or something
background: some-item.checked ? blue : red;
I'm tempted do go with the option 1. I think we should change the value of checked automaticallty (This can be done in MenuFromItemTree::activate, I'd say.) |
1. Adding documentation to `contextmenuarea.mdx` 2. Adding logic to toggle checkmarks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
Could you also add a tests?
Prehaps you can extend this test
https://github.com/slint-ui/slint/blob/master/tests/cases/widgets/menubar.slint
and this one
https://github.com/slint-ui/slint/blob/master/tests/cases/widgets/contextmenu.slint
to include a checkable menu and checked that the property is correctly updated.
Co-authored-by: Olivier Goffart <[email protected]>
I've created two new test cases, but it isn't clear to me how these test cases are executed (the code behind seems to just be comments in the Slint code; presumably there is a test harness?) Also in the logic that actually does the toggling, I query for the status of the |
There are test driver that run these. See https://github.com/slint-ui/slint/blob/master/docs/testing.md#driver-tests
Indeed that's not good. You need to get a Pin. You can do that with |
Are there any more outstanding issues related to this PR? |
Sorry for the delay. This is looking good. Also please add a entry to the gallery's menu |
- Fixing C++ test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
API looks good to me, too.
docs/astro/src/content/docs/reference/window/contextmenuarea.mdx
Outdated
Show resolved
Hide resolved
Co-authored-by: Simon Hausmann <[email protected]>
{ | ||
if let Some(menu_item) = menu_item.downcast::<MenuItem>() { | ||
if menu_item.as_pin_ref().checkable() { | ||
menu_item.checked.set(!menu_item.as_pin_ref().checked()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I suspect this is what I’m looking for?
This is an initial attempt to support menus with checkmarks. This initial support has the following caveats:
MenuItem
objects get sync'd withMenuEntry
objects. I expected this to be happening withinMenuFromItemTree::update_shadow_tree()
, but that seems to not happen in practice. By contrast,enabled
gets sync'd just fine.muda
seems to have distinct structs for menu items that support icons versus checkmarks. It isn't clear to me why this would be. This means that icons and checkmarks cannot be used at the same time whenmuda
is used.muda
has some odd default behaviors forCheckMenuItem
, like automatically toggling the checkmark. This behavior will likely need to be suppressed.Separately, I would also like to see accelerator support; I do see
key_sequence
commented out inbuiltin_structs.rs
. I'm sure that some of the guidance rectifying the above issues will translate for accelerator support.