diff --git a/src/main.rs b/src/main.rs index 0e0069a..e4f166b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,9 @@ #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] -use std::error::Error; mod rutracker; +use slint::{ModelRc, StandardListViewItem, VecModel}; +use std::error::Error; +use std::rc::Rc; slint::include_modules!(); @@ -13,6 +15,22 @@ fn main() -> Result<(), Box> { let _response = rutracker::search(&text); }); + let table_vec: Vec> = vec![]; + let table_model = Rc::new(VecModel::from(table_vec)); + + let test = "test"; + ui.set_table_data(table_model.to_owned().into()); + ui.on_add_row({ + move || { + table_model.push(VecModel::from_slice(&[ + StandardListViewItem::from(slint::SharedString::from(test)), + //StandardListViewItem::from(""), + ])); + } + }); + + ui.run().unwrap(); + ui.run()?; Ok(()) diff --git a/ui/app-window.slint b/ui/app-window.slint index 87a2e34..71d829a 100644 --- a/ui/app-window.slint +++ b/ui/app-window.slint @@ -6,6 +6,9 @@ export component AppWindow inherits Window { in-out property search-text: ""; callback request-text-input(string); + + in-out property <[[StandardListViewItem]]> table-data; + callback add-row(); VerticalBox { alignment: stretch; // width: 50%; @@ -20,7 +23,7 @@ export component AppWindow inherits Window { } HorizontalBox { - StandardTableView { + table := StandardTableView { // width: 230px; // height: 200px; @@ -30,17 +33,14 @@ export component AppWindow inherits Window { { title: "Seeders" }, { title: "Leechers" }, ]; - rows: [ - [ - { text: "Item 1" }, { text: "Item 2" }, - ], - [ - { text: "Item 1" }, { text: "Item 2" }, - ], - [ - { text: "Item 1" }, { text: "Item 2" }, - ] - ]; + rows: table-data; + } + + Button { + text: "Add row"; + clicked => { + add-row(); + } } } }