mirror of
https://github.com/slint-ui/slint.git
synced 2025-09-05 18:10:42 +00:00
C++ tutorial: Remove inline sources from the creating tiles from C++ chapter
This commit is contained in:
parent
6e4da0c14e
commit
4affbf728d
4 changed files with 116 additions and 22 deletions
35
docs/tutorial/cpp/src/main_tiles_from_cpp.cpp
Normal file
35
docs/tutorial/cpp/src/main_tiles_from_cpp.cpp
Normal file
|
@ -0,0 +1,35 @@
|
|||
/* LICENSE BEGIN
|
||||
This file is part of the SixtyFPS Project -- https://sixtyfps.io
|
||||
Copyright (c) 2020 Olivier Goffart <olivier.goffart@sixtyfps.io>
|
||||
Copyright (c) 2020 Simon Hausmann <simon.hausmann@sixtyfps.io>
|
||||
|
||||
SPDX-License-Identifier: GPL-3.0-only
|
||||
This file is also available under commercial licensing terms.
|
||||
Please contact info@sixtyfps.io for more information.
|
||||
LICENSE END */
|
||||
// main.cpp
|
||||
|
||||
#include "memory_tiles_from_cpp.h" // generated header from memory_tiles_from_cpp.60
|
||||
// ANCHOR: main
|
||||
// ...
|
||||
|
||||
#include <random> // Added
|
||||
|
||||
int main()
|
||||
{
|
||||
auto main_window = MainWindow::create();
|
||||
auto old_tiles = main_window->get_memory_tiles();
|
||||
std::vector<TileData> new_tiles;
|
||||
new_tiles.reserve(old_tiles->row_count() * 2);
|
||||
for (int i = 0; i < old_tiles->row_count(); ++i) {
|
||||
new_tiles.push_back(old_tiles->row_data(i));
|
||||
new_tiles.push_back(old_tiles->row_data(i));
|
||||
}
|
||||
std::default_random_engine rng {};
|
||||
std::shuffle(new_tiles.begin(), new_tiles.end(), rng);
|
||||
auto tiles_model = std::make_shared<sixtyfps::VectorModel<TileData>>(new_tiles);
|
||||
main_window->set_memory_tiles(tiles_model);
|
||||
|
||||
main_window->run();
|
||||
}
|
||||
// ANCHOR_END: main
|
Loading…
Add table
Add a link
Reference in a new issue