mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-04 10:50:00 +00:00
Menu: Add enabled property (#8145)
By default it's enabled, of course. This property is not only added to MenuItem, but Menu as well - since they can be nested. It's also possible to select a disabled item, but it's hard to modify that since it's logic is written in Slint. You should be prevented from activating it with a tap or key press at least. See #7791
This commit is contained in:
parent
44a1bec608
commit
d1f2fef430
8 changed files with 64 additions and 9 deletions
|
@ -115,6 +115,7 @@ export component MenuItemBase {
|
|||
|
||||
touch-area := TouchArea {
|
||||
visible: !entry.is-separator;
|
||||
enabled: entry.enabled;
|
||||
|
||||
layout := HorizontalLayout {
|
||||
padding-top: root.padding-top;
|
||||
|
@ -140,11 +141,12 @@ export component MenuItemBase {
|
|||
pointer-event(event) => {
|
||||
if event.kind == PointerEventKind.move && !root.is-current {
|
||||
root.set-current()
|
||||
} else if event.kind == PointerEventKind.down && entry.has-sub-menu {
|
||||
} else if event.kind == PointerEventKind.down && entry.has-sub-menu && entry.enabled {
|
||||
activate(entry, self.absolute-position.y);
|
||||
} else if event.kind == PointerEventKind.up
|
||||
&& self.mouse-y > 0 && self.mouse-y < self.height
|
||||
&& self.mouse-x > 0 && self.mouse-x < self.width {
|
||||
&& self.mouse-x > 0 && self.mouse-x < self.width
|
||||
&& entry.enabled {
|
||||
// can't put this in `clicked` because then the menu would close causing a panic in the pointer-event
|
||||
activate(entry, self.absolute-position.y);
|
||||
}
|
||||
|
@ -168,5 +170,8 @@ export component MenuItemBase {
|
|||
background-layer.background: root.current-background;
|
||||
label.color: root.current-foreground;
|
||||
}
|
||||
disabled when !entry.enabled : {
|
||||
label.opacity: 0.5;
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -85,12 +85,12 @@ export component PopupMenuImpl inherits Window {
|
|||
}
|
||||
return accept;
|
||||
} else if event.text == Key.Return {
|
||||
if current-highlight >= 0 && current-highlight < entries.length {
|
||||
if current-highlight >= 0 && current-highlight < entries.length && entries[current-highlight].enabled {
|
||||
activate(entries[current-highlight], y-pos(current-highlight), current-highlight);
|
||||
}
|
||||
return accept;
|
||||
} else if event.text == Key.RightArrow {
|
||||
if current-highlight >= 0 && current-highlight < entries.length && entries[current-highlight].has-sub-menu {
|
||||
if current-highlight >= 0 && current-highlight < entries.length && entries[current-highlight].has-sub-menu && entries[current-highlight].enabled {
|
||||
activate(entries[current-highlight], y-pos(current-highlight), current-highlight);
|
||||
}
|
||||
return accept;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue