-
Hey, Slint Code:
`` Rust Method: ``pub fn fetch_customers() -> Vec {
} Any help is appreciated 🙏 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You will need to define a struct Customer {
name: string,
age: int,
} Then you can have a You use that model like this: for customer in root.model : Rectangle {
height: 40px;
width: parent.width;
Button {
x: 0;
text: data.text;
//color: white;
width: parent.width;
}
} Then you implement that model on the rust side (the Customer stuct is visible there!) and set it into the slint property. The benefit of using a model is that you can add/remove/change elements in the model and that will do the right things... In your approach it would get a fresh array of elements each time it needs to render the customers... which transfers a lot of data and will rerender anything from scratch each time. That is hugely inefficient and will also trash your UI state like scroll location and such. The docs to a There is an example using a VecModel here: slint/examples/todo/rust/lib.rs Line 27 in 1a9d09b I hope this helps! |
Beta Was this translation helpful? Give feedback.
You will need to define a
Customer
struct in Slint:Then you can have a
in property <[Customer]> model;
in your main slint component with a list of those customers.You use that model like this:
Then you implement that model on the rust side (the Customer stuct is visible there!) and set it into the slint property.
The benefit of using a model is that you can add/remove/change elements in the model…