Comments (6)
There is indeed a design flaw: #602
I'm not sure yet what's the best way to solve this.
from slint.
from slint.
import { Button, StandardListView, VerticalBox } from "std-widgets.slint";
export component MainWindow inherits Window {
in-out property <[StandardListViewItem]> model: [
{text: "000"}, {text: "001"}, {text: "002"}, {text: "003"}, {text: "004"}, {text: "005"}, {text: "006"}, {text: "007"}, {text: "008"}, {text: "009"},
{text: "010"}, {text: "011"}, {text: "012"}, {text: "013"}, {text: "014"}, {text: "015"}, {text: "016"}, {text: "017"}, {text: "018"}, {text: "019"},
{text: "020"}, {text: "021"}, {text: "022"}, {text: "023"}, {text: "024"}, {text: "025"}, {text: "026"}, {text: "027"}, {text: "028"}, {text: "029"},
{text: "030"}, {text: "031"}, {text: "032"}, {text: "033"}, {text: "034"}, {text: "035"}, {text: "036"}, {text: "037"}, {text: "038"}, {text: "039"},
{text: "040"}, {text: "041"}, {text: "042"}, {text: "043"}, {text: "044"}, {text: "045"}, {text: "046"}, {text: "047"}, {text: "048"}, {text: "049"},
{text: "050"}, {text: "051"}, {text: "052"}, {text: "053"}, {text: "054"}, {text: "055"}, {text: "056"}, {text: "057"}, {text: "058"}, {text: "059"},
{text: "060"}, {text: "061"}, {text: "062"}, {text: "063"}, {text: "064"}, {text: "065"}, {text: "066"}, {text: "067"}, {text: "068"}, {text: "069"},
{text: "070"}, {text: "071"}, {text: "072"}, {text: "073"}, {text: "074"}, {text: "075"}, {text: "076"}, {text: "077"}, {text: "078"}, {text: "079"},
{text: "080"}, {text: "081"}, {text: "082"}, {text: "083"}, {text: "084"}, {text: "085"}, {text: "086"}, {text: "087"}, {text: "088"}, {text: "089"},
{text: "090"}, {text: "091"}, {text: "092"}, {text: "093"}, {text: "094"}, {text: "095"}, {text: "096"}, {text: "097"}, {text: "098"}, {text: "099"},
];
private property <length> item-height: my-list-view.viewport-height / my-list-view.model.length;
private property <int> into-view-item: 0;
private property <length> into-view-item-y: root.item-y(root.into-view-item);
out property <length> my-list-view-viewport-y: my-list-view.viewport-y;
out property <length> my-list-view-visible-height: my-list-view.visible-height;
pure function item-y(index: int) -> length {
return my-list-view.viewport-y + index * root.item-height;
}
public function bring-into-view(row: int) {
if (row < 0 || row >= my-list-view.model.length) {
return;
}
into-view-item = row;
if (into-view-item-y < 0) {
my-list-view.viewport-y += 0 - into-view-item-y;
}
if (into-view-item-y + item-height > my-list-view.visible-height) {
my-list-view.viewport-y -= into-view-item-y + root.item-height - my-list-view.visible-height;
}
}
min-width: 400px;
min-height: 400px;
max-width: 10000px;
max-height: 10000px;
VerticalBox {
Button {
text: "Bring Into View";
clicked => { bring-into-view(42); }
}
my-list-view := StandardListView {
model: root.model;
}
}
// the "clicked" work, but the init doesn't
init => { bring-into-view(42); }
}
I made a reproducer in pure Slint using the init
callback.
The problem is that the geometry of the ListView is not yet calculated as the items are not instantiated until they need to be rendered.
And there is no way to force the instantiation otherwise
from slint.
I suppose then my question becomes, what is the recommended (or at least, "least worst") way to do this?
from slint.
I'm starting to think that this is a design flaw, as it means that there is not a reliable way to simultaneously update both:
- The backing data for a
ListView
- Ancillary UI state (e.g. - positioning within the viewport, selected item for
StandardListView
etc) that might require the above data be processed
from slint.
I figured out a hacky workaround to get what I want:
- On my struct that implements
Model
, I add a member of typeCell<Option<Box<dyn Future<Output = ()> + 'static>>>
- When I refresh my model, I put logic that updates the selection (or brings the selected item into view) in a future, and place it into the
Cell
described above - I put the following code in my implementation of
Model::row_count()
:
if let Some(callback) = cell.take() {
let callback = Pin::from(callback);
spawn_local(callback).unwrap();
}
This is a gross hack but it seems to work. I'm looking forward to when this hack becomes obsolete ;-)
from slint.
Related Issues (20)
- resource embedding eats too much memory (c++) HOT 6
- Separate the Zephyr CI actions based on the Rust toolchain they require
- Slint node walk-through link is a dead link HOT 1
- Float-to-string conversion while controlling decimal place count HOT 2
- Every Alt+Tab to window moves focus HOT 3
- quickstart/memory_tile: wrong @image-url for the Rust case HOT 2
- quickstart/polishing_the_tile: introduces the ui/appwindow.slint file without explanation (Rust case)
- panic when pressing Tab on a rolled-down ComboBox HOT 1
- Python: Expose Slint enums
- Issue with DatePickerPopup When using LineEdit Callback HOT 2
- Broken todo-mvc example HOT 1
- placeholder issue for images
- How to request permissions on Android with Rust ? HOT 1
- Using tokio::time::sleep() in a future passed to spawn_local seems to hang HOT 1
- MacOS Widget issues HOT 1
- Callback edited in TextEdit does not work
- Callback "edited" in TextEdit does not work
- TextInput.focus in PopupWindow causes crash in i-slint-compiler HOT 3
- Property in two-way binding cannot be set in C++ in special cases
- After window.hide() first and then window.show(), the content is not refreshed and the interaction is not feedback. HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from slint.