C++ model for the todo example in C++

This commit is contained in:
Olivier Goffart 2020-09-30 18:30:19 +02:00
parent f01977ca06
commit 6d9af3449a
2 changed files with 27 additions and 1 deletions

View file

@ -12,5 +12,30 @@ LICENSE END */
int main()
{
static MainWindow demo;
auto todo_model = std::make_shared<sixtyfps::VectorModel<TodoItem>>(std::vector {
TodoItem { true, "Implement the .60 file" },
TodoItem { false, "Do the rust part" },
TodoItem { true, "Make the C++ code" },
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} );
});
demo.on_remove_done([todo_model] {
int offset = 0;
int count = todo_model->row_count();
for (int i = 0; i < count; ++i) {
if (todo_model->row_data(i - offset).checked) {
todo_model->erase(i - offset);
offset += 1;
}
}
});
demo.run();
}