Browse Source

Profile button

master v1
Lev 3 years ago
parent
commit
d9afc776c0
  1. 303
      Cargo.lock
  2. 4
      degeon/Cargo.toml
  3. BIN
      degeon/src/CRC35.otf
  4. 4
      degeon/src/main.rs
  5. 123
      degeon/src/state.rs
  6. 2
      degeon_core/Cargo.toml
  7. 4
      degeon_core/src/chat.rs
  8. 32
      degeon_core/src/degeon_worker.rs
  9. 4
      degeon_core/src/gui_events.rs

303
Cargo.lock generated

@ -18,6 +18,12 @@ version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a13739d7177fbd22bb0ed28badfff9f372f8bef46c863db4e1c6248f6b223b6e" checksum = "a13739d7177fbd22bb0ed28badfff9f372f8bef46c863db4e1c6248f6b223b6e"
[[package]]
name = "adler32"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aae1277d39aeec15cb388266ecc24b11c80469deae6067e17a1a7aa9e5c1f234"
[[package]] [[package]]
name = "ahash" name = "ahash"
version = "0.4.7" version = "0.4.7"
@ -37,12 +43,6 @@ dependencies = [
"xml-rs", "xml-rs",
] ]
[[package]]
name = "android_glue"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "000444226fcff248f2bc4c7625be32c63caccfecc2723a2b9f78a7487a49c407"
[[package]] [[package]]
name = "approx" name = "approx"
version = "0.5.0" version = "0.5.0"
@ -220,15 +220,6 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e"
[[package]]
name = "cgl"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ced0551234e87afee12411d535648dd89d2e7f34c78b753395567aff3d447ff"
dependencies = [
"libc",
]
[[package]] [[package]]
name = "chrono" name = "chrono"
version = "0.4.19" version = "0.4.19"
@ -292,22 +283,6 @@ dependencies = [
"cc", "cc",
] ]
[[package]]
name = "cocoa"
version = "0.23.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c54201c07dcf3a5ca33fececb8042aed767ee4bfd5a0235a8ceabcda956044b2"
dependencies = [
"bitflags",
"block",
"cocoa-foundation",
"core-foundation 0.9.2",
"core-graphics 0.22.3",
"foreign-types",
"libc",
"objc",
]
[[package]] [[package]]
name = "cocoa" name = "cocoa"
version = "0.24.0" version = "0.24.0"
@ -339,6 +314,12 @@ dependencies = [
"objc", "objc",
] ]
[[package]]
name = "color_quant"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b"
[[package]] [[package]]
name = "const-oid" name = "const-oid"
version = "0.6.2" version = "0.6.2"
@ -454,6 +435,15 @@ dependencies = [
"objc", "objc",
] ]
[[package]]
name = "crc32fast"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "738c290dfaea84fc1ca15ad9c168d083b05a714e1efddd8edaab678dc28d2836"
dependencies = [
"cfg-if 1.0.0",
]
[[package]] [[package]]
name = "crossbeam-channel" name = "crossbeam-channel"
version = "0.5.1" version = "0.5.1"
@ -561,6 +551,16 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "deflate"
version = "0.8.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73770f8e1fe7d64df17ca66ad28994a0a623ea497fa69486e14984e715c5d174"
dependencies = [
"adler32",
"byteorder",
]
[[package]] [[package]]
name = "degeon" name = "degeon"
version = "0.1.0" version = "0.1.0"
@ -1101,7 +1101,7 @@ dependencies = [
"bitflags", "bitflags",
"gfx-auxil", "gfx-auxil",
"gfx-hal", "gfx-hal",
"glow 0.7.2", "glow",
"js-sys", "js-sys",
"khronos-egl", "khronos-egl",
"libloading 0.6.7", "libloading 0.6.7",
@ -1173,14 +1173,13 @@ dependencies = [
] ]
[[package]] [[package]]
name = "gl_generator" name = "gif"
version = "0.14.0" version = "0.11.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a95dfc23a2b4a9a2f5ab41d194f8bfda3cabec42af4e39f08c339eb2a0c124d" checksum = "c3a7187e78088aead22ceedeee99779455b23fc231fe13ec443f99bb71694e5b"
dependencies = [ dependencies = [
"khronos_api", "color_quant",
"log", "weezl",
"xml-rs",
] ]
[[package]] [[package]]
@ -1192,18 +1191,6 @@ dependencies = [
"version_check", "version_check",
] ]
[[package]]
name = "glow"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1625b792e2f9267116dd41eb7d325e0ea2572ceba5069451906745e04f852f33"
dependencies = [
"js-sys",
"slotmap",
"wasm-bindgen",
"web-sys",
]
[[package]] [[package]]
name = "glow" name = "glow"
version = "0.7.2" version = "0.7.2"
@ -1216,90 +1203,6 @@ dependencies = [
"web-sys", "web-sys",
] ]
[[package]]
name = "glow_glyph"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0510450eb46dd2b8e3284b50b08bfd870f1ef93a55045f54d7376fbcb63b1cb"
dependencies = [
"bytemuck",
"glow 0.6.1",
"glyph_brush",
"log",
]
[[package]]
name = "glutin"
version = "0.26.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ae1cbb9176b9151c4ce03f012e3cd1c6c18c4be79edeaeb3d99f5d8085c5fa3"
dependencies = [
"android_glue",
"cgl",
"cocoa 0.23.0",
"core-foundation 0.9.2",
"glutin_egl_sys",
"glutin_emscripten_sys",
"glutin_gles2_sys",
"glutin_glx_sys",
"glutin_wgl_sys",
"lazy_static",
"libloading 0.6.7",
"log",
"objc",
"osmesa-sys",
"parking_lot",
"wayland-client 0.28.6",
"wayland-egl",
"winapi 0.3.9",
"winit",
]
[[package]]
name = "glutin_egl_sys"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2abb6aa55523480c4adc5a56bbaa249992e2dddb2fc63dc96e04a3355364c211"
dependencies = [
"gl_generator",
"winapi 0.3.9",
]
[[package]]
name = "glutin_emscripten_sys"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "80de4146df76e8a6c32b03007bc764ff3249dcaeb4f675d68a06caf1bac363f1"
[[package]]
name = "glutin_gles2_sys"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8094e708b730a7c8a1954f4f8a31880af00eb8a1c5b5bf85d28a0a3c6d69103"
dependencies = [
"gl_generator",
"objc",
]
[[package]]
name = "glutin_glx_sys"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7e393c8fc02b807459410429150e9c4faffdb312d59b8c038566173c81991351"
dependencies = [
"gl_generator",
"x11-dl",
]
[[package]]
name = "glutin_wgl_sys"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3da5951a1569dbab865c6f2a863efafff193a93caf05538d193e9e3816d21696"
dependencies = [
"gl_generator",
]
[[package]] [[package]]
name = "glyph_brush" name = "glyph_brush"
version = "0.7.3" version = "0.7.3"
@ -1428,8 +1331,6 @@ checksum = "05279cf5a83b960a1a01cff455fede8a33df720f3ff4fc9d33be79fcea9d2466"
dependencies = [ dependencies = [
"iced_core", "iced_core",
"iced_futures", "iced_futures",
"iced_glow",
"iced_glutin",
"iced_web", "iced_web",
"iced_wgpu", "iced_wgpu",
"iced_winit", "iced_winit",
@ -1453,34 +1354,6 @@ dependencies = [
"wasm-bindgen-futures", "wasm-bindgen-futures",
] ]
[[package]]
name = "iced_glow"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c860ee895d4092101a4e640c4acdf8a3bac04a02b86c20888da038c46a47912"
dependencies = [
"bytemuck",
"euclid",
"glow 0.6.1",
"glow_glyph",
"glyph_brush",
"iced_graphics",
"iced_native",
"log",
]
[[package]]
name = "iced_glutin"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3be8da44dd0e796276089dbc8462490bf73f3f45bc5c04c41024ed11d577eff3"
dependencies = [
"glutin",
"iced_graphics",
"iced_native",
"iced_winit",
]
[[package]] [[package]]
name = "iced_graphics" name = "iced_graphics"
version = "0.2.0" version = "0.2.0"
@ -1547,6 +1420,7 @@ dependencies = [
"guillotiere", "guillotiere",
"iced_graphics", "iced_graphics",
"iced_native", "iced_native",
"image",
"log", "log",
"raw-window-handle 0.3.4", "raw-window-handle 0.3.4",
"wgpu", "wgpu",
@ -1586,6 +1460,23 @@ dependencies = [
"unicode-normalization", "unicode-normalization",
] ]
[[package]]
name = "image"
version = "0.23.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24ffcb7e7244a9bf19d35bf2883b9c080c4ced3c07a9895572178cdb8f13f6a1"
dependencies = [
"bytemuck",
"byteorder",
"color_quant",
"gif",
"jpeg-decoder",
"num-iter",
"num-rational",
"num-traits",
"png",
]
[[package]] [[package]]
name = "include_optional" name = "include_optional"
version = "1.0.1" version = "1.0.1"
@ -1696,6 +1587,15 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "jpeg-decoder"
version = "0.1.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "229d53d58899083193af11e15917b5640cd40b29ff475a1fe4ef725deb02d0f2"
dependencies = [
"rayon",
]
[[package]] [[package]]
name = "js-sys" name = "js-sys"
version = "0.3.46" version = "0.3.46"
@ -1725,12 +1625,6 @@ dependencies = [
"libloading 0.6.7", "libloading 0.6.7",
] ]
[[package]]
name = "khronos_api"
version = "3.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2db585e1d738fc771bf08a151420d3ed193d9d895a36df7f6f8a9456b911ddc"
[[package]] [[package]]
name = "lazy_static" name = "lazy_static"
version = "1.4.0" version = "1.4.0"
@ -1876,6 +1770,15 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
[[package]]
name = "miniz_oxide"
version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "791daaae1ed6889560f8c4359194f56648355540573244a5448a83ba1ecc7435"
dependencies = [
"adler32",
]
[[package]] [[package]]
name = "mio" name = "mio"
version = "0.6.23" version = "0.6.23"
@ -2080,6 +1983,17 @@ dependencies = [
"num-traits", "num-traits",
] ]
[[package]]
name = "num-rational"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "12ac428b1cb17fce6f731001d307d351ec70a6d202fc2e60f7d4c5e42d8f4f07"
dependencies = [
"autocfg 1.0.1",
"num-integer",
"num-traits",
]
[[package]] [[package]]
name = "num-traits" name = "num-traits"
version = "0.2.14" version = "0.2.14"
@ -2182,15 +2096,6 @@ dependencies = [
"num-traits", "num-traits",
] ]
[[package]]
name = "osmesa-sys"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "88cfece6e95d2e717e0872a7f53a8684712ad13822a7979bc760b9c77ec0013b"
dependencies = [
"shared_library",
]
[[package]] [[package]]
name = "owned_ttf_parser" name = "owned_ttf_parser"
version = "0.6.0" version = "0.6.0"
@ -2348,6 +2253,18 @@ version = "0.3.24"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "58893f751c9b0412871a09abd62ecd2a00298c6c83befa223ef98c52aef40cbe" checksum = "58893f751c9b0412871a09abd62ecd2a00298c6c83befa223ef98c52aef40cbe"
[[package]]
name = "png"
version = "0.16.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c3287920cb847dee3de33d301c463fba14dda99db24214ddf93f83d3021f4c6"
dependencies = [
"bitflags",
"crc32fast",
"deflate",
"miniz_oxide",
]
[[package]] [[package]]
name = "ppv-lite86" name = "ppv-lite86"
version = "0.2.15" version = "0.2.15"
@ -2728,16 +2645,6 @@ dependencies = [
"opaque-debug", "opaque-debug",
] ]
[[package]]
name = "shared_library"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a9e7e0f2bfae24d8a5b5a66c5b257a83c7412304311512a0c054cd5e619da11"
dependencies = [
"lazy_static",
"libc",
]
[[package]] [[package]]
name = "slab" name = "slab"
version = "0.4.5" version = "0.4.5"
@ -3256,16 +3163,6 @@ dependencies = [
"xcursor", "xcursor",
] ]
[[package]]
name = "wayland-egl"
version = "0.28.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99ba1ab1e18756b23982d36f08856d521d7df45015f404a2d7c4f0b2d2f66956"
dependencies = [
"wayland-client 0.28.6",
"wayland-sys 0.28.6",
]
[[package]] [[package]]
name = "wayland-protocols" name = "wayland-protocols"
version = "0.28.6" version = "0.28.6"
@ -3344,6 +3241,12 @@ dependencies = [
"wasm-bindgen", "wasm-bindgen",
] ]
[[package]]
name = "weezl"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8b77fdfd5a253be4ab714e4ffa3c49caf146b4de743e97510c0656cf90f1e8e"
[[package]] [[package]]
name = "wgpu" name = "wgpu"
version = "0.7.1" version = "0.7.1"
@ -3487,7 +3390,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da4eda6fce0eb84bd0a33e3c8794eb902e1033d0a1d5a31bc4f19b1b4bbff597" checksum = "da4eda6fce0eb84bd0a33e3c8794eb902e1033d0a1d5a31bc4f19b1b4bbff597"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"cocoa 0.24.0", "cocoa",
"core-foundation 0.9.2", "core-foundation 0.9.2",
"core-graphics 0.22.3", "core-graphics 0.22.3",
"core-video-sys", "core-video-sys",

4
degeon/Cargo.toml

@ -6,8 +6,8 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
iced = { version = "0.3.0", features = ["glow"] } iced = { version = "0.3.0", features = ["image"] }
ironforce = { path = "../ironforce", features = ["std", "image"] } ironforce = { path = "../ironforce", features = ["std"] }
degeon_core = { path = "../degeon_core" } degeon_core = { path = "../degeon_core" }
base64 = "0.13.0" base64 = "0.13.0"
serde = { version = "1.0" } serde = { version = "1.0" }

BIN
degeon/src/CRC35.otf

Binary file not shown.

4
degeon/src/main.rs

@ -10,5 +10,7 @@ use iced::Application;
use crate::state::DegeonApp; use crate::state::DegeonApp;
fn main() -> Result<(), Box<dyn std::error::Error>> { fn main() -> Result<(), Box<dyn std::error::Error>> {
Ok(DegeonApp::run(iced::Settings::default())?) let mut settings = iced::Settings::default();
settings.default_font = Some(include_bytes!("CRC35.otf"));
Ok(DegeonApp::run(settings)?)
} }

123
degeon/src/state.rs

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

2
degeon_core/Cargo.toml

@ -12,7 +12,7 @@ serde = { version = "1.0" }
serde_json = "1.0.72" serde_json = "1.0.72"
futures = "0.3.18" futures = "0.3.18"
chrono = "0.4.19" chrono = "0.4.19"
iced = { version = "0.3.0", features = ["glow"] } iced = { version = "0.3.0" }
rand = "0.8.4" rand = "0.8.4"
[dependencies.pyo3] [dependencies.pyo3]

4
degeon_core/src/chat.rs

@ -28,7 +28,7 @@ impl Chat {
Self { Self {
pkey, pkey,
messages: vec![], messages: vec![],
profile: Profile { name: "".to_string() }, profile: Profile { name: "".to_string(), bio: "".to_string() },
scrolled: 0.0, scrolled: 0.0,
input: "".to_string(), input: "".to_string(),
} }
@ -51,7 +51,7 @@ impl Chat {
}, },
], ],
profile: Profile { name: format!("Example user ({})", i) }, profile: Profile { name: format!("Example user ({})", i), bio: "".to_string() },
scrolled: 0.0, scrolled: 0.0,
pkey, pkey,
input: "".to_string(), input: "".to_string(),

32
degeon_core/src/degeon_worker.rs

@ -152,7 +152,35 @@ impl Degeon {
target: &PublicKey, target: &PublicKey,
) -> iced::Command<GuiEvent> { ) -> iced::Command<GuiEvent> {
let if_clone = self.ironforce.clone(); let if_clone = self.ironforce.clone();
let _target = target.clone(); let target = target.clone();
let keys = self.keys.clone();
println!("Creating a send command: {:?}", msg);
iced::Command::perform(async {}, move |_| {
println!("Sending message: {:?}", msg);
if_clone
.lock()
.unwrap()
.send_to_all(
Message::build()
.message_type(MessageType::Broadcast)
.content(serde_json::to_vec(&msg).unwrap())
.recipient(&target)
.sign(&keys)
.build()
.unwrap(),
)
.unwrap();
GuiEvent::None
})
}
/// Created an iced command that sends a message to everybody
pub fn get_broadcast_send_command(
&self,
msg: ProtocolMsg,
) -> iced::Command<GuiEvent> {
let if_clone = self.ironforce.clone();
let keys = self.keys.clone(); let keys = self.keys.clone();
println!("Creating a send command: {:?}", msg); println!("Creating a send command: {:?}", msg);
@ -165,8 +193,6 @@ impl Degeon {
Message::build() Message::build()
.message_type(MessageType::Broadcast) .message_type(MessageType::Broadcast)
.content(serde_json::to_vec(&msg).unwrap()) .content(serde_json::to_vec(&msg).unwrap())
// todo:
// .recipient(&target)
.sign(&keys) .sign(&keys)
.build() .build()
.unwrap(), .unwrap(),

4
degeon_core/src/gui_events.rs

@ -4,7 +4,7 @@ use serde::{Serialize, Deserialize};
/// The screens (pages) of the app /// The screens (pages) of the app
#[derive(Copy, Clone, Debug, Serialize, Deserialize)] #[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq)]
pub enum AppScreen { pub enum AppScreen {
/// The one with the chats /// The one with the chats
Main, Main,
@ -41,6 +41,8 @@ pub enum GuiEvent {
ChangeScreen(AppScreen), ChangeScreen(AppScreen),
/// Changed the name in the field on profile screen /// Changed the name in the field on profile screen
ChangeName(String), ChangeName(String),
/// Changed the bio in the field on profile screen
ChangeBio(String),
/// Nothing happened /// Nothing happened
None, None,
} }

Loading…
Cancel
Save