hint gaming

This commit is contained in:
2025-11-21 20:18:29 -05:00
parent c0de059241
commit 528a7503fc
5 changed files with 216 additions and 189 deletions

83
src/bin/client/ui/main.rs Normal file
View File

@@ -0,0 +1,83 @@
use super::*;
pub const SIZE: u32 = 20;
pub fn main_view(client: &mut Client, network: NetSender) -> WidgetId {
let msg_panel = msg_panel(client, network);
let side_bar = rect(Color::BLACK.brighter(0.05)).width(80);
let bg = (
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(&mut client.ui)
.any()
}
pub fn msg_widget(msg: Msg) -> impl WidgetLike<FnTag> {
let content = text(msg.content)
.editable()
.size(SIZE)
.wrap(true)
.id_on(CursorSense::click(), |i, c, d| focus(i.clone(), c, d));
let header = text(msg.user).size(SIZE);
(
image(include_bytes!("../assets/sungals.png"))
.sized((70, 70))
.align(Align::TOP),
(header, content)
.span(Dir::DOWN)
.gap(10)
.width(rest(1))
.align(Align::TOP),
)
.span(Dir::RIGHT)
.gap(10)
}
pub fn msg_panel(client: &mut Client, network: NetSender) -> impl WidgetFn<Sized> + use<> {
let Client { ui, channel, .. } = client;
let msg_area = Span::empty(Dir::DOWN).gap(15).add(ui);
*channel = Some(msg_area.clone());
let send_text = text("")
.editable()
.size(SIZE)
.wrap(true)
.hint(hint("send message"))
.add(ui);
(
msg_area
.clone()
.scroll()
.pad(Padding::x(15).with_top(15))
.height(rest(1)),
send_text
.clone()
.id_on(Submit, move |id, client: &mut Client, _| {
let content = client.ui.text(id).take();
let msg = Msg {
content: content.clone(),
user: client.username.clone(),
};
network.send(ClientMsg::SendMsg(msg.clone()));
let msg = msg_widget(msg).add(&mut client.ui);
client.ui[&msg_area].children.push(msg.any());
})
.pad(15)
.on(CursorSense::click(), focus_other(send_text))
.scroll()
.masked()
.background(rect(Color::BLACK.brighter(0.05)).radius(15))
.pad(15)
.max_height(rel(0.5))
.z_offset(1),
)
.span(Dir::DOWN)
.width(rest(1))
}