finally usable state stuff ig
This commit is contained in:
2
iris
2
iris
Submodule iris updated: b66d4da5d7...434e3c3af7
@@ -54,9 +54,16 @@ impl DefaultAppState for Client {
|
|||||||
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);
|
||||||
|
let bg = (
|
||||||
|
image(include_bytes!("./assets/fuit.jpg")),
|
||||||
|
rect(Color::BLACK.alpha((0.8 * 255.0) as u8)),
|
||||||
|
)
|
||||||
|
.stack();
|
||||||
|
|
||||||
(
|
(
|
||||||
notif.clone().pad(Padding::top(10)).align(Align::TOP_CENTER),
|
bg,
|
||||||
main_ui.clone(),
|
main_ui.clone(),
|
||||||
|
notif.clone().pad(Padding::top(10)).align(Align::TOP_CENTER),
|
||||||
)
|
)
|
||||||
.stack()
|
.stack()
|
||||||
.set_root(ui);
|
.set_root(ui);
|
||||||
@@ -86,7 +93,7 @@ impl DefaultAppState for Client {
|
|||||||
thread: th,
|
thread: th,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
login_screen(self, ui).set_ptr(&self.main_ui, ui);
|
// login_screen(self, ui).set_ptr(&self.main_ui, ui);
|
||||||
}
|
}
|
||||||
ClientEvent::ServerMsg(msg) => match msg {
|
ClientEvent::ServerMsg(msg) => match msg {
|
||||||
ServerMsg::SendMsg(msg) => {
|
ServerMsg::SendMsg(msg) => {
|
||||||
|
|||||||
4
src/bin/client/ui/color.rs
Normal file
4
src/bin/client/ui/color.rs
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
use super::*;
|
||||||
|
|
||||||
|
pub const MODAL_BG: UiColor = UiColor::BLACK.brighter(0.05);
|
||||||
|
pub const GREEN: UiColor = UiColor::rgb(0, 150, 0);
|
||||||
@@ -1,8 +1,3 @@
|
|||||||
use iris::winit::{UiState, event::Edited};
|
|
||||||
use openworm::net::ClientMsg;
|
|
||||||
|
|
||||||
use crate::{net::AppHandle, state::ClientState};
|
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
pub fn start_screen(client: &mut Client, ui: &mut Ui) -> WidgetRef {
|
pub fn start_screen(client: &mut Client, ui: &mut Ui) -> WidgetRef {
|
||||||
@@ -18,118 +13,134 @@ pub fn start_screen(client: &mut Client, ui: &mut Ui) -> WidgetRef {
|
|||||||
.any(),
|
.any(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let connect = Button::submit("connect", ui);
|
||||||
|
let create = Button::submit("create", ui);
|
||||||
|
let connect_ = connect.clone();
|
||||||
|
let create_ = create.clone();
|
||||||
|
ui.on(connect.view(), Submit, move |_| {
|
||||||
|
connect_.disable();
|
||||||
|
create_.disable();
|
||||||
|
});
|
||||||
|
|
||||||
(
|
(
|
||||||
wtext("Select Account").text_align(Align::CENTER).size(30),
|
wtext("Select Account").text_align(Align::CENTER).size(30),
|
||||||
accounts,
|
accounts,
|
||||||
(
|
(connect, create).span(Dir::RIGHT).gap(10),
|
||||||
submit_button("connect", |_, _| {}),
|
|
||||||
submit_button("create", |_, _| {}),
|
|
||||||
)
|
|
||||||
.span(Dir::RIGHT)
|
|
||||||
.gap(10),
|
|
||||||
)
|
)
|
||||||
.span(Dir::DOWN)
|
.span(Dir::DOWN)
|
||||||
.gap(10)
|
.gap(30)
|
||||||
.pad(15)
|
.pad(15)
|
||||||
.background(rect(Color::BLACK.brighter(0.2)).radius(15))
|
.background(rect(color::MODAL_BG).radius(15))
|
||||||
.width(400)
|
.width(400)
|
||||||
.align(Align::CENTER)
|
.align(Align::CENTER)
|
||||||
.add(ui)
|
.add(ui)
|
||||||
.any()
|
.any()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn connect_screen(client: &mut Client, ui: &mut Ui, state: &UiState) -> WidgetRef {
|
// 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();
|
||||||
let handle = AppHandle {
|
// let handle = AppHandle {
|
||||||
proxy: proxy.clone(),
|
// proxy: proxy.clone(),
|
||||||
window: state.window.clone(),
|
// window: state.window.clone(),
|
||||||
};
|
// };
|
||||||
let submit = submit_button("connect", move |client, _ui| {
|
//
|
||||||
let ClientState::Connect(state) = &mut client.state else {
|
// let submit = Button::submit("connect", ui);
|
||||||
return;
|
//
|
||||||
};
|
// submit.on(Submit, move |ctx| {
|
||||||
let ip = ip_.get().content();
|
// let ClientState::Connect(state) = &mut ctx.state.state else {
|
||||||
state.handle = Some(connect(handle.clone(), ConnectInfo { ip }));
|
// return;
|
||||||
});
|
// };
|
||||||
(
|
// let ip = ip_.get().content();
|
||||||
wtext("connect to a server")
|
// state.handle = Some(connect(handle.clone(), ConnectInfo { ip }));
|
||||||
.text_align(Align::CENTER)
|
// });
|
||||||
.size(30),
|
//
|
||||||
field_box(
|
// (
|
||||||
// NOTE: should probably do this on submit
|
// wtext("connect to a server")
|
||||||
ip.on(Edited, |ctx| {
|
// .text_align(Align::CENTER)
|
||||||
ctx.state.data.ip = ctx.widget.get().content();
|
// .size(30),
|
||||||
})
|
// field_box(
|
||||||
.add(ui),
|
// // NOTE: should probably do this on submit
|
||||||
ui,
|
// ip.on(Edited, |ctx| {
|
||||||
),
|
// ctx.state.data.ip = ctx.widget.get().content();
|
||||||
submit,
|
// })
|
||||||
)
|
// .add(ui),
|
||||||
.span(Dir::DOWN)
|
// ui,
|
||||||
.gap(10)
|
// ),
|
||||||
.pad(15)
|
// submit,
|
||||||
.background(rect(Color::BLACK.brighter(0.2)).radius(15))
|
// )
|
||||||
.width(400)
|
// .span(Dir::DOWN)
|
||||||
.align(Align::CENTER)
|
// .gap(10)
|
||||||
.add(ui)
|
// .pad(15)
|
||||||
.any()
|
// .background(rect(Color::BLACK.brighter(0.2)).radius(15))
|
||||||
}
|
// .width(400)
|
||||||
|
// .align(Align::CENTER)
|
||||||
|
// .add(ui)
|
||||||
|
// .any()
|
||||||
|
// }
|
||||||
|
|
||||||
pub fn login_screen(client: &mut Client, ui: &mut Ui) -> WidgetRef {
|
// 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 = Button::submit("login", ui);
|
||||||
let ClientState::Login(state) = &mut client.state else {
|
// submit
|
||||||
return;
|
// .on(move |client, _ui| {
|
||||||
};
|
// let ClientState::Login(state) = &mut client.state else {
|
||||||
let username = username_.get().content();
|
// return;
|
||||||
let password = password_.get().content();
|
// };
|
||||||
state.handle.send(ClientMsg::Login { username, password });
|
// let username = username_.get().content();
|
||||||
});
|
// let password = password_.get().content();
|
||||||
let username_ = username.clone();
|
// state.handle.send(ClientMsg::Login { username, password });
|
||||||
let password_ = password.clone();
|
// })
|
||||||
let create_button = submit_button("create account", move |client, _ui| {
|
// .add(ui);
|
||||||
let ClientState::Login(state) = &mut client.state else {
|
// let username_ = username.clone();
|
||||||
return;
|
// let password_ = password.clone();
|
||||||
};
|
// let create_button = Button::submit(
|
||||||
let username = username_.get().content();
|
// "create account",
|
||||||
let password = password_.get().content();
|
// move |client, _ui| {
|
||||||
state
|
// let ClientState::Login(state) = &mut client.state else {
|
||||||
.handle
|
// return;
|
||||||
.send(ClientMsg::CreateAccount { username, password });
|
// };
|
||||||
});
|
// let username = username_.get().content();
|
||||||
(
|
// let password = password_.get().content();
|
||||||
wtext("login to server").text_align(Align::CENTER).size(30),
|
// state
|
||||||
field_box(
|
// .handle
|
||||||
username
|
// .send(ClientMsg::CreateAccount { username, password });
|
||||||
.on(Edited, |ctx| {
|
// },
|
||||||
ctx.state.data.username = ctx.widget.get().content();
|
// ui,
|
||||||
})
|
// );
|
||||||
.add(ui),
|
// create_button.on()
|
||||||
ui,
|
// (
|
||||||
),
|
// wtext("login to server").text_align(Align::CENTER).size(30),
|
||||||
field_box(
|
// field_box(
|
||||||
password
|
// username
|
||||||
.on(Edited, |ctx| {
|
// .on(Edited, |ctx| {
|
||||||
ctx.state.data.password = ctx.widget.get().content();
|
// ctx.state.data.username = ctx.widget.get().content();
|
||||||
})
|
// })
|
||||||
.add(ui),
|
// .add(ui),
|
||||||
ui,
|
// ui,
|
||||||
),
|
// ),
|
||||||
submit,
|
// field_box(
|
||||||
create_button,
|
// password
|
||||||
)
|
// .on(Edited, |ctx| {
|
||||||
.span(Dir::DOWN)
|
// ctx.state.data.password = ctx.widget.get().content();
|
||||||
.gap(10)
|
// })
|
||||||
.pad(15)
|
// .add(ui),
|
||||||
.background(rect(Color::BLACK.brighter(0.2)).radius(15))
|
// ui,
|
||||||
.width(400)
|
// ),
|
||||||
.align(Align::CENTER)
|
// submit,
|
||||||
.add(ui)
|
// create_button,
|
||||||
.any()
|
// )
|
||||||
}
|
// .span(Dir::DOWN)
|
||||||
|
// .gap(10)
|
||||||
|
// .pad(15)
|
||||||
|
// .background(rect(Color::BLACK.brighter(0.2)).radius(15))
|
||||||
|
// .width(400)
|
||||||
|
// .align(Align::CENTER)
|
||||||
|
// .add(ui)
|
||||||
|
// .any()
|
||||||
|
// }
|
||||||
|
|||||||
@@ -1,12 +1,5 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
use crate::state::{ClientState, LoggedIn};
|
use crate::state::{ClientState, LoggedIn};
|
||||||
use iris::{
|
|
||||||
layout::len_fns::*,
|
|
||||||
winit::{
|
|
||||||
attr::{Selectable, Selector},
|
|
||||||
event::Submit,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
use openworm::net::{ClientMsg, NetClientMsg};
|
use openworm::net::{ClientMsg, NetClientMsg};
|
||||||
|
|
||||||
pub const SIZE: u32 = 20;
|
pub const SIZE: u32 = 20;
|
||||||
@@ -18,16 +11,7 @@ pub fn main_view(client: &mut Client, ui: &mut Ui) -> WidgetRef {
|
|||||||
let msg_panel = msg_panel(ui, state);
|
let msg_panel = msg_panel(ui, state);
|
||||||
let side_bar = rect(Color::BLACK.brighter(0.05)).width(80);
|
let side_bar = rect(Color::BLACK.brighter(0.05)).width(80);
|
||||||
|
|
||||||
let bg = (
|
(side_bar, msg_panel).span(Dir::RIGHT).add(ui).any()
|
||||||
image(include_bytes!("../assets/fuit.jpg")),
|
|
||||||
rect(Color::BLACK.alpha((0.8 * 255.0) as u8)),
|
|
||||||
)
|
|
||||||
.stack();
|
|
||||||
(side_bar, msg_panel)
|
|
||||||
.span(Dir::RIGHT)
|
|
||||||
.background(bg)
|
|
||||||
.add(ui)
|
|
||||||
.any()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn msg_widget(username: &str, content: &str) -> impl WidgetRet {
|
pub fn msg_widget(username: &str, content: &str) -> impl WidgetRet {
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
use iris::winit::attr::Selector;
|
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
pub fn werror(ui: &mut Ui, msg: &str) -> WidgetRef {
|
pub fn werror(ui: &mut Ui, msg: &str) -> WidgetRef {
|
||||||
@@ -33,27 +31,72 @@ pub fn field_box(field: WidgetRef<TextEdit>, ui: &mut Ui) -> WidgetRef {
|
|||||||
.any()
|
.any()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn submit_button(
|
#[derive(Clone)]
|
||||||
text: &str,
|
pub struct Button {
|
||||||
on_submit: impl Fn(&mut Client, &mut Ui) + 'static,
|
color: UiColor,
|
||||||
) -> impl WidgetRet {
|
root: WidgetRef,
|
||||||
let color = Color::rgb(0, 200, 0);
|
rect: WidgetRef<Rect>,
|
||||||
rect(color)
|
enabled: Handle<bool>,
|
||||||
.radius(15)
|
}
|
||||||
.on(CursorSense::click(), move |ctx| {
|
|
||||||
ctx.widget.get_mut().color = color.darker(0.2);
|
impl WidgetView for Button {
|
||||||
on_submit(ctx.state, ctx.ui);
|
fn view(&self) -> &WidgetRef<Self::Widget> {
|
||||||
})
|
&self.root
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Button {
|
||||||
|
pub fn new(text: &str, color: UiColor, ui: &mut Ui) -> Self {
|
||||||
|
let rect = rect(color).radius(15).add(ui);
|
||||||
|
let enabled = Handle::from(true);
|
||||||
|
let enabled_ = enabled.clone();
|
||||||
|
let enabled__ = enabled.clone();
|
||||||
|
let root = rect
|
||||||
|
.clone()
|
||||||
.on(
|
.on(
|
||||||
CursorSense::HoverStart | CursorSense::unclick(),
|
CursorSense::HoverStart | CursorSense::unclick(),
|
||||||
move |ctx| {
|
move |ctx| {
|
||||||
|
if !*enabled_.get() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
ctx.widget.get_mut().color = color.brighter(0.1);
|
ctx.widget.get_mut().color = color.brighter(0.1);
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.on(CursorSense::HoverEnd, move |ctx| {
|
.on(CursorSense::HoverEnd, move |ctx| {
|
||||||
|
if !*enabled__.get() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
ctx.widget.get_mut().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))
|
||||||
.to_any()
|
.add(ui)
|
||||||
|
.any();
|
||||||
|
let root_ = root.clone();
|
||||||
|
let enabled_ = enabled.clone();
|
||||||
|
rect.clone()
|
||||||
|
.on(CursorSense::click(), move |ctx| {
|
||||||
|
if !*enabled_.get() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ctx.widget.get_mut().color = color.darker(0.2);
|
||||||
|
ctx.ui.run_event(ctx.state, &root_, Submit, ());
|
||||||
|
})
|
||||||
|
.add(ui);
|
||||||
|
Self {
|
||||||
|
root,
|
||||||
|
rect,
|
||||||
|
color,
|
||||||
|
enabled,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn submit(text: &str, ui: &mut Ui) -> Self {
|
||||||
|
Self::new(text, color::GREEN, ui)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn disable(&self) {
|
||||||
|
*self.enabled.get_mut() = false;
|
||||||
|
self.rect.get_mut().color = self.color.darker(0.8);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
use crate::{
|
use crate::Client;
|
||||||
Client,
|
|
||||||
net::{ConnectInfo, connect},
|
|
||||||
};
|
|
||||||
use iris::prelude::*;
|
use iris::prelude::*;
|
||||||
|
use len_fns::*;
|
||||||
|
|
||||||
mod login;
|
mod login;
|
||||||
mod main;
|
mod main;
|
||||||
mod misc;
|
mod misc;
|
||||||
|
pub mod color;
|
||||||
|
|
||||||
pub use login::*;
|
pub use login::*;
|
||||||
pub use main::*;
|
pub use main::*;
|
||||||
pub use misc::*;
|
pub use misc::*;
|
||||||
|
|||||||
Reference in New Issue
Block a user