From 089ed08c16f6df9b57519c6a6b3efa0a97a82515 Mon Sep 17 00:00:00 2001 From: Shadow Cat Date: Sun, 7 Dec 2025 15:18:39 -0500 Subject: [PATCH] switch to WidgetRef --- iris | 2 +- src/bin/client/main.rs | 14 +++++++------- src/bin/client/state.rs | 2 +- src/bin/client/ui/login.rs | 28 ++++++++++++++-------------- src/bin/client/ui/main.rs | 6 +++--- src/bin/client/ui/misc.rs | 12 ++++++------ 6 files changed, 32 insertions(+), 32 deletions(-) diff --git a/iris b/iris index 38266de..b66d4da 160000 --- a/iris +++ b/iris @@ -1 +1 @@ -Subproject commit 38266debb6e3b5a9b6dbd75da8293cca34b9d7db +Subproject commit b66d4da5d7dfc7ac3ca8e0cd0fc4e1a5b0322f04 diff --git a/src/bin/client/main.rs b/src/bin/client/main.rs index 1766a85..44b230f 100644 --- a/src/bin/client/main.rs +++ b/src/bin/client/main.rs @@ -32,8 +32,8 @@ pub struct Client { dir: DataDir, data: ClientData, state: ClientState, - main_ui: WidgetId, - notif: WidgetId, + main_ui: WidgetRef, + notif: WidgetRef, proxy: Proxy, } @@ -50,7 +50,7 @@ impl DefaultAppState for Client { WindowAttributes::default().with_title("OPENWORM") } - fn new(ui: &mut Ui, state: &UiState, proxy: Proxy) -> Self { + fn new(ui: &mut Ui, _state: &UiState, proxy: Proxy) -> Self { let dir = DataDir::default(); let notif = WidgetPtr::default().add(ui); let main_ui = WidgetPtr::default().add(ui); @@ -94,7 +94,7 @@ impl DefaultAppState for Client { && let Some(msg_area) = &state.channel { let msg = msg_widget(&msg.user, &msg.content).add(ui); - ui[msg_area].children.push(msg.any()); + msg_area.get_mut().children.push(msg.any()); } } ServerMsg::LoadMsgs(msgs) => { @@ -104,7 +104,7 @@ impl DefaultAppState for Client { for msg in msgs { state.msgs.push(msg.clone()); let msg = msg_widget(&msg.user, &msg.content).add(ui); - ui[msg_area].children.push(msg.any()); + msg_area.get_mut().children.push(msg.any()); } } } @@ -123,11 +123,11 @@ impl DefaultAppState for Client { } ServerMsg::Error(error) => { let msg = format!("{error:?}"); - ui[&self.notif].inner = Some(werror(ui, &msg)); + self.notif.get_mut().inner = Some(werror(ui, &msg)); } }, ClientEvent::Err(msg) => { - ui[&self.notif].inner = Some(werror(ui, &msg)); + self.notif.get_mut().inner = Some(werror(ui, &msg)); } } } diff --git a/src/bin/client/state.rs b/src/bin/client/state.rs index c5c5f97..58bc5ac 100644 --- a/src/bin/client/state.rs +++ b/src/bin/client/state.rs @@ -16,7 +16,7 @@ pub struct Login { pub struct LoggedIn { pub network: NetHandle, pub msgs: Vec, - pub channel: Option>, + pub channel: Option>, pub username: String, } diff --git a/src/bin/client/ui/login.rs b/src/bin/client/ui/login.rs index 7a3ca31..168e4c4 100644 --- a/src/bin/client/ui/login.rs +++ b/src/bin/client/ui/login.rs @@ -5,7 +5,7 @@ use crate::{net::AppHandle, state::ClientState}; use super::*; -pub fn start_screen(client: &mut Client, ui: &mut Ui) -> WidgetId { +pub fn start_screen(client: &mut Client, ui: &mut Ui) -> WidgetRef { let mut accounts = Span::empty(Dir::DOWN); accounts.push( @@ -38,7 +38,7 @@ pub fn start_screen(client: &mut Client, ui: &mut Ui) -> WidgetId { .any() } -pub fn connect_screen(client: &mut Client, ui: &mut Ui, state: &UiState) -> WidgetId { +pub fn connect_screen(client: &mut Client, ui: &mut Ui, state: &UiState) -> WidgetRef { let Client { data, proxy, .. } = client; let ip = field_widget(&data.ip, "ip", ui); let ip_ = ip.clone(); @@ -46,11 +46,11 @@ pub fn connect_screen(client: &mut Client, ui: &mut Ui, state: &UiState) -> Widg proxy: proxy.clone(), window: state.window.clone(), }; - let submit = submit_button("connect", move |client, ui| { + let submit = submit_button("connect", move |client, _ui| { let ClientState::Connect(state) = &mut client.state else { return; }; - let ip = ui[&ip_].content(); + let ip = ip_.get().content(); state.handle = Some(connect(handle.clone(), ConnectInfo { ip })); }); ( @@ -60,7 +60,7 @@ pub fn connect_screen(client: &mut Client, ui: &mut Ui, state: &UiState) -> Widg field_box( // NOTE: should probably do this on submit ip.on(Edited, |ctx| { - ctx.state.data.ip = ctx.ui[ctx.id].content(); + ctx.state.data.ip = ctx.widget.get().content(); }) .add(ui), ui, @@ -77,28 +77,28 @@ pub fn connect_screen(client: &mut Client, ui: &mut Ui, state: &UiState) -> Widg .any() } -pub fn login_screen(client: &mut Client, ui: &mut Ui) -> WidgetId { +pub fn login_screen(client: &mut Client, ui: &mut Ui) -> WidgetRef { let Client { data, .. } = client; let username = field_widget(&data.username, "username", ui); let password = field_widget(&data.password, "password", ui); let username_ = username.clone(); let password_ = password.clone(); - let submit = submit_button("login", move |client, ui| { + let submit = submit_button("login", move |client, _ui| { let ClientState::Login(state) = &mut client.state else { return; }; - let username = ui[&username_].content(); - let password = ui[&password_].content(); + let username = username_.get().content(); + let password = password_.get().content(); state.handle.send(ClientMsg::Login { username, password }); }); let username_ = username.clone(); let password_ = password.clone(); - let create_button = submit_button("create account", move |client, ui| { + let create_button = submit_button("create account", move |client, _ui| { let ClientState::Login(state) = &mut client.state else { return; }; - let username = ui[&username_].content(); - let password = ui[&password_].content(); + let username = username_.get().content(); + let password = password_.get().content(); state .handle .send(ClientMsg::CreateAccount { username, password }); @@ -108,7 +108,7 @@ pub fn login_screen(client: &mut Client, ui: &mut Ui) -> WidgetId { field_box( username .on(Edited, |ctx| { - ctx.state.data.username = ctx.ui[ctx.id].content(); + ctx.state.data.username = ctx.widget.get().content(); }) .add(ui), ui, @@ -116,7 +116,7 @@ pub fn login_screen(client: &mut Client, ui: &mut Ui) -> WidgetId { field_box( password .on(Edited, |ctx| { - ctx.state.data.password = ctx.ui[ctx.id].content(); + ctx.state.data.password = ctx.widget.get().content(); }) .add(ui), ui, diff --git a/src/bin/client/ui/main.rs b/src/bin/client/ui/main.rs index 4074c2e..c8505a2 100644 --- a/src/bin/client/ui/main.rs +++ b/src/bin/client/ui/main.rs @@ -11,7 +11,7 @@ use openworm::net::{ClientMsg, NetClientMsg}; pub const SIZE: u32 = 20; -pub fn main_view(client: &mut Client, ui: &mut Ui) -> WidgetId { +pub fn main_view(client: &mut Client, ui: &mut Ui) -> WidgetRef { let ClientState::LoggedIn(state) = &mut client.state else { panic!("we ain't logged in buh"); }; @@ -75,13 +75,13 @@ pub fn msg_panel(ui: &mut Ui, state: &mut LoggedIn) -> impl WidgetRet + use<> { let ClientState::LoggedIn(state) = &mut ctx.state.state else { panic!("we ain't logged in buh"); }; - let content = ctx.ui.text(ctx.id).take(); + let content = ctx.widget.get_mut().take(); let msg = NetClientMsg { content: content.clone(), }; state.network.send(ClientMsg::SendMsg(msg.clone())); let msg = msg_widget(&state.username, &content).add(ctx.ui); - ctx.ui[&msg_area].children.push(msg.any()); + msg_area.get_mut().children.push(msg.any()); }) .pad(15) .attr::(send_text) diff --git a/src/bin/client/ui/misc.rs b/src/bin/client/ui/misc.rs index e4545e0..ecd89a2 100644 --- a/src/bin/client/ui/misc.rs +++ b/src/bin/client/ui/misc.rs @@ -2,7 +2,7 @@ use iris::winit::attr::Selector; use super::*; -pub fn werror(ui: &mut Ui, msg: &str) -> WidgetId { +pub fn werror(ui: &mut Ui, msg: &str) -> WidgetRef { wtext(msg) .size(20) .pad(10) @@ -15,7 +15,7 @@ pub fn hint(msg: impl Into) -> TextBuilder { wtext(msg).size(20).color(Color::GRAY) } -pub fn field_widget(name: &str, hint_text: &str, ui: &mut Ui) -> WidgetId { +pub fn field_widget(name: &str, hint_text: &str, ui: &mut Ui) -> WidgetRef { wtext(name) .editable(true) .size(20) @@ -23,7 +23,7 @@ pub fn field_widget(name: &str, hint_text: &str, ui: &mut Ui) -> WidgetId, ui: &mut Ui) -> WidgetId { +pub fn field_box(field: WidgetRef, ui: &mut Ui) -> WidgetRef { field .clone() .pad(10) @@ -41,17 +41,17 @@ pub fn submit_button( rect(color) .radius(15) .on(CursorSense::click(), move |ctx| { - ctx.ui[ctx.id].color = color.darker(0.2); + ctx.widget.get_mut().color = color.darker(0.2); on_submit(ctx.state, ctx.ui); }) .on( CursorSense::HoverStart | CursorSense::unclick(), move |ctx| { - ctx.ui[ctx.id].color = color.brighter(0.1); + ctx.widget.get_mut().color = color.brighter(0.1); }, ) .on(CursorSense::HoverEnd, move |ctx| { - ctx.ui[ctx.id].color = color; + ctx.widget.get_mut().color = color; }) .height(60) .foreground(wtext(text).size(25).text_align(Align::CENTER))