WORKING BASIC MSG SERVER

This commit is contained in:
2025-11-17 01:44:22 -05:00
parent 8a9e766633
commit 46a566ebd0
8 changed files with 265 additions and 115 deletions
+28 -6
View File
@@ -6,8 +6,8 @@ use render::Renderer;
use winit::{event::WindowEvent, event_loop::ActiveEventLoop};
use crate::{
client::ui::{Submit, main_view},
net::client::NetSender,
client::ui::{Submit, main_view, msg_widget},
net::{ClientMsg, ServerMsg, client::NetSender},
};
mod app;
@@ -17,9 +17,9 @@ mod ui;
pub use app::AppHandle;
#[derive(Debug)]
pub enum ClientEvent {
Connect(NetSender),
Connect { send: NetSender, username: String },
ServerMsg(ServerMsg),
}
pub struct Client {
@@ -27,6 +27,8 @@ pub struct Client {
input: Input,
ui: Ui,
focus: Option<WidgetId<TextEdit>>,
channel: Option<WidgetId<Span>>,
username: String,
clipboard: Clipboard,
}
@@ -40,16 +42,36 @@ impl Client {
renderer,
input: Input::default(),
ui,
channel: None,
focus: None,
username: "<unknown>".to_string(),
clipboard: Clipboard::new().unwrap(),
}
}
pub fn event(&mut self, event: ClientEvent, _: &ActiveEventLoop) {
match event {
ClientEvent::Connect(send) => {
main_view(&mut self.ui, send).set_root(&mut self.ui);
ClientEvent::Connect { send, username } => {
self.username = username;
send.send(ClientMsg::RequestMsgs);
main_view(self, send).set_root(&mut self.ui);
}
ClientEvent::ServerMsg(msg) => match msg {
ServerMsg::SendMsg(msg) => {
if let Some(msg_area) = &self.channel {
let msg = msg_widget(msg).add(&mut self.ui);
self.ui[msg_area].children.push(msg.any());
}
}
ServerMsg::LoadMsgs(msgs) => {
if let Some(msg_area) = &self.channel {
for msg in msgs {
let msg = msg_widget(msg).add(&mut self.ui);
self.ui[msg_area].children.push(msg.any());
}
}
}
},
}
}