feat: populate all table columns
This commit is contained in:
+19
-13
@@ -10,7 +10,7 @@ slint::include_modules!();
|
||||
fn main() -> Result<(), Box<dyn Error>> {
|
||||
let ui = AppWindow::new()?;
|
||||
let ui_weak = ui.as_weak();
|
||||
let items = Rc::new(VecModel::<StandardListViewItem>::from(Vec::new()));
|
||||
let items = Rc::new(VecModel::<[StandardListViewItem; 4]>::from(Vec::new()));
|
||||
|
||||
let items_clone = items.clone();
|
||||
ui.on_request_text_input(move |text| {
|
||||
@@ -23,13 +23,25 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
let elapsed_time = now.elapsed();
|
||||
println!("Search took {} seconds", elapsed_time.as_secs());
|
||||
|
||||
let new_items: Vec<StandardListViewItem> = match response {
|
||||
let new_items: Vec<[StandardListViewItem; 4]> = match response {
|
||||
Ok(softwares) => softwares
|
||||
.into_iter()
|
||||
.map(|s| StandardListViewItem::from(s.title.as_str()))
|
||||
.map(|s| {
|
||||
[
|
||||
StandardListViewItem::from(s.title.as_str()),
|
||||
StandardListViewItem::from(s.author.as_str()),
|
||||
StandardListViewItem::from(s.seeders.as_str()),
|
||||
StandardListViewItem::from(s.leechers.as_str()),
|
||||
]
|
||||
})
|
||||
.collect(),
|
||||
|
||||
Err(e) => vec![StandardListViewItem::from(format!("Error: {}", e).as_str())],
|
||||
Err(e) => vec![[
|
||||
StandardListViewItem::from(format!("Error: {}", e).as_str()),
|
||||
StandardListViewItem::from(format!("Error: {}", e).as_str()),
|
||||
StandardListViewItem::from(format!("Error: {}", e).as_str()),
|
||||
StandardListViewItem::from(format!("Error: {}", e).as_str()),
|
||||
]],
|
||||
};
|
||||
|
||||
items_clone.set_vec(new_items);
|
||||
@@ -46,17 +58,11 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
}
|
||||
|
||||
fn add_rows(
|
||||
items: &Rc<VecModel<StandardListViewItem>>,
|
||||
items: &Rc<VecModel<[StandardListViewItem; 4]>>,
|
||||
table_model: &Rc<VecModel<ModelRc<StandardListViewItem>>>,
|
||||
) {
|
||||
for item in items.iter() {
|
||||
let row = Rc::new(VecModel::from(vec![
|
||||
item.clone(),
|
||||
StandardListViewItem::from("placeholder column 1"),
|
||||
StandardListViewItem::from("placeholder column 2"),
|
||||
StandardListViewItem::from("placeholder column 3"),
|
||||
]));
|
||||
|
||||
table_model.push(ModelRc::from(row.clone()));
|
||||
let row = Rc::new(VecModel::from(item.to_vec()));
|
||||
table_model.push(ModelRc::from(row));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user