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