This commit is contained in:
2026-01-12 18:42:34 -05:00
parent efb21705c3
commit 040b70e1c5
9 changed files with 517 additions and 196 deletions
+7 -9
View File
@@ -1,6 +1,6 @@
use super::*;
pub fn start_ui(client: &mut Client, ui: &mut Ui) -> WidgetRef {
pub fn start_ui(rsc: &mut Rsc) -> WidgetRef {
let mut accounts = Span::empty(Dir::DOWN);
accounts.push(
@@ -9,16 +9,14 @@ pub fn start_ui(client: &mut Client, ui: &mut Ui) -> WidgetRef {
.center_text()
.color(Color::GRAY)
.height(60)
.add(ui),
.add_strong(rsc),
);
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();
let connect = Button::submit("connect", rsc);
let create = Button::submit("create", rsc);
connect.on(Submit, move |_, rsc| {
connect.disable();
create.disable();
});
let connect_ = connect.clone();
+20 -31
View File
@@ -1,22 +1,19 @@
use crate::Rsc;
use super::*;
use crate::state::{ClientState, LoggedIn};
use openworm::net::{ClientMsg, NetClientMsg};
pub const SIZE: u32 = 20;
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");
};
let msg_panel = msg_panel(ui, state);
pub fn main_view(rsc: &mut Rsc) -> WidgetRef {
let msg_panel = msg_panel(rsc);
let side_bar = rect(Color::BLACK.brighter(0.05)).width(80);
(side_bar, msg_panel).span(Dir::RIGHT).add(ui)
(side_bar, msg_panel).span(Dir::RIGHT).add(rsc)
}
pub fn msg_widget(username: &str, content: &str) -> impl WidgetRet {
pub fn msg_widget(username: &str, content: &str) -> impl WidgetIdFn<Rsc> {
let content = wtext(content)
.editable(false)
.editable(EditMode::MultiLine)
.size(SIZE)
.wrap(true)
.attr::<Selectable>(());
@@ -36,40 +33,32 @@ pub fn msg_widget(username: &str, content: &str) -> impl WidgetRet {
.to_any()
}
pub fn msg_panel(ui: &mut Ui, state: &mut LoggedIn) -> WidgetRef {
let msg_area = Span::empty(Dir::DOWN).gap(15).add(ui);
state.channel = Some(msg_area.clone());
pub fn msg_panel(rsc: &mut Rsc) -> WidgetRef {
let msg_area = Span::empty(Dir::DOWN).gap(15);
let send_text = wtext("")
.editable(false)
.editable(EditMode::MultiLine)
.size(SIZE)
.wrap(true)
.hint(hint("send message"))
.add(ui);
.add(rsc);
let msg_area = msg_area.add(rsc);
(
msg_area
.clone()
.scroll()
.scrollable()
.pad(Padding::x(15).with_top(15))
.height(rest(1)),
send_text
.clone()
.on(Submit, move |ctx| {
let ClientState::LoggedIn(state) = &mut ctx.state.state else {
panic!("we ain't logged in buh");
};
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);
msg_area.get_mut().children.push(msg);
.on(Submit, move |ctx, rsc| {
let content = ctx.widget.edit(rsc).take();
let msg = msg_widget("ur mothe:", &content).add_strong(rsc);
rsc.ui[msg_area].children.push(msg);
})
.pad(15)
.attr::<Selector>(send_text)
.scroll()
.scrollable()
.masked()
.background(rect(Color::BLACK.brighter(0.05)).radius(15))
.pad(15)
@@ -78,5 +67,5 @@ pub fn msg_panel(ui: &mut Ui, state: &mut LoggedIn) -> WidgetRef {
)
.span(Dir::DOWN)
.width(rest(1))
.add(ui)
.add(rsc)
}
+46 -51
View File
@@ -1,106 +1,101 @@
use super::*;
pub fn werror(ui: &mut Ui, msg: &str) -> WidgetRef {
pub fn werror(msg: &str, rsc: &mut Rsc) -> WidgetHandle {
wtext(msg)
.size(20)
.pad(10)
.background(rect(Color::RED).radius(10))
.add(ui)
.add_strong(rsc)
}
pub fn hint(msg: impl Into<String>) -> TextBuilder {
pub fn hint(msg: impl Into<String>) -> TextBuilder<Rsc> {
wtext(msg).size(20).color(Color::GRAY)
}
pub fn field_widget(name: &str, hint_text: &str, ui: &mut Ui) -> WidgetRef<TextEdit> {
pub fn field_widget(name: &str, hint_text: &str, rsc: &mut Rsc) -> WidgetRef<TextEdit> {
wtext(name)
.editable(true)
.editable(EditMode::SingleLine)
.size(20)
.hint(hint(hint_text))
.add(ui)
.add(rsc)
}
pub fn field_box(field: WidgetRef<TextEdit>, ui: &mut Ui) -> WidgetRef {
pub fn field_box(field: WidgetRef<TextEdit>, rsc: &mut Rsc) -> WidgetRef {
field
.clone()
.pad(10)
.background(rect(Color::BLACK.brighter(0.1)).radius(15))
.attr::<Selector>(field)
.add(ui)
.add(rsc)
}
#[derive(Clone)]
#[derive(Clone, Copy, WidgetView)]
pub struct Button {
color: UiColor,
#[root]
root: WidgetRef,
rect: WidgetRef<Rect>,
enabled: Handle<bool>,
}
impl WidgetView for Button {
fn view(&self) -> &WidgetRef<Self::Widget> {
&self.root
}
}
// impl WidgetView for Button {
// 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();
pub fn new(text: &str, color: UiColor, rsc: &mut Rsc) -> Self {
let rect = rect(color).radius(15).add(rsc);
// let enabled = Handle::from(true);
// let enabled_ = enabled.clone();
// let enabled__ = enabled.clone();
let root = rect
.clone()
.on(
CursorSense::HoverStart | CursorSense::unclick(),
move |ctx| {
if !*enabled_.get() {
return;
}
ctx.widget.get_mut().color = color.brighter(0.1);
move |ctx, rsc: &mut Rsc| {
// if !*enabled_.get() {
// return;
// }
rsc.ui[ctx.widget].color = color.brighter(0.1);
},
)
.on(CursorSense::HoverEnd, move |ctx| {
if !*enabled__.get() {
return;
}
ctx.widget.get_mut().color = color;
.on(CursorSense::HoverEnd, move |ctx, rsc| {
// if !*enabled__.get() {
// return;
// }
rsc.ui[ctx.widget].color = color;
})
.height(60)
.foreground(wtext(text).size(25).text_align(Align::CENTER))
.add(ui);
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);
.add(rsc);
// let enabled_ = enabled.clone();
rect.on(CursorSense::click(), move |ctx, rsc: &mut Rsc| {
// if !*enabled_.get() {
// return;
// }
rsc.ui[ctx.widget].color = color.darker(0.2);
rsc.run_event::<Submit>(root, (), ctx.state);
})
.add(rsc);
Self {
root,
rect,
color,
enabled,
// enabled,
}
}
pub fn submit(text: &str, ui: &mut Ui) -> Self {
Self::new(text, color::GREEN, ui)
pub fn submit(text: &str, rsc: &mut Rsc) -> Self {
Self::new(text, color::GREEN, rsc)
}
pub fn disable(&self) {
pub fn disable(&self, rsc: &mut Rsc) {
*self.enabled.get_mut() = false;
self.rect.get_mut().color = self.color.darker(0.8);
}
}
widget_trait! {
pub trait Stuff;
fn modal(self, width: impl UiNum) -> impl WidgetIdFn {
pub trait Stuff<Rsc: HasUi + 'static>;
fn modal(self, width: impl UiNum) -> impl WidgetIdFn<Rsc> {
|ui| {
self
.pad(15)
+2 -5
View File
@@ -1,14 +1,11 @@
use crate::Client;
use crate::Rsc;
use iris::prelude::*;
use len_fns::*;
pub mod color;
mod connect;
mod main;
mod misc;
pub mod color;
pub use connect::*;
pub use main::*;
pub use misc::*;
event_ctx!(Client);