add client data cache for ip and username

This commit is contained in:
2025-11-17 17:57:41 -05:00
parent 510fafac9f
commit b3c833c667
8 changed files with 153 additions and 24 deletions
+29 -10
View File
@@ -2,7 +2,7 @@ use iris::prelude::*;
use len_fns::*;
use crate::{
client::{Client, app::AppHandle},
client::Client,
net::{
ClientMsg, Msg,
client::{ConnectInfo, NetSender, connect},
@@ -12,14 +12,19 @@ use crate::{
#[derive(Eq, PartialEq, Hash, Clone)]
pub struct Submit;
#[derive(Eq, PartialEq, Hash, Clone)]
pub struct Edited;
impl DefaultEvent for Submit {
type Data = ();
}
pub fn ui(handle: AppHandle) -> Ui {
let mut ui = Ui::new();
login_screen(&mut ui, handle).set_root(&mut ui);
ui
impl DefaultEvent for Edited {
type Data = ();
}
pub fn init(client: &mut Client) {
login_screen(client).set_root(&mut client.ui);
}
pub fn main_view(client: &mut Client, network: NetSender) -> WidgetId<AnyWidget> {
@@ -32,10 +37,14 @@ pub fn main_view(client: &mut Client, network: NetSender) -> WidgetId<AnyWidget>
.any()
}
fn login_screen(ui: &mut Ui, handle: AppHandle) -> WidgetId<AnyWidget> {
fn login_screen(client: &mut Client) -> WidgetId<AnyWidget> {
let Client {
ui, handle, data, ..
} = client;
let mut field = |name| text(name).editable().size(20).add(ui);
let ip = field("localhost:16839");
let username = field("username");
let ip = field(&data.ip);
let username = field(&data.username);
// let password = field("password");
let fbx = |field: WidgetId<TextEdit>| {
@@ -46,6 +55,8 @@ fn login_screen(ui: &mut Ui, handle: AppHandle) -> WidgetId<AnyWidget> {
.on(CursorSense::click(), focus(field))
};
// I LAV NOT HAVING ERGONOMIC CLONES
let handle = handle.clone();
let ip_ = ip.clone();
let username_ = username.clone();
let color = Color::GREEN;
@@ -60,8 +71,16 @@ fn login_screen(ui: &mut Ui, handle: AppHandle) -> WidgetId<AnyWidget> {
.height(40);
(
text("login").size(30),
fbx(ip),
fbx(username),
fbx(ip
.id_on(Edited, |id, client: &mut Client, _| {
client.data.ip = client.ui[id].content();
})
.add(ui)),
fbx(username
.id_on(Edited, |id, client: &mut Client, _| {
client.data.username = client.ui[id].content();
})
.add(ui)),
// fbx(password),
submit,
)