columnify, rowify a lil

master
Bel LaPointe 2023-03-27 15:13:08 -06:00
parent 21d8cfb185
commit ff2c41cf69
1 changed files with 35 additions and 27 deletions

View File

@ -1,4 +1,4 @@
use iced::widget::{button, column, text}; use iced::widget::{button, column, row, text};
use iced::widget::text_input; use iced::widget::text_input;
use iced::executor; use iced::executor;
use iced::keyboard; use iced::keyboard;
@ -35,8 +35,8 @@ pub fn main(cfg: GUI, output_stream: Box<dyn OutputStream>) -> iced::Result {
struct Main { struct Main {
c: std::sync::mpsc::Receiver<String>, c: std::sync::mpsc::Receiver<String>,
ntfy1: String, ntfy_from_client: String,
ntfy2: String, ntfy_from_server: String,
configuring: Option<Message>, configuring: Option<Message>,
inputs: Inputs, inputs: Inputs,
keys_newly_down: Vec<iced::keyboard::KeyCode>, keys_newly_down: Vec<iced::keyboard::KeyCode>,
@ -74,7 +74,6 @@ enum Message {
EventOccurred(iced_native::Event), EventOccurred(iced_native::Event),
Tick, Tick,
InputTextEntryUpdate(String), InputTextEntryUpdate(String),
InputTextEntrySubmission,
Up, Up,
Down, Down,
Left, Left,
@ -117,7 +116,7 @@ impl Main {
loop { loop {
match self.c.try_recv() { match self.c.try_recv() {
Ok(msg) => { Ok(msg) => {
self.ntfy2 = msg self.ntfy_from_server = msg
}, },
_ => return, _ => return,
}; };
@ -205,8 +204,8 @@ impl Application for Main {
}); });
return (Self { return (Self {
c: receiver, c: receiver,
ntfy1: String::from(":wave:"), ntfy_from_client: String::from(""),
ntfy2: String::from(""), ntfy_from_server: String::from(""),
configuring: None, configuring: None,
inputs: Inputs{ inputs: Inputs{
stick: Stick { stick: Stick {
@ -243,10 +242,12 @@ impl Application for Main {
Message::InputTextEntryUpdate(payload) => { Message::InputTextEntryUpdate(payload) => {
self.input_text_entry_value = payload; self.input_text_entry_value = payload;
}, },
/*
Message::InputTextEntrySubmission => { Message::InputTextEntrySubmission => {
eprintln!("input text entry pushed: {}", self.input_text_entry_value); // TODO do somethin with this eprintln!("input text entry pushed: {}", self.input_text_entry_value); // TODO do somethin with this
self.input_text_entry_value = String::from(""); self.input_text_entry_value = String::from("");
}, },
*/
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{
@ -267,7 +268,7 @@ impl Application for Main {
Message::R => { self.inputs.r = key_code }, Message::R => { self.inputs.r = key_code },
_ => {}, _ => {},
}; };
self.ntfy1 = format!("{:?} => {:?}", key_code.clone(), self.configuring.as_ref().unwrap()); self.ntfy_from_client = format!("{:?} => {:?}", key_code.clone(), self.configuring.as_ref().unwrap());
self.configuring = None; self.configuring = None;
}, },
_ => {}, _ => {},
@ -314,7 +315,7 @@ impl Application for Main {
}, },
_ => { _ => {
self.configuring = Some(msg.clone()); self.configuring = Some(msg.clone());
self.ntfy1 = format!("push a key to bind to {:?}", msg.clone()); self.ntfy_from_client = format!("push a key to bind to {:?}", msg.clone());
}, },
} }
return Command::none(); return Command::none();
@ -331,29 +332,36 @@ impl Application for Main {
} }
fn view(&self) -> Element<Message> { fn view(&self) -> Element<Message> {
let new_cfg_button = |msg: Message, s| button(text(controller_button_to_string(msg.clone(), s))).on_press(msg.clone());
return column![ return column![
button(text(controller_button_to_string(Message::Up, self.inputs.stick.up))).on_press(Message::Up), text(String::from("= MAYHEM PARTY =")).size(32),
button(text(controller_button_to_string(Message::Down, self.inputs.stick.down))).on_press(Message::Down), row![
button(text(controller_button_to_string(Message::Left, self.inputs.stick.left))).on_press(Message::Left), column![
button(text(controller_button_to_string(Message::Right, self.inputs.stick.right))).on_press(Message::Right), text(String::from("Button Mapping")).size(24),
button(text(controller_button_to_string(Message::A, self.inputs.a))).on_press(Message::A), text(String::from("--------------")).size(24),
button(text(controller_button_to_string(Message::B, self.inputs.b))).on_press(Message::B), new_cfg_button(Message::Up, self.inputs.stick.up),
button(text(controller_button_to_string(Message::X, self.inputs.x))).on_press(Message::X), new_cfg_button(Message::Down, self.inputs.stick.down),
button(text(controller_button_to_string(Message::Y, self.inputs.y))).on_press(Message::Y), new_cfg_button(Message::Left, self.inputs.stick.left),
button(text(controller_button_to_string(Message::L, self.inputs.l))).on_press(Message::L), new_cfg_button(Message::Right, self.inputs.stick.right),
button(text(controller_button_to_string(Message::R, self.inputs.r))).on_press(Message::R), new_cfg_button(Message::A, self.inputs.a),
text(self.ntfy1.clone()).size(50), new_cfg_button(Message::B, self.inputs.b),
text(self.ntfy2.clone()).size(50), new_cfg_button(Message::X, self.inputs.x),
new_cfg_button(Message::Y, self.inputs.y),
new_cfg_button(Message::L, self.inputs.l),
new_cfg_button(Message::R, self.inputs.r),
text(String::from("--------------")).size(24),
text(self.ntfy_from_client.clone()).size(18),
].padding(20).align_items(Alignment::Fill),
column![
text_input( text_input(
&self.input_text_entry_instruction, &self.input_text_entry_instruction,
&self.input_text_entry_value, &self.input_text_entry_value,
Message::InputTextEntryUpdate Message::InputTextEntryUpdate
) ),
.on_submit(Message::InputTextEntrySubmission), text(self.ntfy_from_server.clone()).size(18),
] ].padding(20).align_items(Alignment::Center),
.padding(20) ].padding(20).align_items(Alignment::Center),
.align_items(Alignment::Center) ].padding(20).align_items(Alignment::Center).into();
.into();
} }
} }