mirror of
https://github.com/slint-ui/slint.git
synced 2025-09-28 21:04:47 +00:00

This is not supported right now, the other elements will not be part of the layout, and two `for` will be in the same listview, creating bad situation with the scrollbar. This is a warning since it would be a breaking change to make it an error. For example, we used a FocusScope in the StandardListView implementation so I had to go trough one level of indirection CC: #860
38 lines
1.2 KiB
Text
38 lines
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
|
|
}
|
|
|
|
StandardListViewBase := ListView {
|
|
in property<[StandardListViewItem]> model;
|
|
in-out property<int> current-item: -1;
|
|
|
|
for item[idx] in model : Item {
|
|
selected: idx == root.current-item;
|
|
text: item.text;
|
|
clicked => { current-item = idx; }
|
|
}
|
|
}
|
|
|
|
// Like `ListView`, but with a default delegate, and a `model` property which is a model of type `StandardListViewItem`.
|
|
export StandardListView := StandardListViewBase {
|
|
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
|
|
}
|
|
}
|
|
}
|