Comments (2)
We probably need a few things here. Which we still need to design API for.
1. Some kind of built-in Action
type.
maybe a struct { text: string, icon: image, tool-tip: string, enabled: bool, checkable : bool, sub-menu: [Action], shortcut: string }
maybe we even need an icon
type instead of re-using image?
For convenience, we might want to have implicit conversion from string to Menu
It is also quite similar to the StandardListViewItem
we already have.
What about sub_menus? currently we can't have a recursive struct. but maybe we can make an exception for the action type.
2. How to represent a Menu Bar
Maybe something like this
MainWindow := Window {
MenuBar {
model: [
{
text: "File",
sub-menu: [ { text: "Open", icon: @image-url(...) }, { text: "Close", ... }, ... ]
},
{
text: "Edit",
sub-menu: [ { text: "Copy", icon: @image-url(...) }, { text: "Paste", ... }, ... ]
},
];
trigerred(item) => {
if (item == "File") { // re-using the text is a very bad idea because of translation, we need something better than data
...
} else ...
}
}
...
}
An alternative would be NOT using an Action type, but using something more looking like our syntax like this:
MainWindow := Window {
property <[Action]> recent_model;
MenuBar {
Menu {
name: "File";
MenuItem { name: "Open"; icon: "..."; triggered => { ... } }
MenuItem { name: "Close"; icon: "..."; triggered => { ... } }
Menu {
name: "Open Recent";
model: recent_model; // provided by the logic
}
}
}
...
}
Another way would be to have a collection of action with another special syntax
global MyActions := ActionCollections {
file-open := Action {
text: "Open";
icon: @image-url(...);
triggered => {...}
shortcut: "Ctrl+O";
}
file-close := Action {
text: "Close";
icon: @image-url(...);
triggered => {...}
}
}
MainWindow := Window {
MenuBar {
Menu {
text: "File";
model: [MyActions.file-open, MyActions.file-close, ...];
}
Menu { ... }
}
The problem with that last approach is that ActionCollections
it is kind of a very special case which somehow re-use the same syntax, but with a completely different semantic. Although we also abuse that for the Path
sub-elements and the Row
within GridLayout.
What i mean here is that Elements are no longer really graphical items. But also that one can access the sub elements of an ActionCollection by their id from a different component.
3. ContextMenu
Similar to Menu bar, we want to be able to set context menu to element.
Do we want each element to get a context-menu
property:
Foo := Rectangle {
...
Rectangle {
context-menu: [ MyActions.file-open, {text: "Another Action" } ];
...
}
}
Or should we get another element
Foo := Rectangle {
...
Rectangle {
ContextMenu {
// similar to the MenuBar above
model: [ ... ];
}
}
}
from slint.
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
from slint.
Related Issues (20)
- New `Label` widget
- New number-getting props for `LineEdit` HOT 3
- Unicode variation selectors don't work with Skia
- `Slider` widget doesn't clamp its `value` HOT 3
- Gettext feature for Android HOT 1
- `TouchArea`: Add support for passing through events
- Hardware acceeration for the software renderer. HOT 1
- Layouts should offer the possibility to collapse margins HOT 2
- high cpu usage on idle HOT 4
- Can't use skia-vulkan HOT 10
- How can we use slint with tokio in main thread event loop
- Unreadable Slint snippets with ayu in docs
- Animations stop when resizing or moving windows HOT 4
- I encountered a failure building wasm when using 'skia' renderer. HOT 6
- flatpak zed and vscode report `slint::include_modules!();` rust-analyzer: failed to load file `UNRESOLVED_ENV_VAR` HOT 7
- LSP: diagnostics from dependencies are not refreshed when something changes
- LSP: race condition with diagnostics from the preview HOT 3
- resource embedding eats too much memory (c++) HOT 6
- Separate the Zephyr CI actions based on the Rust toolchain they require
- Slint node walk-through link is a dead link HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from slint.