login screen
This commit is contained in:
@@ -1,117 +1,57 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
pub use app::App;
|
||||
use arboard::Clipboard;
|
||||
use input::Input;
|
||||
use iris::prelude::*;
|
||||
use render::Renderer;
|
||||
use ui::prelude::*;
|
||||
use winit::{event::WindowEvent, event_loop::ActiveEventLoop, window::Window};
|
||||
use winit::{event::WindowEvent, event_loop::ActiveEventLoop};
|
||||
|
||||
use crate::client::ui::{Submit, UiData};
|
||||
|
||||
mod app;
|
||||
mod input;
|
||||
mod render;
|
||||
mod ui;
|
||||
|
||||
use len_fns::*;
|
||||
pub use app::AppHandle;
|
||||
|
||||
pub enum ClientEvent {
|
||||
Connect,
|
||||
}
|
||||
|
||||
pub struct Client {
|
||||
renderer: Renderer,
|
||||
input: Input,
|
||||
ui: Ui,
|
||||
focus: Option<WidgetId<TextEdit>>,
|
||||
ui_data: UiData,
|
||||
clipboard: Clipboard,
|
||||
}
|
||||
|
||||
#[derive(Eq, PartialEq, Hash, Clone)]
|
||||
struct Submit;
|
||||
|
||||
impl DefaultEvent for Submit {
|
||||
type Data = ();
|
||||
}
|
||||
|
||||
pub fn msg_widget(content: String) -> impl WidgetLike<FnTag> {
|
||||
let content = text(content)
|
||||
.editable()
|
||||
.size(20)
|
||||
.text_align(Align::Left)
|
||||
.wrap(true)
|
||||
.id_on(CursorSense::click(), |id, client: &mut Client, ctx| {
|
||||
client.ui.text(id).select(ctx.cursor, ctx.size);
|
||||
client.focus = Some(id.clone());
|
||||
});
|
||||
let header = text("some user").size(20);
|
||||
(
|
||||
image(include_bytes!("./assets/sungals.png"))
|
||||
.sized((70, 70))
|
||||
.align(Align::TopLeft),
|
||||
(header.align(Align::TopLeft), content.align(Align::TopLeft))
|
||||
.span(Dir::DOWN)
|
||||
.gap(10),
|
||||
)
|
||||
.span(Dir::RIGHT)
|
||||
.gap(10)
|
||||
}
|
||||
|
||||
impl Client {
|
||||
pub fn new(window: Arc<Window>) -> Self {
|
||||
let renderer = Renderer::new(window);
|
||||
pub fn new(handle: AppHandle) -> Self {
|
||||
let renderer = Renderer::new(handle.window.clone());
|
||||
|
||||
let mut ui = Ui::new();
|
||||
|
||||
let send_text = text("some stuff idk")
|
||||
.editable()
|
||||
.size(20)
|
||||
.text_align(Align::Left)
|
||||
.add(&mut ui);
|
||||
|
||||
let msg_area = Span::empty(Dir::DOWN).gap(15).add(&mut ui);
|
||||
|
||||
quinn::rustls::crypto::aws_lc_rs::default_provider()
|
||||
.install_default()
|
||||
.unwrap();
|
||||
// connect().unwrap();
|
||||
|
||||
let msg_panel = (
|
||||
msg_area
|
||||
.clone()
|
||||
.background(rect(Color::SKY))
|
||||
.align(Align::BotLeft)
|
||||
.scroll()
|
||||
.pad(Padding::x(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_widget(content).add(&mut client.ui);
|
||||
client.ui[&msg_area].children.push(msg.any());
|
||||
})
|
||||
.pad(15)
|
||||
.on(CursorSense::click(), move |client: &mut Client, data| {
|
||||
client.ui.text(&send_text).select(data.cursor, data.size);
|
||||
client.focus = Some(send_text.clone());
|
||||
})
|
||||
.background(rect(Color::BLACK.brighter(0.05)).radius(15))
|
||||
.pad(15)
|
||||
.height(80),
|
||||
)
|
||||
.span(Dir::DOWN)
|
||||
.width(rest(1))
|
||||
.background(rect(Color::BLACK.brighter(0.1)));
|
||||
|
||||
(rect(Color::BLACK.brighter(0.05)).width(80), msg_panel)
|
||||
.span(Dir::RIGHT)
|
||||
.set_root(&mut ui);
|
||||
let (ui, ui_data) = ui::ui(handle);
|
||||
|
||||
Self {
|
||||
renderer,
|
||||
input: Input::default(),
|
||||
ui,
|
||||
ui_data,
|
||||
focus: None,
|
||||
clipboard: Clipboard::new().unwrap(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn event(&mut self, event: WindowEvent, event_loop: &ActiveEventLoop) {
|
||||
pub fn event(&mut self, event: ClientEvent, _: &ActiveEventLoop) {
|
||||
match event {
|
||||
ClientEvent::Connect => {
|
||||
self.ui.set_root(self.ui_data.main_view.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn window_event(&mut self, event: WindowEvent, event_loop: &ActiveEventLoop) {
|
||||
let input_changed = self.input.event(&event);
|
||||
let cursor_state = self.cursor_state().clone();
|
||||
if let Some(focus) = &self.focus
|
||||
|
||||
Reference in New Issue
Block a user