mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-04 18:58:36 +00:00
Added a node version of the todo app
This commit is contained in:
parent
c59b1e61ac
commit
aad9306d54
6 changed files with 100 additions and 7 deletions
|
@ -15,15 +15,18 @@ int main()
|
|||
|
||||
auto todo_model = std::make_shared<sixtyfps::VectorModel<TodoItem>>(std::vector {
|
||||
TodoItem { true, "Implement the .60 file" },
|
||||
TodoItem { false, "Do the rust part" },
|
||||
TodoItem { false, "Do the Rust part" },
|
||||
TodoItem { true, "Make the C++ code" },
|
||||
TodoItem { false, "Write some JavaScript code" },
|
||||
TodoItem { false, "Test the application" },
|
||||
TodoItem { false, "Ship to customer" },
|
||||
TodoItem { false, "???" },
|
||||
TodoItem { false, "Profit" }
|
||||
});
|
||||
demo.set_todo_model(todo_model);
|
||||
|
||||
demo.on_todo_added([todo_model](const sixtyfps::SharedString &s) {
|
||||
todo_model->push_back(TodoItem { false, s} );
|
||||
todo_model->push_back(TodoItem { false, s });
|
||||
});
|
||||
|
||||
demo.on_remove_done([todo_model] {
|
||||
|
|
6
examples/todo/node/README
Normal file
6
examples/todo/node/README
Normal file
|
@ -0,0 +1,6 @@
|
|||
Run with
|
||||
|
||||
# npm install
|
||||
# npm start
|
||||
|
||||
|
67
examples/todo/node/main.js
Normal file
67
examples/todo/node/main.js
Normal file
|
@ -0,0 +1,67 @@
|
|||
#!/usr/bin/env node
|
||||
/* 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 */
|
||||
|
||||
// import "sixtyfps";
|
||||
let sixtyfps = require("sixtyfps");
|
||||
// import * as demo from "../ui/todo.60";
|
||||
let demo = require("../ui/todo.60");
|
||||
let app = new demo.MainWindow();
|
||||
|
||||
let model = new sixtyfps.ArrayModel([
|
||||
{
|
||||
title: "Implement the .60 file",
|
||||
checked: true
|
||||
},
|
||||
{
|
||||
title: "Do the Rust part",
|
||||
checked: false
|
||||
},
|
||||
{
|
||||
title: "Make the C++ code",
|
||||
checked: false
|
||||
},
|
||||
{
|
||||
title: "Write some JavaScript code",
|
||||
checked: true
|
||||
},
|
||||
{
|
||||
title: "Test the application",
|
||||
checked: false
|
||||
},
|
||||
{
|
||||
title: "Ship to customer",
|
||||
checked: false
|
||||
},
|
||||
{
|
||||
title: "???",
|
||||
checked: false
|
||||
},
|
||||
{
|
||||
title: "Profit",
|
||||
checked: false
|
||||
},
|
||||
]);
|
||||
app.todo_model = model;
|
||||
|
||||
app.todo_added.setHandler(function (text) {
|
||||
model.push({ title: text, checked: false })
|
||||
})
|
||||
|
||||
app.remove_done.setHandler(function () {
|
||||
for (const [i, item] of model.entries()) {
|
||||
if (item.checked) {
|
||||
model.remove(i, 1);
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
app.show();
|
||||
|
11
examples/todo/node/package.json
Normal file
11
examples/todo/node/package.json
Normal file
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"name": "todo",
|
||||
"version": "0.0.0",
|
||||
"main": "main.js",
|
||||
"dependencies": {
|
||||
"sixtyfps": "../../../api/sixtyfps-node"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "node ."
|
||||
}
|
||||
}
|
|
@ -25,8 +25,11 @@ pub fn main() {
|
|||
|
||||
let todo_model = Rc::new(sixtyfps::VecModel::<TodoItem>::from(vec![
|
||||
TodoItem { checked: true, title: "Implement the .60 file".into() },
|
||||
TodoItem { checked: true, title: "Do the rust part".into() },
|
||||
TodoItem { checked: true, title: "Do the Rust part".into() },
|
||||
TodoItem { checked: false, title: "Make the C++ code".into() },
|
||||
TodoItem { checked: false, title: "Write some JavaScript code".into() },
|
||||
TodoItem { checked: false, title: "Test the application".into() },
|
||||
TodoItem { checked: false, title: "Ship to customer".into() },
|
||||
TodoItem { checked: false, title: "???".into() },
|
||||
TodoItem { checked: false, title: "Profit".into() },
|
||||
]));
|
||||
|
|
|
@ -23,8 +23,11 @@ MainWindow := Window {
|
|||
|
||||
property <[TodoItem]> todo_model: [
|
||||
{ title: "Implement the .60 file", checked: true },
|
||||
{ title: "Do the rust part", checked: false },
|
||||
{ title: "Do the Rust part", checked: false },
|
||||
{ title: "Make the C++ code", checked: false },
|
||||
{ title: "Write some JavaScript code", checked: false },
|
||||
{ title: "Test the application", checked: false },
|
||||
{ title: "Ship to customer", checked: false },
|
||||
{ title: "???", checked: false },
|
||||
{ title: "Profit", checked: false },
|
||||
];
|
||||
|
@ -32,13 +35,13 @@ MainWindow := Window {
|
|||
GridLayout {
|
||||
Row {
|
||||
text_edit := LineEdit {
|
||||
text: "Something to do";
|
||||
text: "Play Golf";
|
||||
accepted(text) => {
|
||||
todo_added(text);
|
||||
}
|
||||
}
|
||||
btn := Button {
|
||||
text: "Add Todo";
|
||||
text: "Add New Entry";
|
||||
clicked => {
|
||||
todo_added(text_edit.text);
|
||||
}
|
||||
|
@ -70,7 +73,7 @@ MainWindow := Window {
|
|||
Row {
|
||||
Button {
|
||||
col: 1;
|
||||
text: "Remove done items!";
|
||||
text: "Remove Done Items";
|
||||
clicked => { root.remove_done(); }
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue