Rename rust API

This commit is contained in:
Tobias Hunger 2022-02-02 11:16:18 +01:00
parent 8d1c852e89
commit cc3994b58d
No known key found for this signature in database
GPG key ID: 60874021D2F23F91
128 changed files with 631 additions and 627 deletions

View file

@ -37,5 +37,5 @@ name = "memory_tutorial_game_logic_in_rust"
path = "main_game_logic_in_rust.rs"
[dependencies]
sixtyfps = { path = "../../../../api/rs/slint" }
slint = { path = "../../../../api/rs/slint" }
rand = "0.8"

View file

@ -12,7 +12,7 @@ rand = "0.8" # Added
What we'll do is take the list of tiles declared in the .slint language, duplicate it, and shuffle it.
We'll do so by accessing the `memory_tiles` property through the Rust code. For each top-level property,
a getter and a setter function is generated - in our case `get_memory_tiles` and `set_memory_tiles`.
Since `memory_tiles` is an array in the `.slint` language, it is represented as a [`Rc<dyn sixtyfps::Model>`](https://sixtyfps.io/docs/rust/sixtyfps/trait.model).
Since `memory_tiles` is an array in the `.slint` language, it is represented as a [`Rc<dyn slint::Model>`](https://sixtyfps.io/docs/rust/sixtyfps/trait.model).
We can't modify the model generated by the .slint, but we can extract the tiles from it, and put it
in a [`VecModel`](https://sixtyfps.io/docs/rust/sixtyfps/struct.vecmodel) which implements the `Model` trait.
`VecModel` allows us to make modifications and we can use it to replace the static generated model.

View file

@ -3,7 +3,7 @@
#[allow(dead_code)]
fn main() {
use sixtyfps::Model;
use slint::Model;
let main_window = MainWindow::new();
@ -19,7 +19,7 @@ fn main() {
// ANCHOR: game_logic
// Assign the shuffled Vec to the model property
let tiles_model = std::rc::Rc::new(sixtyfps::VecModel::from(tiles));
let tiles_model = std::rc::Rc::new(slint::VecModel::from(tiles));
main_window.set_memory_tiles(tiles_model.clone().into());
let main_window_weak = main_window.as_weak();
@ -40,7 +40,7 @@ fn main() {
let main_window = main_window_weak.unwrap();
main_window.set_disable_tiles(true);
let tiles_model = tiles_model.clone();
sixtyfps::Timer::single_shot(std::time::Duration::from_secs(1), move || {
slint::Timer::single_shot(std::time::Duration::from_secs(1), move || {
main_window.set_disable_tiles(false);
t1.image_visible = false;
tiles_model.set_row_data(t1_idx, t1);
@ -54,7 +54,8 @@ fn main() {
main_window.run();
// ANCHOR_END: game_logic
}
sixtyfps::sixtyfps! {
slint::slint! {
struct TileData := {
image: image,
image_visible: bool,

View file

@ -6,7 +6,8 @@
fn main() {
MainWindow::new().run();
}
sixtyfps::sixtyfps! {
slint::slint! {
MainWindow := Window {
Text {
text: "hello world";

View file

@ -5,7 +5,7 @@
fn main() {
MainWindow::new().run();
}
sixtyfps::sixtyfps! {
slint::slint! {
// ANCHOR: tile
MemoryTile := Rectangle {
width: 64px;

View file

@ -5,7 +5,7 @@
fn main() {
MainWindow::new().run();
}
sixtyfps::sixtyfps! {
slint::slint! {
// ANCHOR: tile_data
// Added:

View file

@ -5,7 +5,7 @@
fn main() {
MainWindow::new().run();
}
sixtyfps::sixtyfps! {
slint::slint! {
// ANCHOR: tile
MemoryTile := Rectangle {
callback clicked;

View file

@ -4,7 +4,7 @@
#[allow(dead_code)]
// ANCHOR: tiles
fn main() {
use sixtyfps::Model;
use slint::Model;
let main_window = MainWindow::new();
@ -19,13 +19,14 @@ fn main() {
tiles.shuffle(&mut rng);
// Assign the shuffled Vec to the model property
let tiles_model = std::rc::Rc::new(sixtyfps::VecModel::from(tiles));
let tiles_model = std::rc::Rc::new(slint::VecModel::from(tiles));
main_window.set_memory_tiles(tiles_model.into());
main_window.run();
}
// ANCHOR_END: tiles
sixtyfps::sixtyfps! {
slint::slint! {
struct TileData := {
image: image,
image_visible: bool,