|
|
@ -4,12 +4,10 @@ use crate::gui_events::GuiEvent; |
|
|
|
use crate::message::{DegMessage, DegMessageContent, ProtocolMsg}; |
|
|
|
use crate::message::{DegMessage, DegMessageContent, ProtocolMsg}; |
|
|
|
use crate::styles::style; |
|
|
|
use crate::styles::style; |
|
|
|
use core::default::Default; |
|
|
|
use core::default::Default; |
|
|
|
use iced::window::Mode; |
|
|
|
|
|
|
|
use iced::{ |
|
|
|
use iced::{ |
|
|
|
button, Align, Application, Button, Color, Column, Element, HorizontalAlignment, Length, Row, |
|
|
|
button, Align, Application, Button, Column, Element, HorizontalAlignment, Length, Row, |
|
|
|
Settings, Text, TextInput, VerticalAlignment, |
|
|
|
Text, TextInput, VerticalAlignment, |
|
|
|
}; |
|
|
|
}; |
|
|
|
use ironforce::res::{IFError, IFResult}; |
|
|
|
|
|
|
|
use ironforce::PublicKey; |
|
|
|
use ironforce::PublicKey; |
|
|
|
|
|
|
|
|
|
|
|
/// Render a message into an iced `Element`
|
|
|
|
/// Render a message into an iced `Element`
|
|
|
@ -49,6 +47,7 @@ pub enum AppScreen { |
|
|
|
/// Settings and profile
|
|
|
|
/// Settings and profile
|
|
|
|
ProfileEditor, |
|
|
|
ProfileEditor, |
|
|
|
/// The screen that appears if no peers are available and asks for the IP address of at least one peer
|
|
|
|
/// The screen that appears if no peers are available and asks for the IP address of at least one peer
|
|
|
|
|
|
|
|
#[allow(dead_code)] |
|
|
|
PeerInput, |
|
|
|
PeerInput, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -73,6 +72,10 @@ pub struct DegeonApp { |
|
|
|
text_input_state: iced::text_input::State, |
|
|
|
text_input_state: iced::text_input::State, |
|
|
|
/// Buttons for chat previews
|
|
|
|
/// Buttons for chat previews
|
|
|
|
preview_button_states: Vec<button::State>, |
|
|
|
preview_button_states: Vec<button::State>, |
|
|
|
|
|
|
|
/// Name input on profile screen
|
|
|
|
|
|
|
|
name_input_state: iced::text_input::State, |
|
|
|
|
|
|
|
/// Button on the profile screen
|
|
|
|
|
|
|
|
profile_done_button_state: iced::button::State, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
impl DegeonApp { |
|
|
|
impl DegeonApp { |
|
|
@ -145,6 +148,46 @@ impl DegeonApp { |
|
|
|
.height(Length::Fill) |
|
|
|
.height(Length::Fill) |
|
|
|
.into() |
|
|
|
.into() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn profile_editor(&mut self) -> Element<GuiEvent> { |
|
|
|
|
|
|
|
let Self { |
|
|
|
|
|
|
|
data: |
|
|
|
|
|
|
|
Degeon { |
|
|
|
|
|
|
|
profile: crate::message::Profile { name }, |
|
|
|
|
|
|
|
.. |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
profile_done_button_state, |
|
|
|
|
|
|
|
name_input_state, |
|
|
|
|
|
|
|
.. |
|
|
|
|
|
|
|
} = self; |
|
|
|
|
|
|
|
iced::Container::new( |
|
|
|
|
|
|
|
Column::new() |
|
|
|
|
|
|
|
.align_items(Align::Center) |
|
|
|
|
|
|
|
.width(Length::Fill) |
|
|
|
|
|
|
|
.spacing(60) |
|
|
|
|
|
|
|
.push(Text::new("Profile")) |
|
|
|
|
|
|
|
.push( |
|
|
|
|
|
|
|
iced::Container::new(Row::with_children(vec![ |
|
|
|
|
|
|
|
Text::new("Name").into(), |
|
|
|
|
|
|
|
TextInput::new(name_input_state, "Name", name.as_str(), |name| { |
|
|
|
|
|
|
|
GuiEvent::ChangeName(name) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.padding(5) |
|
|
|
|
|
|
|
.into(), |
|
|
|
|
|
|
|
]).max_width(250).align_items(Align::Center)) |
|
|
|
|
|
|
|
.align_x(Align::Center) |
|
|
|
|
|
|
|
.padding(40) |
|
|
|
|
|
|
|
.style(style::Container::Field), |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
.push( |
|
|
|
|
|
|
|
Button::new(profile_done_button_state, Text::new("Done")) |
|
|
|
|
|
|
|
.style(style::Button::Primary) |
|
|
|
|
|
|
|
.on_press(GuiEvent::ChangeScreen(AppScreen::Main)), |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
.align_x(Align::Center) |
|
|
|
|
|
|
|
.into() |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
impl Application for DegeonApp { |
|
|
|
impl Application for DegeonApp { |
|
|
@ -155,15 +198,20 @@ impl Application for DegeonApp { |
|
|
|
fn new(_: ()) -> (Self, iced::Command<GuiEvent>) { |
|
|
|
fn new(_: ()) -> (Self, iced::Command<GuiEvent>) { |
|
|
|
let mut data = Degeon::restore_from_file("".to_string()).unwrap(); |
|
|
|
let mut data = Degeon::restore_from_file("".to_string()).unwrap(); |
|
|
|
data.chats = vec![Chat::example(1, &data.keys), Chat::example(2, &data.keys)]; |
|
|
|
data.chats = vec![Chat::example(1, &data.keys), Chat::example(2, &data.keys)]; |
|
|
|
data.profile.name = "John".to_string(); |
|
|
|
|
|
|
|
data.send_multicast(ProtocolMsg::Ping).unwrap(); |
|
|
|
data.send_multicast(ProtocolMsg::Ping).unwrap(); |
|
|
|
let st = DegeonApp { |
|
|
|
let st = DegeonApp { |
|
|
|
|
|
|
|
screen: if data.profile.name.is_empty() { |
|
|
|
|
|
|
|
AppScreen::ProfileEditor |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
AppScreen::Main |
|
|
|
|
|
|
|
}, |
|
|
|
data, |
|
|
|
data, |
|
|
|
screen: Default::default(), |
|
|
|
|
|
|
|
selected_chat: 0, |
|
|
|
selected_chat: 0, |
|
|
|
send_button_state: Default::default(), |
|
|
|
send_button_state: Default::default(), |
|
|
|
text_input_state: Default::default(), |
|
|
|
text_input_state: Default::default(), |
|
|
|
preview_button_states: vec![Default::default(), Default::default()], |
|
|
|
preview_button_states: vec![Default::default(), Default::default()], |
|
|
|
|
|
|
|
name_input_state: Default::default(), |
|
|
|
|
|
|
|
profile_done_button_state: Default::default(), |
|
|
|
}; |
|
|
|
}; |
|
|
|
let data_clone = st.data.clone(); |
|
|
|
let data_clone = st.data.clone(); |
|
|
|
std::thread::spawn(move || { |
|
|
|
std::thread::spawn(move || { |
|
|
@ -229,7 +277,11 @@ impl Application for DegeonApp { |
|
|
|
&target, |
|
|
|
&target, |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
GuiEvent::ChangeScreen(sc) => self.screen = sc, |
|
|
|
GuiEvent::ChangeScreen(sc) => { |
|
|
|
|
|
|
|
self.screen = sc; |
|
|
|
|
|
|
|
self.data.save_to_file("".to_string()).unwrap(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
GuiEvent::ChangeName(name) => self.data.profile.name = name, |
|
|
|
} |
|
|
|
} |
|
|
|
iced::Command::none() |
|
|
|
iced::Command::none() |
|
|
|
} |
|
|
|
} |
|
|
@ -241,7 +293,7 @@ impl Application for DegeonApp { |
|
|
|
fn view(&mut self) -> Element<'_, Self::Message> { |
|
|
|
fn view(&mut self) -> Element<'_, Self::Message> { |
|
|
|
match self.screen { |
|
|
|
match self.screen { |
|
|
|
AppScreen::Main => self.main_view(), |
|
|
|
AppScreen::Main => self.main_view(), |
|
|
|
AppScreen::ProfileEditor => todo!(), |
|
|
|
AppScreen::ProfileEditor => self.profile_editor(), |
|
|
|
AppScreen::PeerInput => todo!(), |
|
|
|
AppScreen::PeerInput => todo!(), |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|