Add Spc and Clr buttons to MCDU
This commit is contained in:
parent
0f5d87eeba
commit
305d1e3f53
33
src/mcdu.rs
33
src/mcdu.rs
@ -23,6 +23,7 @@ pub enum McduOutput {
|
||||
#[derive(Debug)]
|
||||
pub enum KeyboardEvent {
|
||||
ButtonPress(char),
|
||||
ClrButtonPress,
|
||||
SearchStarted(String),
|
||||
QueryChanged(String),
|
||||
}
|
||||
@ -81,6 +82,30 @@ impl SimpleComponent for McduModel {
|
||||
.attach(&button, column as i32, row as i32, 1, 1);
|
||||
}
|
||||
|
||||
let button = gtk::Button::default();
|
||||
button.set_label("SPC");
|
||||
button.connect_clicked(glib::clone!(@strong sender => move |_| {
|
||||
sender.input(KeyboardEvent::ButtonPress(' '));
|
||||
}));
|
||||
let i = alphabet.len();
|
||||
let column = i % mcdu_width;
|
||||
let row = (i - column) / mcdu_width;
|
||||
widgets
|
||||
.keyboard
|
||||
.attach(&button, column as i32, row as i32, 1, 1);
|
||||
|
||||
let button = gtk::Button::default();
|
||||
button.set_label("CLR");
|
||||
button.connect_clicked(glib::clone!(@strong sender => move |_| {
|
||||
sender.input(KeyboardEvent::ClrButtonPress);
|
||||
}));
|
||||
let i = alphabet.len() + 1;
|
||||
let column = i % mcdu_width;
|
||||
let row = (i - column) / mcdu_width;
|
||||
widgets
|
||||
.keyboard
|
||||
.attach(&button, column as i32, row as i32, 1, 1);
|
||||
|
||||
ComponentParts { model, widgets }
|
||||
}
|
||||
|
||||
@ -88,12 +113,16 @@ impl SimpleComponent for McduModel {
|
||||
self.query_changed_by_mcdu_keys = false;
|
||||
match message {
|
||||
KeyboardEvent::ButtonPress(c) => {
|
||||
// println!("Button press: {}", c);
|
||||
self.query_changed_by_mcdu_keys = true;
|
||||
self.query.push(c);
|
||||
}
|
||||
KeyboardEvent::ClrButtonPress => {
|
||||
self.query_changed_by_mcdu_keys = true;
|
||||
self.query.clear();
|
||||
// Run search since gtk::SearchEntry will not run it if text is empty
|
||||
sender.input(KeyboardEvent::SearchStarted(String::new()));
|
||||
}
|
||||
KeyboardEvent::SearchStarted(s) => {
|
||||
// println!("Started search: {}", s);
|
||||
sender.output(McduOutput::SearchStarted(s)).unwrap();
|
||||
}
|
||||
KeyboardEvent::QueryChanged(query) => self.query = query,
|
||||
|
Loading…
x
Reference in New Issue
Block a user