mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-02 06:41:14 +00:00
tutorial: separate out the rust code into .rs files
That way even the "incomplete" snippets can be compile tested as only the anchors will be pulled into the docs but the complete file can be compile-tested in the future.
This commit is contained in:
parent
fbf011abf2
commit
9da1bc7eb6
6 changed files with 93 additions and 72 deletions
24
docs/tutorial/src/main_tiles_from_rust.rs
Normal file
24
docs/tutorial/src/main_tiles_from_rust.rs
Normal file
|
@ -0,0 +1,24 @@
|
|||
fn main() {
|
||||
use sixtyfps::Model;
|
||||
|
||||
let main_window = MainWindow::new();
|
||||
|
||||
// Fetch the tiles from the model
|
||||
let mut tiles: Vec<TileData> =
|
||||
main_window.get_memory_tiles().iter().collect();
|
||||
// Duplicate them to ensure that we have pairs
|
||||
tiles.extend(tiles.clone());
|
||||
|
||||
// Randomly mix the tiles
|
||||
use rand::seq::SliceRandom;
|
||||
let mut rng = rand::thread_rng();
|
||||
tiles.shuffle(&mut rng);
|
||||
|
||||
// Assign the shuffled Vec to the model property
|
||||
let tiles_model =
|
||||
std::rc::Rc::new(sixtyfps::VecModel::from(tiles));
|
||||
main_window.set_memory_tiles(
|
||||
sixtyfps::ModelHandle::new(tiles_model.clone()));
|
||||
|
||||
main_window.run();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue