slint/internal/compiler/widgets/material-base/widget-listview.slint
Florian Blasius 072d8fabcb
Add material, material-light and material-dark widgets (#1784)
Add material, material-light and material-dark widgets and make it available by the `env` `SLINT_STYLE`.
2022-10-31 14:54:50 +01:00

36 lines
No EOL
1.2 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 == Keys.UpArrow && current-item > 0) {
current-item -= 1;
return accept;
} else if (event.text == Keys.DownArrow && current-item + 1 < model.length) {
current-item += 1;
return accept;
}
reject
}
}
}