mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-05 08:00:21 +00:00
Rename tutorial to quickstart (#4941)
This commit is contained in:
parent
02775f7783
commit
7afa34a7e1
79 changed files with 35 additions and 35 deletions
27
docs/quickstart/cpp/src/creating_the_tiles_from_cpp.md
Normal file
27
docs/quickstart/cpp/src/creating_the_tiles_from_cpp.md
Normal file
|
@ -0,0 +1,27 @@
|
|||
<!-- Copyright © SixtyFPS GmbH <info@slint.dev> ; SPDX-License-Identifier: MIT -->
|
||||
|
||||
# Creating The Tiles From C++
|
||||
|
||||
This step places the game tiles randomly.
|
||||
|
||||
Change the `main` function and includes in `src/main.cpp` to the following:
|
||||
|
||||
```cpp
|
||||
{{#include main_tiles_from_cpp.cpp:main}}
|
||||
```
|
||||
|
||||
The code takes the list of tiles, duplicates it, and shuffles it, accessing the `memory_tiles` property through the C++ code.
|
||||
|
||||
For each top-level property, Slint generates a getter and a setter function. In this case `get_memory_tiles` and `set_memory_tiles`.
|
||||
Since `memory_tiles` is a Slint array, it's represented as a [`std::shared_ptr<slint::Model>`](https://slint.dev/docs/cpp/api/classslint_1_1model).
|
||||
|
||||
You can't change the model generated by Slint, but you can extract the tiles from it and put them
|
||||
in a [`slint::VectorModel`](https://slint.dev/docs/cpp/api/classslint_1_1vectormodel) which inherits from `Model`.
|
||||
`VectorModel` lets you make changes and you can use it to replace the static generated model.
|
||||
|
||||
Running this code opens a window that now shows a 4 by 4 grid of rectangles, which show or hide
|
||||
the icons when a player clicks on them.
|
||||
|
||||
There's one last aspect missing now, the rules for the game.
|
||||
|
||||
<video autoplay loop muted playsinline src="https://slint.dev/blog/memory-game-tutorial/creating-the-tiles-from-rust.mp4"></video>
|
Loading…
Add table
Add a link
Reference in a new issue