I DID it
parent
941220eef8
commit
3ef0a15ce4
47
src/gui.rs
47
src/gui.rs
|
|
@ -1,7 +1,9 @@
|
||||||
use iced::widget::{button, column, text};
|
use iced::widget::{button, column, text};
|
||||||
use iced::executor;
|
use iced::executor;
|
||||||
|
use iced::keyboard;
|
||||||
|
use iced::event;
|
||||||
|
use iced::subscription;
|
||||||
use iced::{Alignment, Element, Application, Settings, Subscription, Theme, Command};
|
use iced::{Alignment, Element, Application, Settings, Subscription, Theme, Command};
|
||||||
use iced_native::Event;
|
|
||||||
|
|
||||||
pub fn main() -> iced::Result {
|
pub fn main() -> iced::Result {
|
||||||
Main::run(Settings::default())
|
Main::run(Settings::default())
|
||||||
|
|
@ -10,7 +12,24 @@ pub fn main() -> iced::Result {
|
||||||
struct Main {
|
struct Main {
|
||||||
ntfy: String,
|
ntfy: String,
|
||||||
configuring: bool,
|
configuring: bool,
|
||||||
inputs: std::collections::HashMap<Message, char>,
|
inputs: Inputs,
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Inputs {
|
||||||
|
stick: Stick,
|
||||||
|
a: char,
|
||||||
|
b: char,
|
||||||
|
x: char,
|
||||||
|
y: char,
|
||||||
|
l: char,
|
||||||
|
r: char,
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Stick {
|
||||||
|
up: char,
|
||||||
|
down: char,
|
||||||
|
left: char,
|
||||||
|
right: char,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
|
@ -42,6 +61,20 @@ impl Application for Main {
|
||||||
return (Self {
|
return (Self {
|
||||||
ntfy: String::from(":wave:"),
|
ntfy: String::from(":wave:"),
|
||||||
configuring: false,
|
configuring: false,
|
||||||
|
inputs: Inputs{
|
||||||
|
stick: Stick {
|
||||||
|
up: 'w',
|
||||||
|
down: 's',
|
||||||
|
left: 'a',
|
||||||
|
right: 'd',
|
||||||
|
},
|
||||||
|
a: 'k',
|
||||||
|
b: 'j',
|
||||||
|
x: 'i',
|
||||||
|
y: 'u',
|
||||||
|
l: 'q',
|
||||||
|
r: 'e',
|
||||||
|
},
|
||||||
}, Command::none())
|
}, Command::none())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -53,8 +86,12 @@ impl Application for Main {
|
||||||
match msg {
|
match msg {
|
||||||
Message::EventOccurred(event) if self.configuring => {
|
Message::EventOccurred(event) if self.configuring => {
|
||||||
match event {
|
match event {
|
||||||
iced_native::Event::Keyboard(kb) => {
|
iced::event::Event::Keyboard(keyboard::Event::KeyPressed{
|
||||||
self.ntfy = format!("would set {:?}", kb);
|
key_code,
|
||||||
|
modifiers,
|
||||||
|
..
|
||||||
|
}) => {
|
||||||
|
self.ntfy = format!("would set {:?}", key_code);
|
||||||
self.configuring = false;
|
self.configuring = false;
|
||||||
},
|
},
|
||||||
_ => {},
|
_ => {},
|
||||||
|
|
@ -70,7 +107,7 @@ impl Application for Main {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn subscription(&self) -> Subscription<Message> {
|
fn subscription(&self) -> Subscription<Message> {
|
||||||
iced_native::subscription::events().map(Message::EventOccurred)
|
return subscription::events().map(Message::EventOccurred)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn view(&self) -> Element<Message> {
|
fn view(&self) -> Element<Message> {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue