65 lines
2.0 KiB
Rust
65 lines
2.0 KiB
Rust
use crate::net::NetState;
|
|
|
|
use super::*;
|
|
|
|
pub fn login_screen(client: &mut Client) -> WidgetId {
|
|
let Client {
|
|
ui, handle, data, ..
|
|
} = client;
|
|
|
|
let mut field = |name, hint_| text(name).editable(true).size(20).hint(hint(hint_)).add(ui);
|
|
let ip = field(&data.ip, "ip");
|
|
let username = field(&data.username, "username");
|
|
// let password = field("password");
|
|
|
|
let fbx = |field: WidgetId<TextEdit>| {
|
|
field
|
|
.clone()
|
|
.pad(10)
|
|
.background(rect(Color::BLACK.brighter(0.1)).radius(15))
|
|
.attr::<Selector>(field)
|
|
};
|
|
|
|
// I LAV NOT HAVING ERGONOMIC CLONES
|
|
let handle = handle.clone();
|
|
let ip_ = ip.clone();
|
|
let username_ = username.clone();
|
|
let color = Color::GREEN;
|
|
let submit = rect(color)
|
|
.radius(15)
|
|
.id_on(CursorSense::click(), move |id, client: &mut Client, _| {
|
|
client.ui[id].color = color.darker(0.3);
|
|
let ip = client.ui[&ip_].content();
|
|
let username = client.ui[&username_].content();
|
|
let th = connect(handle.clone(), ConnectInfo { ip, username });
|
|
client.net = NetState::Connecting(th);
|
|
})
|
|
.height(40);
|
|
let modal = (
|
|
text("login").text_align(Align::CENTER).size(30),
|
|
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,
|
|
)
|
|
.span(Dir::DOWN)
|
|
.gap(10)
|
|
.pad(15)
|
|
.background(rect(Color::BLACK.brighter(0.2)).radius(15))
|
|
.width(400)
|
|
.align(Align::CENTER);
|
|
|
|
let err = WidgetPtr::default().add(ui);
|
|
client.error = Some(err.clone());
|
|
|
|
(modal, err.align(Align::TOP_CENTER)).stack().add(ui).any()
|
|
}
|