ITS A CONFIG GIVE OR TAKE
parent
54a7befcb9
commit
f137d9a823
|
|
@ -1936,6 +1936,7 @@ dependencies = [
|
||||||
"gilrs",
|
"gilrs",
|
||||||
"hidapi",
|
"hidapi",
|
||||||
"iced",
|
"iced",
|
||||||
|
"iced_native",
|
||||||
"rdkafka",
|
"rdkafka",
|
||||||
"rusb",
|
"rusb",
|
||||||
"serde",
|
"serde",
|
||||||
|
|
|
||||||
|
|
@ -13,3 +13,4 @@ rusb = "0.9.1"
|
||||||
hidapi = "0.5.0"
|
hidapi = "0.5.0"
|
||||||
gilrs = "0.10.1"
|
gilrs = "0.10.1"
|
||||||
iced = "0.8.0"
|
iced = "0.8.0"
|
||||||
|
iced_native = "0.9.1"
|
||||||
|
|
|
||||||
71
src/gui.rs
71
src/gui.rs
|
|
@ -1,5 +1,6 @@
|
||||||
use iced::widget::{button, column, text};
|
use iced::widget::{button, column, text};
|
||||||
use iced::{Alignment, Element, Sandbox, Settings};
|
use iced::executor;
|
||||||
|
use iced::{Alignment, Element, Application, Settings, Subscription, Theme, Command};
|
||||||
use iced_native::Event;
|
use iced_native::Event;
|
||||||
|
|
||||||
pub fn main() -> iced::Result {
|
pub fn main() -> iced::Result {
|
||||||
|
|
@ -8,10 +9,11 @@ pub fn main() -> iced::Result {
|
||||||
|
|
||||||
struct Main {
|
struct Main {
|
||||||
ntfy: String,
|
ntfy: String,
|
||||||
|
configuring: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone)]
|
||||||
enum ControllerButton {
|
enum Message {
|
||||||
EventOccurred(iced_native::Event),
|
EventOccurred(iced_native::Event),
|
||||||
Up,
|
Up,
|
||||||
Down,
|
Down,
|
||||||
|
|
@ -25,44 +27,63 @@ enum ControllerButton {
|
||||||
R,
|
R,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn controller_button_to_string(btn: ControllerButton) -> String {
|
fn controller_button_to_string(msg: Message) -> String {
|
||||||
return format!("{:?}", btn);
|
return format!("{:?}", msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Sandbox for Main {
|
impl Application for Main {
|
||||||
type Message = ControllerButton;
|
type Message = Message;
|
||||||
|
type Flags = ();
|
||||||
|
type Theme = Theme;
|
||||||
|
type Executor = executor::Default;
|
||||||
|
|
||||||
fn new() -> Self {
|
fn new(_flags: ()) -> (Self, Command<Message>) {
|
||||||
return Self { ntfy: String::from(":wave:") }
|
return (Self {
|
||||||
|
ntfy: String::from(":wave:"),
|
||||||
|
configuring: false,
|
||||||
|
}, Command::none())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn title(&self) -> String {
|
fn title(&self) -> String {
|
||||||
return String::from("Rusty Pipe")
|
return String::from("Rusty Pipe")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(&mut self, controllerButton: ControllerButton) {
|
fn update(&mut self, msg: Message) -> Command<Message> {
|
||||||
match message {
|
match msg {
|
||||||
ControllerButton::EventOccurred(Event) => {
|
Message::EventOccurred(event) if self.configuring => {
|
||||||
Err(String::from("ohno")).unwrap();
|
match event {
|
||||||
|
iced_native::Event::Keyboard(kb) => {
|
||||||
|
self.ntfy = format!("would set {:?}", kb);
|
||||||
|
self.configuring = false;
|
||||||
},
|
},
|
||||||
|
_ => {},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Message::EventOccurred(event) if ! self.configuring => {},
|
||||||
_ => {
|
_ => {
|
||||||
self.ntfy = format!("push a key to bind to {:?}", controllerButton);
|
self.configuring = true;
|
||||||
|
self.ntfy = format!("push a key to bind to {:?}", msg);
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
return Command::none();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn view(&self) -> Element<ControllerButton> {
|
fn subscription(&self) -> Subscription<Message> {
|
||||||
|
iced_native::subscription::events().map(Message::EventOccurred)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn view(&self) -> Element<Message> {
|
||||||
return column![
|
return column![
|
||||||
button(text(controller_button_to_string(ControllerButton::Up))).on_press(ControllerButton::Up),
|
button(text(controller_button_to_string(Message::Up))).on_press(Message::Up),
|
||||||
button(text(controller_button_to_string(ControllerButton::Down))).on_press(ControllerButton::Down),
|
button(text(controller_button_to_string(Message::Down))).on_press(Message::Down),
|
||||||
button(text(controller_button_to_string(ControllerButton::Left))).on_press(ControllerButton::Left),
|
button(text(controller_button_to_string(Message::Left))).on_press(Message::Left),
|
||||||
button(text(controller_button_to_string(ControllerButton::Right))).on_press(ControllerButton::Right),
|
button(text(controller_button_to_string(Message::Right))).on_press(Message::Right),
|
||||||
button(text(controller_button_to_string(ControllerButton::A))).on_press(ControllerButton::A),
|
button(text(controller_button_to_string(Message::A))).on_press(Message::A),
|
||||||
button(text(controller_button_to_string(ControllerButton::B))).on_press(ControllerButton::B),
|
button(text(controller_button_to_string(Message::B))).on_press(Message::B),
|
||||||
button(text(controller_button_to_string(ControllerButton::X))).on_press(ControllerButton::X),
|
button(text(controller_button_to_string(Message::X))).on_press(Message::X),
|
||||||
button(text(controller_button_to_string(ControllerButton::Y))).on_press(ControllerButton::Y),
|
button(text(controller_button_to_string(Message::Y))).on_press(Message::Y),
|
||||||
button(text(controller_button_to_string(ControllerButton::L))).on_press(ControllerButton::L),
|
button(text(controller_button_to_string(Message::L))).on_press(Message::L),
|
||||||
button(text(controller_button_to_string(ControllerButton::R))).on_press(ControllerButton::R),
|
button(text(controller_button_to_string(Message::R))).on_press(Message::R),
|
||||||
text(self.ntfy.clone()).size(50),
|
text(self.ntfy.clone()).size(50),
|
||||||
]
|
]
|
||||||
.padding(20)
|
.padding(20)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue