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:
Simon Hausmann 2021-06-15 19:08:08 +02:00
parent fbf011abf2
commit 9da1bc7eb6
6 changed files with 93 additions and 72 deletions

View 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(&amp;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();
}