switch to WidgetRef
This commit is contained in:
2
iris
2
iris
Submodule iris updated: 38266debb6...b66d4da5d7
@@ -32,8 +32,8 @@ pub struct Client {
|
|||||||
dir: DataDir,
|
dir: DataDir,
|
||||||
data: ClientData,
|
data: ClientData,
|
||||||
state: ClientState,
|
state: ClientState,
|
||||||
main_ui: WidgetId<WidgetPtr>,
|
main_ui: WidgetRef<WidgetPtr>,
|
||||||
notif: WidgetId<WidgetPtr>,
|
notif: WidgetRef<WidgetPtr>,
|
||||||
proxy: Proxy<ClientEvent>,
|
proxy: Proxy<ClientEvent>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,7 +50,7 @@ impl DefaultAppState for Client {
|
|||||||
WindowAttributes::default().with_title("OPENWORM")
|
WindowAttributes::default().with_title("OPENWORM")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new(ui: &mut Ui, state: &UiState, proxy: Proxy<Self::Event>) -> Self {
|
fn new(ui: &mut Ui, _state: &UiState, proxy: Proxy<Self::Event>) -> Self {
|
||||||
let dir = DataDir::default();
|
let dir = DataDir::default();
|
||||||
let notif = WidgetPtr::default().add(ui);
|
let notif = WidgetPtr::default().add(ui);
|
||||||
let main_ui = 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 Some(msg_area) = &state.channel
|
||||||
{
|
{
|
||||||
let msg = msg_widget(&msg.user, &msg.content).add(ui);
|
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) => {
|
ServerMsg::LoadMsgs(msgs) => {
|
||||||
@@ -104,7 +104,7 @@ impl DefaultAppState for Client {
|
|||||||
for msg in msgs {
|
for msg in msgs {
|
||||||
state.msgs.push(msg.clone());
|
state.msgs.push(msg.clone());
|
||||||
let msg = msg_widget(&msg.user, &msg.content).add(ui);
|
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) => {
|
ServerMsg::Error(error) => {
|
||||||
let msg = format!("{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) => {
|
ClientEvent::Err(msg) => {
|
||||||
ui[&self.notif].inner = Some(werror(ui, &msg));
|
self.notif.get_mut().inner = Some(werror(ui, &msg));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ pub struct Login {
|
|||||||
pub struct LoggedIn {
|
pub struct LoggedIn {
|
||||||
pub network: NetHandle,
|
pub network: NetHandle,
|
||||||
pub msgs: Vec<NetServerMsg>,
|
pub msgs: Vec<NetServerMsg>,
|
||||||
pub channel: Option<WidgetId<Span>>,
|
pub channel: Option<WidgetRef<Span>>,
|
||||||
pub username: String,
|
pub username: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use crate::{net::AppHandle, state::ClientState};
|
|||||||
|
|
||||||
use super::*;
|
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);
|
let mut accounts = Span::empty(Dir::DOWN);
|
||||||
|
|
||||||
accounts.push(
|
accounts.push(
|
||||||
@@ -38,7 +38,7 @@ pub fn start_screen(client: &mut Client, ui: &mut Ui) -> WidgetId {
|
|||||||
.any()
|
.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 Client { data, proxy, .. } = client;
|
||||||
let ip = field_widget(&data.ip, "ip", ui);
|
let ip = field_widget(&data.ip, "ip", ui);
|
||||||
let ip_ = ip.clone();
|
let ip_ = ip.clone();
|
||||||
@@ -46,11 +46,11 @@ pub fn connect_screen(client: &mut Client, ui: &mut Ui, state: &UiState) -> Widg
|
|||||||
proxy: proxy.clone(),
|
proxy: proxy.clone(),
|
||||||
window: state.window.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 {
|
let ClientState::Connect(state) = &mut client.state else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
let ip = ui[&ip_].content();
|
let ip = ip_.get().content();
|
||||||
state.handle = Some(connect(handle.clone(), ConnectInfo { ip }));
|
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(
|
field_box(
|
||||||
// NOTE: should probably do this on submit
|
// NOTE: should probably do this on submit
|
||||||
ip.on(Edited, |ctx| {
|
ip.on(Edited, |ctx| {
|
||||||
ctx.state.data.ip = ctx.ui[ctx.id].content();
|
ctx.state.data.ip = ctx.widget.get().content();
|
||||||
})
|
})
|
||||||
.add(ui),
|
.add(ui),
|
||||||
ui,
|
ui,
|
||||||
@@ -77,28 +77,28 @@ pub fn connect_screen(client: &mut Client, ui: &mut Ui, state: &UiState) -> Widg
|
|||||||
.any()
|
.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 Client { data, .. } = client;
|
||||||
let username = field_widget(&data.username, "username", ui);
|
let username = field_widget(&data.username, "username", ui);
|
||||||
let password = field_widget(&data.password, "password", ui);
|
let password = field_widget(&data.password, "password", ui);
|
||||||
let username_ = username.clone();
|
let username_ = username.clone();
|
||||||
let password_ = password.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 {
|
let ClientState::Login(state) = &mut client.state else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
let username = ui[&username_].content();
|
let username = username_.get().content();
|
||||||
let password = ui[&password_].content();
|
let password = password_.get().content();
|
||||||
state.handle.send(ClientMsg::Login { username, password });
|
state.handle.send(ClientMsg::Login { username, password });
|
||||||
});
|
});
|
||||||
let username_ = username.clone();
|
let username_ = username.clone();
|
||||||
let password_ = password.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 {
|
let ClientState::Login(state) = &mut client.state else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
let username = ui[&username_].content();
|
let username = username_.get().content();
|
||||||
let password = ui[&password_].content();
|
let password = password_.get().content();
|
||||||
state
|
state
|
||||||
.handle
|
.handle
|
||||||
.send(ClientMsg::CreateAccount { username, password });
|
.send(ClientMsg::CreateAccount { username, password });
|
||||||
@@ -108,7 +108,7 @@ pub fn login_screen(client: &mut Client, ui: &mut Ui) -> WidgetId {
|
|||||||
field_box(
|
field_box(
|
||||||
username
|
username
|
||||||
.on(Edited, |ctx| {
|
.on(Edited, |ctx| {
|
||||||
ctx.state.data.username = ctx.ui[ctx.id].content();
|
ctx.state.data.username = ctx.widget.get().content();
|
||||||
})
|
})
|
||||||
.add(ui),
|
.add(ui),
|
||||||
ui,
|
ui,
|
||||||
@@ -116,7 +116,7 @@ pub fn login_screen(client: &mut Client, ui: &mut Ui) -> WidgetId {
|
|||||||
field_box(
|
field_box(
|
||||||
password
|
password
|
||||||
.on(Edited, |ctx| {
|
.on(Edited, |ctx| {
|
||||||
ctx.state.data.password = ctx.ui[ctx.id].content();
|
ctx.state.data.password = ctx.widget.get().content();
|
||||||
})
|
})
|
||||||
.add(ui),
|
.add(ui),
|
||||||
ui,
|
ui,
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ use openworm::net::{ClientMsg, NetClientMsg};
|
|||||||
|
|
||||||
pub const SIZE: u32 = 20;
|
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 {
|
let ClientState::LoggedIn(state) = &mut client.state else {
|
||||||
panic!("we ain't logged in buh");
|
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 {
|
let ClientState::LoggedIn(state) = &mut ctx.state.state else {
|
||||||
panic!("we ain't logged in buh");
|
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 {
|
let msg = NetClientMsg {
|
||||||
content: content.clone(),
|
content: content.clone(),
|
||||||
};
|
};
|
||||||
state.network.send(ClientMsg::SendMsg(msg.clone()));
|
state.network.send(ClientMsg::SendMsg(msg.clone()));
|
||||||
let msg = msg_widget(&state.username, &content).add(ctx.ui);
|
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)
|
.pad(15)
|
||||||
.attr::<Selector>(send_text)
|
.attr::<Selector>(send_text)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use iris::winit::attr::Selector;
|
|||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
pub fn werror(ui: &mut Ui, msg: &str) -> WidgetId {
|
pub fn werror(ui: &mut Ui, msg: &str) -> WidgetRef {
|
||||||
wtext(msg)
|
wtext(msg)
|
||||||
.size(20)
|
.size(20)
|
||||||
.pad(10)
|
.pad(10)
|
||||||
@@ -15,7 +15,7 @@ pub fn hint(msg: impl Into<String>) -> TextBuilder {
|
|||||||
wtext(msg).size(20).color(Color::GRAY)
|
wtext(msg).size(20).color(Color::GRAY)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn field_widget(name: &str, hint_text: &str, ui: &mut Ui) -> WidgetId<TextEdit> {
|
pub fn field_widget(name: &str, hint_text: &str, ui: &mut Ui) -> WidgetRef<TextEdit> {
|
||||||
wtext(name)
|
wtext(name)
|
||||||
.editable(true)
|
.editable(true)
|
||||||
.size(20)
|
.size(20)
|
||||||
@@ -23,7 +23,7 @@ pub fn field_widget(name: &str, hint_text: &str, ui: &mut Ui) -> WidgetId<TextEd
|
|||||||
.add(ui)
|
.add(ui)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn field_box(field: WidgetId<TextEdit>, ui: &mut Ui) -> WidgetId {
|
pub fn field_box(field: WidgetRef<TextEdit>, ui: &mut Ui) -> WidgetRef {
|
||||||
field
|
field
|
||||||
.clone()
|
.clone()
|
||||||
.pad(10)
|
.pad(10)
|
||||||
@@ -41,17 +41,17 @@ pub fn submit_button(
|
|||||||
rect(color)
|
rect(color)
|
||||||
.radius(15)
|
.radius(15)
|
||||||
.on(CursorSense::click(), move |ctx| {
|
.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_submit(ctx.state, ctx.ui);
|
||||||
})
|
})
|
||||||
.on(
|
.on(
|
||||||
CursorSense::HoverStart | CursorSense::unclick(),
|
CursorSense::HoverStart | CursorSense::unclick(),
|
||||||
move |ctx| {
|
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| {
|
.on(CursorSense::HoverEnd, move |ctx| {
|
||||||
ctx.ui[ctx.id].color = color;
|
ctx.widget.get_mut().color = color;
|
||||||
})
|
})
|
||||||
.height(60)
|
.height(60)
|
||||||
.foreground(wtext(text).size(25).text_align(Align::CENTER))
|
.foreground(wtext(text).size(25).text_align(Align::CENTER))
|
||||||
|
|||||||
Reference in New Issue
Block a user