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. 87
      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"
checksum = "a13739d7177fbd22bb0ed28badfff9f372f8bef46c863db4e1c6248f6b223b6e"
[[package]]
name = "adler32"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aae1277d39aeec15cb388266ecc24b11c80469deae6067e17a1a7aa9e5c1f234"
[[package]]
name = "ahash"
version = "0.4.7"
@ -37,12 +43,6 @@ dependencies = [
"xml-rs",
]
[[package]]
name = "android_glue"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "000444226fcff248f2bc4c7625be32c63caccfecc2723a2b9f78a7487a49c407"
[[package]]
name = "approx"
version = "0.5.0"
@ -220,15 +220,6 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e"
[[package]]
name = "cgl"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ced0551234e87afee12411d535648dd89d2e7f34c78b753395567aff3d447ff"
dependencies = [
"libc",
]
[[package]]
name = "chrono"
version = "0.4.19"
@ -292,22 +283,6 @@ dependencies = [
"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]]
name = "cocoa"
version = "0.24.0"
@ -339,6 +314,12 @@ dependencies = [
"objc",
]
[[package]]
name = "color_quant"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b"
[[package]]
name = "const-oid"
version = "0.6.2"
@ -454,6 +435,15 @@ dependencies = [
"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]]
name = "crossbeam-channel"
version = "0.5.1"
@ -561,6 +551,16 @@ dependencies = [
"syn",
]
[[package]]
name = "deflate"
version = "0.8.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73770f8e1fe7d64df17ca66ad28994a0a623ea497fa69486e14984e715c5d174"
dependencies = [
"adler32",
"byteorder",
]
[[package]]
name = "degeon"
version = "0.1.0"
@ -1101,7 +1101,7 @@ dependencies = [
"bitflags",
"gfx-auxil",
"gfx-hal",
"glow 0.7.2",
"glow",
"js-sys",
"khronos-egl",
"libloading 0.6.7",
@ -1173,14 +1173,13 @@ dependencies = [
]
[[package]]
name = "gl_generator"
version = "0.14.0"
name = "gif"
version = "0.11.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a95dfc23a2b4a9a2f5ab41d194f8bfda3cabec42af4e39f08c339eb2a0c124d"
checksum = "c3a7187e78088aead22ceedeee99779455b23fc231fe13ec443f99bb71694e5b"
dependencies = [
"khronos_api",
"log",
"xml-rs",
"color_quant",
"weezl",
]
[[package]]
@ -1192,18 +1191,6 @@ dependencies = [
"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]]
name = "glow"
version = "0.7.2"
@ -1216,90 +1203,6 @@ dependencies = [
"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]]
name = "glyph_brush"
version = "0.7.3"
@ -1428,8 +1331,6 @@ checksum = "05279cf5a83b960a1a01cff455fede8a33df720f3ff4fc9d33be79fcea9d2466"
dependencies = [
"iced_core",
"iced_futures",
"iced_glow",
"iced_glutin",
"iced_web",
"iced_wgpu",
"iced_winit",
@ -1453,34 +1354,6 @@ dependencies = [
"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]]
name = "iced_graphics"
version = "0.2.0"
@ -1547,6 +1420,7 @@ dependencies = [
"guillotiere",
"iced_graphics",
"iced_native",
"image",
"log",
"raw-window-handle 0.3.4",
"wgpu",
@ -1586,6 +1460,23 @@ dependencies = [
"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]]
name = "include_optional"
version = "1.0.1"
@ -1696,6 +1587,15 @@ dependencies = [
"libc",
]
[[package]]
name = "jpeg-decoder"
version = "0.1.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "229d53d58899083193af11e15917b5640cd40b29ff475a1fe4ef725deb02d0f2"
dependencies = [
"rayon",
]
[[package]]
name = "js-sys"
version = "0.3.46"
@ -1725,12 +1625,6 @@ dependencies = [
"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]]
name = "lazy_static"
version = "1.4.0"
@ -1876,6 +1770,15 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
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]]
name = "mio"
version = "0.6.23"
@ -2080,6 +1983,17 @@ dependencies = [
"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]]
name = "num-traits"
version = "0.2.14"
@ -2182,15 +2096,6 @@ dependencies = [
"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]]
name = "owned_ttf_parser"
version = "0.6.0"
@ -2348,6 +2253,18 @@ version = "0.3.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
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]]
name = "ppv-lite86"
version = "0.2.15"
@ -2728,16 +2645,6 @@ dependencies = [
"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]]
name = "slab"
version = "0.4.5"
@ -3256,16 +3163,6 @@ dependencies = [
"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]]
name = "wayland-protocols"
version = "0.28.6"
@ -3344,6 +3241,12 @@ dependencies = [
"wasm-bindgen",
]
[[package]]
name = "weezl"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8b77fdfd5a253be4ab714e4ffa3c49caf146b4de743e97510c0656cf90f1e8e"
[[package]]
name = "wgpu"
version = "0.7.1"
@ -3487,7 +3390,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da4eda6fce0eb84bd0a33e3c8794eb902e1033d0a1d5a31bc4f19b1b4bbff597"
dependencies = [
"bitflags",
"cocoa 0.24.0",
"cocoa",
"core-foundation 0.9.2",
"core-graphics 0.22.3",
"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
[dependencies]
iced = { version = "0.3.0", features = ["glow"] }
ironforce = { path = "../ironforce", features = ["std", "image"] }
iced = { version = "0.3.0", features = ["image"] }
ironforce = { path = "../ironforce", features = ["std"] }
degeon_core = { path = "../degeon_core" }
base64 = "0.13.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;
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)?)
}

87
degeon/src/state.rs

@ -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,10 +74,23 @@ 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::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()
@ -85,7 +101,8 @@ impl DegeonApp {
)
.padding(20)
.spacing(10)
.align_items(Align::Start)
.align_items(Align::Start),
)
.width(Length::FillPortion(1))
.into()
}
@ -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![
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))
])
.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");

2
degeon_core/Cargo.toml

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

4
degeon_core/src/chat.rs

@ -28,7 +28,7 @@ impl Chat {
Self {
pkey,
messages: vec![],
profile: Profile { name: "".to_string() },
profile: Profile { name: "".to_string(), bio: "".to_string() },
scrolled: 0.0,
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,
pkey,
input: "".to_string(),

32
degeon_core/src/degeon_worker.rs

@ -152,7 +152,35 @@ impl Degeon {
target: &PublicKey,
) -> iced::Command<GuiEvent> {
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();
println!("Creating a send command: {:?}", msg);
@ -165,8 +193,6 @@ impl Degeon {
Message::build()
.message_type(MessageType::Broadcast)
.content(serde_json::to_vec(&msg).unwrap())
// todo:
// .recipient(&target)
.sign(&keys)
.build()
.unwrap(),

4
degeon_core/src/gui_events.rs

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

Loading…
Cancel
Save