mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-31 07:37:24 +00:00
Rename rust API
This commit is contained in:
parent
8d1c852e89
commit
cc3994b58d
128 changed files with 631 additions and 627 deletions
|
@ -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"
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -6,7 +6,8 @@
|
|||
fn main() {
|
||||
MainWindow::new().run();
|
||||
}
|
||||
sixtyfps::sixtyfps! {
|
||||
|
||||
slint::slint! {
|
||||
MainWindow := Window {
|
||||
Text {
|
||||
text: "hello world";
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
fn main() {
|
||||
MainWindow::new().run();
|
||||
}
|
||||
sixtyfps::sixtyfps! {
|
||||
slint::slint! {
|
||||
// ANCHOR: tile
|
||||
MemoryTile := Rectangle {
|
||||
width: 64px;
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
fn main() {
|
||||
MainWindow::new().run();
|
||||
}
|
||||
sixtyfps::sixtyfps! {
|
||||
slint::slint! {
|
||||
// ANCHOR: tile_data
|
||||
|
||||
// Added:
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
fn main() {
|
||||
MainWindow::new().run();
|
||||
}
|
||||
sixtyfps::sixtyfps! {
|
||||
slint::slint! {
|
||||
// ANCHOR: tile
|
||||
MemoryTile := Rectangle {
|
||||
callback clicked;
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue