mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-04 18:58:36 +00:00
reset StandardListView's current-item if it is out of bounds
This commit is contained in:
parent
b510c2f7a2
commit
9d18882f9d
2 changed files with 10 additions and 8 deletions
|
@ -377,7 +377,8 @@ export ListView := ScrollView {
|
|||
|
||||
export StandardListView := ListView {
|
||||
property<[StandardListViewItem]> model;
|
||||
property<int> current-item: -1;
|
||||
property<int> current-item: min(actual-current-item, model.length - 1);
|
||||
property<int> actual-current-item: -1;
|
||||
for item[idx] in model : Rectangle {
|
||||
l := HorizontalLayout {
|
||||
padding: 8px;
|
||||
|
@ -392,16 +393,16 @@ export StandardListView := ListView {
|
|||
touch := TouchArea {
|
||||
width: parent.width;
|
||||
height: parent.height;
|
||||
clicked => { current-item = idx; }
|
||||
clicked => { actual-current-item = idx; }
|
||||
}
|
||||
}
|
||||
FocusScope {
|
||||
key-pressed(event) => {
|
||||
if (event.text == Keys.UpArrow && current-item > 0) {
|
||||
current-item -= 1;
|
||||
actual-current-item -= 1;
|
||||
return accept;
|
||||
} else if (event.text == Keys.DownArrow && current-item + 1 < model.length) {
|
||||
current-item += 1;
|
||||
actual-current-item += 1;
|
||||
return accept;
|
||||
}
|
||||
reject
|
||||
|
|
|
@ -69,23 +69,24 @@ export ListView := ScrollView {
|
|||
|
||||
export StandardListView := ListView {
|
||||
property<[StandardListViewItem]> model;
|
||||
property<int> current-item: -1;
|
||||
property<int> current-item: min(actual-current-item, model.length - 1);
|
||||
property<int> actual-current-item: -1;
|
||||
for item[i] in model : NativeStandardListViewItem {
|
||||
item: item;
|
||||
index: i;
|
||||
is-selected: current-item == i;
|
||||
TouchArea {
|
||||
clicked => { current-item = i; }
|
||||
clicked => { actual-current-item = i; }
|
||||
has-hover <=> parent.has-hover;
|
||||
}
|
||||
}
|
||||
FocusScope {
|
||||
key-pressed(event) => {
|
||||
if (event.text == Keys.UpArrow && current-item > 0) {
|
||||
current-item -= 1;
|
||||
actual-current-item -= 1;
|
||||
return accept;
|
||||
} else if (event.text == Keys.DownArrow && current-item + 1 < model.length) {
|
||||
current-item += 1;
|
||||
actual-current-item += 1;
|
||||
return accept;
|
||||
}
|
||||
reject
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue