-
Notifications
You must be signed in to change notification settings - Fork 643
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
Add support for popup menus and menubar #38
Comments
We probably need a few things here. Which we still need to design API for. 1. Some kind of built-in
|
Implementation wise, I see that tauri has created a separate crate for menubar / popup menus that works on macOS, Windows, and Linux - the latter using gtk: https://github.com/tauri-apps/muda |
Sumary of our discussion in the office: The There exist a struct struct MenuEntry {
title: text;
icon: image; // or icon?
id: string; // opaque
keyboard-shortcut: key-sequence;
enabled: bool;
} The ContextMenu can be used like so:
When placed somewhere in the tree, it will automatically be shown on right click or with the menu key.
Not sure if ContexMenuArea is needed or not. For menu bar:Introduce a export component AppWindow inherits Window {
// there can only be one, must be child of `Window` import from std-widgets.slint
MenuBar {
// has no geometry properties, etc.
MenuItem {
title: @tr("Menu" => "File")
MenuItem {
title: "delete currently selected";
enabled: SomeGlobal.is-design-mode;
keyboard-shortcut: @keys(ctrl+d) // lowers to string with our fancy encoded control codes
}
MenuEntries {}
MenuSeparator{}
MenuItem {
blah := MenuItem {
// all the same property as MenuEntry + triggered
}
}
//Action { action: SomeGloba.file-open; }
}
MenuItem { ... }
}
// Fill the rest: y is after the menu bar.
Rectangle { y:0; height: 100%; }
} TODO
|
Note that Windows provides system settings like which side a context menu should open towards. |
I'm very interested in menu bars & context menus. So I'd like to bring in my thoughts on this.
It would be great to allow having multiple keyboard shortcuts for the same action.
For simple (static) UIs it's great to declare all the menu items (for both menu bar & context menus) right in the .slint file as you suggest. But for more dynamic UIs (e.g. configurable keyboard shortcuts, menu items enabled/disabled or even visible/invisible depending on app state etc) it's crucial to allow defining (or modifying) menu items from native code. Maybe through a model would be easiest, though other ways might be fine as well. From reading the code examples above I'm not 100% sure if this case is considered.
Would there be a technical reason for this restriction? If the menu bar would also work in nested UI elements (e.g. tabs) I'd say the user should not be prevented from doing this. Also in PopupWindow it might be nice to have a menu bar. Of course the system integration would only work with the main window's menu bar.
Would this prevent the user from placing any other UI elements above this pseudo y:0? Usually menu bars contain a lot of unused space, where it would be nice to allow using it for other things. For example a search box: I'm aware this is not a standard UI paradigm. But should the UI toolkit prevent the user from doing nonstandard things? It is the great flexibility of Slint I really like compared to the very restrictive and unflexible QtWidgets so IMHO it would be sad to implement similar restrictions in Slint too ;) Actually now I wonder if it would even be feasible to use arbitrary UI elements in menus? For example switches (though checked menu items should probably be a built-in feature):
I agree, but it would be nice to allow disabling it, e.g. for cases as described above where the menu bar is used for other purpose too or contains arbitrary widgets. So far just my thoughts, up to you to decide what makes sense and what doesn't 🙂 |
Under Windows, when making use of the OS-provided menu bar, the window's client area naturally doesn't include the menu bar. Use cases like you described would be a good reason in my opinion to provide custom menu bars and menus. Firefox, e.g., draws its menu bar and menus itself. According to GPT-4o, trying to custom-draw into the non-client area of the menu bar quickly gets complex and inflexible. I think there could also be theme inconsistencies with OS-provided menu bars and menus (like light-themed menu bars and menus in a dark-themed app).
Some custom menu behavior could IMO indeed be desirable. I think everybody knows how annoying it can be having to repeatedly show a series of menus and submenus, paying attention to find the end spot again, just to quickly test a number of features reachable via menu (e.g., enabling and quickly disabling it again, or toggling multiple check marks). A custom menu implementation could provide a means to keep the menu shown after clicking on an item (like when holding a keyboard modifier when clicking). |
are there any workaround examples available for this using muda in conjunction with slint? |
This is a bit out of topic for this issue, but we do use muda to change the menu of the live preview on macOs. (although this uses private API) https://github.com/slint-ui/slint/blob/master/tools/lsp/preview/native.rs#L273 |
#6832 bring experimental support for MenuBar (under a gated by the SLINT_ENABLE_EXPERIMENTAL env variable) TODO:
|
Could you provide the instructions how to use it with 1.9? I'm aware that it is an experimental feature but right now we really need a cross-platform menu bar since we can't use |
@ultimaweapon: define the |
This ticket tracks the ability to declare popup menus in
.60
markup as well as the ability to integrate them into a menu bar.This needs further refinement/triaging regarding a more actionable acceptance criteria.
The text was updated successfully, but these errors were encountered: