Implement working search bar
This commit is contained in:
22
src/main.rs
22
src/main.rs
@@ -6,17 +6,16 @@ use std::{env, path::PathBuf, process};
|
||||
use gtk::prelude::*;
|
||||
use mcdu::McduModel;
|
||||
use relm4::prelude::*;
|
||||
use sheet_listing::SheetListingModel;
|
||||
use sheet_listing::{SheetListingInput, SheetListingModel};
|
||||
|
||||
struct AppModel {
|
||||
text: String,
|
||||
mcdu: Controller<McduModel>,
|
||||
sheet_listing: Controller<SheetListingModel>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
enum AppInput {
|
||||
McduInput(char),
|
||||
SearchStarted(String),
|
||||
SheetPressed(PathBuf),
|
||||
}
|
||||
|
||||
@@ -44,17 +43,7 @@ impl SimpleComponent for AppModel {
|
||||
// set_hscrollbar_policy: PolicyType::Never,
|
||||
},
|
||||
},
|
||||
gtk::Box {
|
||||
set_orientation: gtk::Orientation::Vertical,
|
||||
set_valign: gtk::Align::Center,
|
||||
model.mcdu.widget(),
|
||||
#[name = "label"]
|
||||
gtk::Label {
|
||||
#[watch]
|
||||
set_label: &model.text,
|
||||
set_margin_all: 5,
|
||||
}
|
||||
},
|
||||
model.mcdu.widget(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -69,7 +58,7 @@ impl SimpleComponent for AppModel {
|
||||
let mcdu = McduModel::builder()
|
||||
.launch(())
|
||||
.forward(sender.input_sender(), |response| match response {
|
||||
mcdu::McduOutput::ButtonPress(c) => AppInput::McduInput(c),
|
||||
mcdu::McduOutput::SearchStarted(query) => AppInput::SearchStarted(query),
|
||||
});
|
||||
|
||||
let sheet_listing =
|
||||
@@ -82,7 +71,6 @@ impl SimpleComponent for AppModel {
|
||||
});
|
||||
|
||||
let model = AppModel {
|
||||
text: String::from("Text: "),
|
||||
mcdu,
|
||||
sheet_listing,
|
||||
};
|
||||
@@ -94,8 +82,8 @@ impl SimpleComponent for AppModel {
|
||||
|
||||
fn update(&mut self, message: Self::Input, _sender: ComponentSender<Self>) {
|
||||
match message {
|
||||
AppInput::McduInput(c) => self.text.push(c),
|
||||
AppInput::SheetPressed(sheet) => opener::open(sheet).unwrap(),
|
||||
AppInput::SearchStarted(query) => self.sheet_listing.emit(SheetListingInput { query }),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user