You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a ListView of custom components that differ in height. Something like this:
componentCustomComponent {
inproperty <ComponentData>: component-data;
// display the data somehow// height of this component is arbitrary and can differ depending on `component-data`
}
componentCustomList {
inproperty <[ComponentData]>: data;
list := ListView {
for data[idx] inroot.data: CustomComponent {
component-data: data;
}
}
publicfunction scroll-to-element(idx: int) {
// set position based on element index// list.viewport-y = ...
}
}
Now I want to scroll the list so that particular element is in view. I know that I can set the list.viewport-y to scroll it to a particular position, but how can I access the position of elements created using for ? Or is there any other way to achieve it?
EDIT:
I managed some hacky solution using ScrollView, changed callback and global singleton. It works as intended with live preview and static data, but panics with Recursion detected while reloading preview. Same panic occurs if models are loaded from native code, so it's not really useful yet.
Slint code
globalPositions {
in-out property <[length]> y-pos: [0, 0, /* ... */];
}
componentCustomComponent {
inproperty<int>: index;
inproperty <ComponentData>: component-data;
changed y => {
Positions.y-pos[root.index] = root.y;
}
// display the data somehow// height of this component is arbitrary and can differ depending on `component-data`
}
componentCustomList {
inproperty <[ComponentData]>: data;
list := ScrollView {
VerticalLayout {
for data[idx] inroot.data: CustomComponent {
index: idx;
component-data: data;
}
}
}
publicfunction scroll-to-element(idx: int) {
// set position based on element index
list.viewport-y = min(0, - Positions.y-pos[idx]);
}
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have a
ListView
of custom components that differ in height. Something like this:Now I want to scroll the
list
so that particular element is in view. I know that I can set thelist.viewport-y
to scroll it to a particular position, but how can I access the position of elements created usingfor
? Or is there any other way to achieve it?EDIT:
I managed some hacky solution using
ScrollView
,changed
callback and global singleton. It works as intended with live preview and static data, but panics withRecursion detected
while reloading preview. Same panic occurs if models are loaded from native code, so it's not really useful yet.Slint code
Beta Was this translation helpful? Give feedback.
All reactions