mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-04 10:50:00 +00:00
Menus: make it possible to have items with different height
Can be usefull for separator (Required for #8339)
This commit is contained in:
parent
beef5d9cde
commit
fece71ebf0
1 changed files with 11 additions and 7 deletions
|
@ -9,6 +9,8 @@ export component PopupMenuImpl inherits Window {
|
|||
in property <[MenuEntry]> entries: [];
|
||||
|
||||
property <int> current-highlight: -1;
|
||||
// `y` position of the currently highlighted menu entry
|
||||
property <length> current-highlight-y-pos;
|
||||
property <int> current-open: -1;
|
||||
property <length> px: 1rem / 14;
|
||||
|
||||
|
@ -25,6 +27,12 @@ export component PopupMenuImpl inherits Window {
|
|||
entry: entry;
|
||||
is-current: current-highlight == index;
|
||||
|
||||
changed is-current => {
|
||||
if self.is-current {
|
||||
current-highlight-y-pos = self.absolute-position.y - root.absolute-position.y;
|
||||
}
|
||||
}
|
||||
|
||||
set-current => {
|
||||
focus-scope.focus();
|
||||
root.current-highlight = index;
|
||||
|
@ -50,7 +58,7 @@ export component PopupMenuImpl inherits Window {
|
|||
|
||||
if current-highlight >= 0 {
|
||||
if entries[current-highlight].has-sub-menu {
|
||||
activate(entries[current-highlight], y-pos(current-highlight), current-highlight);
|
||||
activate(entries[current-highlight], current-highlight-y-pos, current-highlight);
|
||||
} else {
|
||||
current-open = -1;
|
||||
sub-menu.close();
|
||||
|
@ -59,10 +67,6 @@ export component PopupMenuImpl inherits Window {
|
|||
}
|
||||
}
|
||||
|
||||
function y-pos(idx: int) -> length {
|
||||
frame.padding + idx * (frame.height - 2 * frame.padding) / entries.length
|
||||
}
|
||||
|
||||
key-pressed(event) => {
|
||||
open-sub-menu-after-timeout.running = false;
|
||||
|
||||
|
@ -86,12 +90,12 @@ export component PopupMenuImpl inherits Window {
|
|||
return accept;
|
||||
} else if event.text == Key.Return {
|
||||
if current-highlight >= 0 && current-highlight < entries.length && entries[current-highlight].enabled {
|
||||
activate(entries[current-highlight], y-pos(current-highlight), current-highlight);
|
||||
activate(entries[current-highlight], current-highlight-y-pos, current-highlight);
|
||||
}
|
||||
return accept;
|
||||
} else if event.text == Key.RightArrow {
|
||||
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);
|
||||
activate(entries[current-highlight], current-highlight-y-pos, current-highlight);
|
||||
}
|
||||
return accept;
|
||||
} else if event.text == Key.LeftArrow {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue