mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-11 22:29:45 +00:00

This change adds `KeyPress` and `KeyRelease` variants to the `WindowEvent` enum, along with the new `slint::Key` enum, that allows encoding keys.
36 lines
1.1 KiB
Text
36 lines
1.1 KiB
Text
// Copyright © SixtyFPS GmbH <info@slint-ui.com>
|
|
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial
|
|
|
|
|
|
import { ScrollView } from "widget-scrollview.slint";
|
|
import { Item } from "widget-item.slint";
|
|
|
|
// `ListView` is like a `Scrollview` but it should have a for element, and the content are automatically layed out in a list.
|
|
export ListView := ScrollView {
|
|
@children
|
|
}
|
|
|
|
// Like `ListView`, but with a default delegate, and a `model` property which is a model of type `StandardListViewItem`.
|
|
export StandardListView := ListView {
|
|
property<[StandardListViewItem]> model;
|
|
property<int> current-item: -1;
|
|
|
|
for item[idx] in model : Item {
|
|
selected: idx == root.current-item;
|
|
text: item.text;
|
|
clicked => { current-item = idx; }
|
|
}
|
|
|
|
FocusScope {
|
|
key-pressed(event) => {
|
|
if (event.text == Key.UpArrow && current-item > 0) {
|
|
current-item -= 1;
|
|
return accept;
|
|
} else if (event.text == Key.DownArrow && current-item + 1 < model.length) {
|
|
current-item += 1;
|
|
return accept;
|
|
}
|
|
reject
|
|
}
|
|
}
|
|
}
|