|
|
|
@ -1,16 +1,16 @@
|
|
|
|
|
use crate::chat::Chat; |
|
|
|
|
use crate::chat::RenderableChat; |
|
|
|
|
use crate::degeon_worker::{Degeon, DegeonContainer}; |
|
|
|
|
use crate::gui_events::GuiEvent; |
|
|
|
|
use crate::message::{DegMessage, DegMessageContent, ProtocolMsg}; |
|
|
|
|
use crate::styles::style; |
|
|
|
|
use core::default::Default; |
|
|
|
|
use degeon_core::AppScreen; |
|
|
|
|
use iced::{ |
|
|
|
|
button, Align, Application, Button, Column, Element, HorizontalAlignment, Length, Row, |
|
|
|
|
Text, TextInput, VerticalAlignment, |
|
|
|
|
button, Align, Application, Button, Column, Element, HorizontalAlignment, Length, Row, Text, |
|
|
|
|
TextInput, VerticalAlignment, |
|
|
|
|
}; |
|
|
|
|
use ironforce::PublicKey; |
|
|
|
|
use degeon_core::AppScreen; |
|
|
|
|
use crate::chat::RenderableChat; |
|
|
|
|
|
|
|
|
|
/// Render a message into an iced `Element`
|
|
|
|
|
pub fn view_message(msg: &DegMessage, pkey: PublicKey) -> Option<Element<GuiEvent>> { |
|
|
|
@ -41,7 +41,6 @@ pub fn view_message(msg: &DegMessage, pkey: PublicKey) -> Option<Element<GuiEven
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// The main application struct (for iced)
|
|
|
|
|
#[derive(Default)] |
|
|
|
|
pub struct DegeonApp { |
|
|
|
@ -59,10 +58,14 @@ pub struct DegeonApp {
|
|
|
|
|
preview_button_states: Vec<button::State>, |
|
|
|
|
/// Name input on profile screen
|
|
|
|
|
name_input_state: iced::text_input::State, |
|
|
|
|
/// Bio input on profile screen
|
|
|
|
|
bio_input_state: iced::text_input::State, |
|
|
|
|
/// Button on the profile screen
|
|
|
|
|
profile_done_button_state: iced::button::State, |
|
|
|
|
/// Scroll state
|
|
|
|
|
scroll: iced::scrollable::State, |
|
|
|
|
/// The button at the left-upper corner of the screen
|
|
|
|
|
profile_logo_state: iced::button::State, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl DegeonApp { |
|
|
|
@ -71,23 +74,37 @@ impl DegeonApp {
|
|
|
|
|
chats: &'a [Chat], |
|
|
|
|
preview_button_states: &'a mut Vec<button::State>, |
|
|
|
|
selected: usize, |
|
|
|
|
profile_logo_state: &'a mut button::State, |
|
|
|
|
) -> Element<'a, GuiEvent> { |
|
|
|
|
while preview_button_states.len() < chats.len() { |
|
|
|
|
preview_button_states.push(Default::default()) |
|
|
|
|
} |
|
|
|
|
Column::with_children( |
|
|
|
|
chats |
|
|
|
|
.iter() |
|
|
|
|
.zip(preview_button_states.iter_mut()) |
|
|
|
|
.enumerate() |
|
|
|
|
.map(|(i, (chat, state))| chat.preview(state, i, i == selected)) |
|
|
|
|
.collect(), |
|
|
|
|
) |
|
|
|
|
.padding(20) |
|
|
|
|
.spacing(10) |
|
|
|
|
.align_items(Align::Start) |
|
|
|
|
.width(Length::FillPortion(1)) |
|
|
|
|
.into() |
|
|
|
|
Column::new() |
|
|
|
|
.push( |
|
|
|
|
iced::Button::new( |
|
|
|
|
profile_logo_state, |
|
|
|
|
iced::Container::new(iced::Image::new(iced::image::Handle::from_memory( |
|
|
|
|
include_bytes!("profile_logo.png").to_vec(), |
|
|
|
|
))) |
|
|
|
|
.width(Length::Units(25)), |
|
|
|
|
) |
|
|
|
|
.on_press(GuiEvent::ChangeScreen(AppScreen::ProfileEditor)), |
|
|
|
|
) |
|
|
|
|
.push( |
|
|
|
|
Column::with_children( |
|
|
|
|
chats |
|
|
|
|
.iter() |
|
|
|
|
.zip(preview_button_states.iter_mut()) |
|
|
|
|
.enumerate() |
|
|
|
|
.map(|(i, (chat, state))| chat.preview(state, i, i == selected)) |
|
|
|
|
.collect(), |
|
|
|
|
) |
|
|
|
|
.padding(20) |
|
|
|
|
.spacing(10) |
|
|
|
|
.align_items(Align::Start), |
|
|
|
|
) |
|
|
|
|
.width(Length::FillPortion(1)) |
|
|
|
|
.into() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Render active chat section
|
|
|
|
@ -119,6 +136,7 @@ impl DegeonApp {
|
|
|
|
|
text_input_state, |
|
|
|
|
preview_button_states, |
|
|
|
|
scroll: scroll_state, |
|
|
|
|
profile_logo_state, |
|
|
|
|
.. |
|
|
|
|
} = self; |
|
|
|
|
Row::new() |
|
|
|
@ -127,6 +145,7 @@ impl DegeonApp {
|
|
|
|
|
chats, |
|
|
|
|
preview_button_states, |
|
|
|
|
*selected_chat, |
|
|
|
|
profile_logo_state, |
|
|
|
|
)) |
|
|
|
|
.push(Self::active_chat( |
|
|
|
|
chats, |
|
|
|
@ -143,11 +162,12 @@ impl DegeonApp {
|
|
|
|
|
let Self { |
|
|
|
|
data: |
|
|
|
|
Degeon { |
|
|
|
|
profile: crate::message::Profile { name }, |
|
|
|
|
profile: crate::message::Profile { name, bio }, |
|
|
|
|
.. |
|
|
|
|
}, |
|
|
|
|
profile_done_button_state, |
|
|
|
|
name_input_state, |
|
|
|
|
bio_input_state, |
|
|
|
|
.. |
|
|
|
|
} = self; |
|
|
|
|
iced::Container::new( |
|
|
|
@ -155,16 +175,42 @@ impl DegeonApp {
|
|
|
|
|
.align_items(Align::Center) |
|
|
|
|
.width(Length::Fill) |
|
|
|
|
.spacing(60) |
|
|
|
|
.push(Text::new("Profile")) |
|
|
|
|
.padding(40) |
|
|
|
|
.push(Text::new("Profile").size(40)) |
|
|
|
|
// Name input
|
|
|
|
|
.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)) |
|
|
|
|
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(), |
|
|
|
|
]) |
|
|
|
|
.spacing(10) |
|
|
|
|
.max_width(250) |
|
|
|
|
.align_items(Align::Center), |
|
|
|
|
) |
|
|
|
|
.align_x(Align::Center) |
|
|
|
|
.padding(40) |
|
|
|
|
.style(style::Container::Field), |
|
|
|
|
) |
|
|
|
|
// Bio input
|
|
|
|
|
.push( |
|
|
|
|
iced::Container::new( |
|
|
|
|
Row::with_children(vec![ |
|
|
|
|
Text::new("Bio").into(), |
|
|
|
|
TextInput::new(bio_input_state, "Bio", bio.as_str(), |bio| { |
|
|
|
|
GuiEvent::ChangeBio(bio) |
|
|
|
|
}) |
|
|
|
|
.padding(5) |
|
|
|
|
.into(), |
|
|
|
|
]) |
|
|
|
|
.spacing(10) |
|
|
|
|
.max_width(250) |
|
|
|
|
.align_items(Align::Center), |
|
|
|
|
) |
|
|
|
|
.align_x(Align::Center) |
|
|
|
|
.padding(40) |
|
|
|
|
.style(style::Container::Field), |
|
|
|
@ -176,6 +222,7 @@ impl DegeonApp {
|
|
|
|
|
), |
|
|
|
|
) |
|
|
|
|
.align_x(Align::Center) |
|
|
|
|
.width(Length::Fill) |
|
|
|
|
.into() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -192,7 +239,11 @@ impl Application for DegeonApp {
|
|
|
|
|
} |
|
|
|
|
data.send_multicast(ProtocolMsg::Ping).unwrap(); |
|
|
|
|
let mut scroll: iced::scrollable::State = Default::default(); |
|
|
|
|
scroll.scroll_to(1., iced::Rectangle::with_size(iced::Size::ZERO), iced::Rectangle::with_size(iced::Size::UNIT)); |
|
|
|
|
scroll.scroll_to( |
|
|
|
|
1., |
|
|
|
|
iced::Rectangle::with_size(iced::Size::ZERO), |
|
|
|
|
iced::Rectangle::with_size(iced::Size::UNIT), |
|
|
|
|
); |
|
|
|
|
let st = DegeonApp { |
|
|
|
|
screen: if data.profile.name.is_empty() { |
|
|
|
|
AppScreen::ProfileEditor |
|
|
|
@ -205,8 +256,10 @@ impl Application for DegeonApp {
|
|
|
|
|
text_input_state: Default::default(), |
|
|
|
|
preview_button_states: vec![Default::default(), Default::default()], |
|
|
|
|
name_input_state: Default::default(), |
|
|
|
|
bio_input_state: Default::default(), |
|
|
|
|
profile_done_button_state: Default::default(), |
|
|
|
|
scroll, |
|
|
|
|
profile_logo_state: Default::default(), |
|
|
|
|
}; |
|
|
|
|
(st, iced::Command::none()) |
|
|
|
|
} |
|
|
|
@ -246,16 +299,18 @@ impl Application for DegeonApp {
|
|
|
|
|
self.screen = sc; |
|
|
|
|
self.data.save_to_file("".to_string()).unwrap(); |
|
|
|
|
if prev_screen == AppScreen::ProfileEditor { |
|
|
|
|
return self.data.get_send_command( |
|
|
|
|
ProtocolMsg::ProfileResponse(self.data.get_profile()), |
|
|
|
|
&target, |
|
|
|
|
); |
|
|
|
|
return self |
|
|
|
|
.data |
|
|
|
|
.get_broadcast_send_command(ProtocolMsg::ProfileResponse( |
|
|
|
|
self.data.get_profile(), |
|
|
|
|
)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
GuiEvent::ChangeName(name) => self.data.profile.name = name, |
|
|
|
|
GuiEvent::ChangeBio(bio) => self.data.profile.bio = bio, |
|
|
|
|
// The following events are already handled in Degeon::process_event
|
|
|
|
|
GuiEvent::NewMessageInChat(_pkey, _msg) => {} |
|
|
|
|
GuiEvent::SetProfile(_pkey, _profile) => { } |
|
|
|
|
GuiEvent::SetProfile(_pkey, _profile) => {} |
|
|
|
|
GuiEvent::None => {} |
|
|
|
|
GuiEvent::WeHaveToSendProfile(target) => { |
|
|
|
|
println!("WHTSP"); |
|
|
|
|