gotta map keycodes to strings since single chars dont cover stuff like arrows nicely
parent
cc7329f6e4
commit
1b687c445a
BIN
src/.gui.rs.swp
BIN
src/.gui.rs.swp
Binary file not shown.
62
src/gui.rs
62
src/gui.rs
|
|
@ -11,7 +11,7 @@ pub fn main() -> iced::Result {
|
||||||
|
|
||||||
struct Main {
|
struct Main {
|
||||||
ntfy: String,
|
ntfy: String,
|
||||||
configuring: Option<&char>,
|
configuring: Option<Message>,
|
||||||
inputs: Inputs,
|
inputs: Inputs,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -83,26 +83,68 @@ impl Application for Main {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(&mut self, msg: Message) -> Command<Message> {
|
fn update(&mut self, msg: Message) -> Command<Message> {
|
||||||
match msg {
|
match msg.clone() {
|
||||||
Message::EventOccurred(event) if self.configuring.is_some() => {
|
Message::EventOccurred(event) if self.configuring.is_some() => {
|
||||||
match event {
|
match event {
|
||||||
iced::event::Event::Keyboard(keyboard::Event::KeyPressed{
|
iced::event::Event::Keyboard(keyboard::Event::KeyPressed{
|
||||||
key_code,
|
key_code,
|
||||||
modifiers,
|
modifiers: _,
|
||||||
..
|
..
|
||||||
}) => {
|
}) => {
|
||||||
self.ntfy = format!("would set {:?}", key_code);
|
let key_char = match key_code {
|
||||||
|
iced::keyboard::KeyCode::Key1 => '1',
|
||||||
|
iced::keyboard::KeyCode::Key2 => '2',
|
||||||
|
iced::keyboard::KeyCode::Key3 => '3',
|
||||||
|
iced::keyboard::KeyCode::Key4 => '4',
|
||||||
|
iced::keyboard::KeyCode::Key5 => '5',
|
||||||
|
iced::keyboard::KeyCode::Key6 => '6',
|
||||||
|
iced::keyboard::KeyCode::Key7 => '7',
|
||||||
|
iced::keyboard::KeyCode::Key8 => '8',
|
||||||
|
iced::keyboard::KeyCode::Key9 => '9',
|
||||||
|
iced::keyboard::KeyCode::Key0 => '0',
|
||||||
|
iced::keyboard::KeyCode::A => 'a',
|
||||||
|
iced::keyboard::KeyCode::B => 'b',
|
||||||
|
iced::keyboard::KeyCode::C => 'c',
|
||||||
|
iced::keyboard::KeyCode::D => 'd',
|
||||||
|
iced::keyboard::KeyCode::E => 'e',
|
||||||
|
iced::keyboard::KeyCode::F => 'f',
|
||||||
|
iced::keyboard::KeyCode::G => 'g',
|
||||||
|
iced::keyboard::KeyCode::H => 'h',
|
||||||
|
iced::keyboard::KeyCode::I => 'i',
|
||||||
|
iced::keyboard::KeyCode::J => 'j',
|
||||||
|
iced::keyboard::KeyCode::K => 'k',
|
||||||
|
iced::keyboard::KeyCode::L => 'l',
|
||||||
|
iced::keyboard::KeyCode::M => 'm',
|
||||||
|
iced::keyboard::KeyCode::N => 'n',
|
||||||
|
iced::keyboard::KeyCode::O => 'o',
|
||||||
|
iced::keyboard::KeyCode::P => 'p',
|
||||||
|
iced::keyboard::KeyCode::Q => 'q',
|
||||||
|
iced::keyboard::KeyCode::R => 'r',
|
||||||
|
iced::keyboard::KeyCode::S => 's',
|
||||||
|
iced::keyboard::KeyCode::T => 't',
|
||||||
|
iced::keyboard::KeyCode::U => 'u',
|
||||||
|
iced::keyboard::KeyCode::V => 'v',
|
||||||
|
iced::keyboard::KeyCode::W => 'w',
|
||||||
|
iced::keyboard::KeyCode::X => 'x',
|
||||||
|
iced::keyboard::KeyCode::Y => 'y',
|
||||||
|
iced::keyboard::KeyCode::Z => 'z',
|
||||||
|
iced::keyboard::KeyCode::Up => 'a',
|
||||||
|
_ => '`',
|
||||||
|
};
|
||||||
|
self.ntfy = format!("set {:?}", key_char.clone());
|
||||||
|
match self.configuring.as_ref().unwrap() {
|
||||||
|
Message::Up => { self.inputs.stick.up = key_char },
|
||||||
|
_ => {},
|
||||||
|
};
|
||||||
self.configuring = None;
|
self.configuring = None;
|
||||||
},
|
},
|
||||||
_ => {},
|
_ => {},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Message::EventOccurred(event) if ! self.configuring => {},
|
Message::EventOccurred(_) => {},
|
||||||
_ => {
|
_ => {
|
||||||
self.configuring = Some(match event {
|
self.configuring = Some(msg.clone());
|
||||||
_ => None,
|
self.ntfy = format!("push a key to bind to {:?}", msg.clone());
|
||||||
});
|
|
||||||
self.ntfy = format!("push a key to bind to {:?}", msg);
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
return Command::none();
|
return Command::none();
|
||||||
|
|
@ -110,7 +152,7 @@ impl Application for Main {
|
||||||
|
|
||||||
fn subscription(&self) -> Subscription<Message> {
|
fn subscription(&self) -> Subscription<Message> {
|
||||||
return subscription::events_with(|event, _| match event {
|
return subscription::events_with(|event, _| match event {
|
||||||
iced::Event::Keyboard(x) => Some(Message::EventOccurred(event)),
|
iced::Event::Keyboard(_) => Some(Message::EventOccurred(event)),
|
||||||
_ => None,
|
_ => None,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue