fix ui widget alignment, remove add row button, add timer for search request

This commit is contained in:
2026-07-27 01:52:24 +02:00
parent 7ba312528f
commit 153ba18d1c
3 changed files with 40 additions and 42 deletions
+35 -19
View File
@@ -9,34 +9,34 @@ 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_clone = items.clone();
ui.on_request_text_input(move |text| {
println!("User input: {}", text);
let response = rutracker::search(&text);
if let Some(ui) = ui_weak.upgrade() {
println!("User input: {}", text);
let now = std::time::Instant::now();
let new_items: Vec<StandardListViewItem> = match response {
Ok(softwares) => softwares
.into_iter()
.map(|s| StandardListViewItem::from(s.title.as_str()))
.collect(),
let response = rutracker::search(&text);
Err(e) => vec![StandardListViewItem::from(format!("Error: {}", e).as_str())],
};
let elapsed_time = now.elapsed();
println!("Search took {} seconds", elapsed_time.as_secs());
items_clone.set_vec(new_items);
});
let new_items: Vec<StandardListViewItem> = match response {
Ok(softwares) => softwares
.into_iter()
.map(|s| StandardListViewItem::from(s.title.as_str()))
.collect(),
let table_model = Rc::new(VecModel::from(Vec::<ModelRc<StandardListViewItem>>::new()));
let items_clone = items.clone();
Err(e) => vec![StandardListViewItem::from(format!("Error: {}", e).as_str())],
};
ui.set_table_data(table_model.clone().into());
ui.on_add_row({
move || {
for item in items_clone.iter() {
table_model.push(ModelRc::new(VecModel::from_slice(&[item.clone()])));
}
items_clone.set_vec(new_items);
let table_model = Rc::new(VecModel::from(Vec::<ModelRc<StandardListViewItem>>::new()));
ui.set_table_data(table_model.clone().into());
add_rows(&items_clone, &table_model);
}
});
@@ -44,3 +44,19 @@ fn main() -> Result<(), Box<dyn Error>> {
Ok(())
}
fn add_rows(
items: &Rc<VecModel<StandardListViewItem>>,
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()));
}
}
-4
View File
@@ -12,7 +12,6 @@ pub struct Software {
}
#[tokio::main]
//pub async fn search(value: &str) -> Result<Value, reqwest::Error> {
pub async fn search(value: &str) -> Result<Vec<Software>, reqwest::Error> {
let api_url = "https://api.michijackson.xyz/search?q=".to_owned();
let results = reqwest::get(api_url + value).await?;
@@ -26,11 +25,8 @@ pub async fn search(value: &str) -> Result<Vec<Software>, reqwest::Error> {
for item in data.as_array().unwrap() {
let software: Software =
serde_json::from_value(item.clone()).expect("Failed to deserialize");
println!("{:?}", software);
software_list.push(software);
}
//println!("{:?}", data);
//Ok(v)
Ok(software_list)
}
+5 -19
View File
@@ -1,9 +1,6 @@
import { Button, LineEdit, VerticalBox, HorizontalBox, StandardTableView } from "std-widgets.slint";
export component AppWindow inherits Window {
width: 200px;
height: 60px;
in-out property <string> search-text: "";
callback request-text-input(string);
@@ -11,11 +8,8 @@ export component AppWindow inherits Window {
callback add-row();
VerticalBox {
alignment: stretch;
// width: 50%;
// height: 50%;
LineEdit {
width: 500px;
placeholder-text: "Search for Software";
accepted(text) => {
root.request-text-input(self.text);
@@ -23,25 +17,17 @@ export component AppWindow inherits Window {
}
HorizontalBox {
alignment: stretch;
table := StandardTableView {
// width: 230px;
// height: 200px;
columns: [
{ title: "Post Title" },
{ title: "Author" },
{ title: "Seeders" },
{ title: "Leechers" },
{ title: "Post Title", horizontal_stretch: 0.5 },
{ title: "Author", horizontal_stretch: 0.3 },
{ title: "Seeders", horizontal_stretch: 0.1 },
{ title: "Leechers", horizontal_stretch: 0.1 },
];
rows: table-data;
}
Button {
text: "Add row";
clicked => {
add-row();
}
}
}
}
}