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