mirror of
https://github.com/slint-ui/slint.git
synced 2025-09-30 13:51:13 +00:00
add js memory tutorial (#2421)
This commit is contained in:
parent
16fbee01fe
commit
c6472f9662
23 changed files with 597 additions and 2 deletions
23
docs/tutorial/node/src/main_tiles_from_js.js
Normal file
23
docs/tutorial/node/src/main_tiles_from_js.js
Normal file
|
@ -0,0 +1,23 @@
|
|||
// Copyright © SixtyFPS GmbH <info@slint-ui.com>
|
||||
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial
|
||||
|
||||
// ANCHOR: main
|
||||
// main.js
|
||||
let slint = require("slint-ui");
|
||||
let ui = require("./memory.slint");
|
||||
let mainWindow = new ui.MainWindow();
|
||||
|
||||
let initial_tiles = mainWindow.memory_tiles;
|
||||
let tiles = initial_tiles.concat(initial_tiles.map((tile) => Object.assign({}, tile)));
|
||||
|
||||
for (let i = tiles.length - 1; i > 0; i--) {
|
||||
const j = Math.floor(Math.random() * i);
|
||||
[tiles[i], tiles[j]] = [tiles[j], tiles[i]];
|
||||
}
|
||||
|
||||
let model = new slint.ArrayModel(tiles);
|
||||
mainWindow.memory_tiles = model;
|
||||
|
||||
mainWindow.run();
|
||||
|
||||
// ANCHOR_END: main
|
Loading…
Add table
Add a link
Reference in a new issue