the beginning
This commit is contained in:
216
src/main.rs
216
src/main.rs
@@ -5,7 +5,6 @@ use arboard::Clipboard;
|
||||
use input::Input;
|
||||
use render::Renderer;
|
||||
use ui::prelude::*;
|
||||
use text_lib::Family;
|
||||
use winit::{event::WindowEvent, event_loop::ActiveEventLoop, window::Window};
|
||||
|
||||
mod app;
|
||||
@@ -20,7 +19,6 @@ pub struct Client {
|
||||
renderer: Renderer,
|
||||
input: Input,
|
||||
ui: Ui,
|
||||
info: WidgetId<Text>,
|
||||
focus: Option<WidgetId<TextEdit>>,
|
||||
clipboard: Clipboard,
|
||||
}
|
||||
@@ -37,193 +35,58 @@ impl Client {
|
||||
let renderer = Renderer::new(window);
|
||||
|
||||
let mut ui = Ui::new();
|
||||
let rrect = rect(Color::WHITE).radius(20);
|
||||
let pad_test = (
|
||||
rrect.color(Color::BLUE),
|
||||
(
|
||||
rrect.color(Color::RED).sized(100).center(),
|
||||
(
|
||||
rrect.color(Color::ORANGE),
|
||||
rrect.color(Color::LIME).pad(10.0),
|
||||
)
|
||||
.span(Dir::RIGHT, ratio(1)),
|
||||
rrect.color(Color::YELLOW),
|
||||
)
|
||||
.span(Dir::RIGHT, [2, 2, 1])
|
||||
.pad(10),
|
||||
)
|
||||
.span(Dir::RIGHT, [1, 3])
|
||||
.add_static(&mut ui);
|
||||
|
||||
let span_test = (
|
||||
rrect.color(Color::GREEN),
|
||||
rrect.color(Color::ORANGE),
|
||||
rrect.color(Color::CYAN),
|
||||
rrect.color(Color::BLUE),
|
||||
rrect.color(Color::MAGENTA),
|
||||
rrect.color(Color::RED),
|
||||
)
|
||||
.span(
|
||||
Dir::LEFT,
|
||||
[
|
||||
fixed(100),
|
||||
ratio(1),
|
||||
ratio(1),
|
||||
relative(0.5),
|
||||
fixed(100),
|
||||
fixed(100),
|
||||
],
|
||||
)
|
||||
.add_static(&mut ui);
|
||||
|
||||
let span_add = Span::empty(Dir::RIGHT).add_static(&mut ui);
|
||||
|
||||
let add_button = rect(Color::LIME)
|
||||
.radius(30)
|
||||
.on(CursorSense::click(), move |ctx: &mut Client, _| {
|
||||
let child = ctx
|
||||
.ui
|
||||
.add(image(include_bytes!("assets/sungals.png")).center())
|
||||
.any();
|
||||
ctx.ui[span_add].children.push((child, sized()));
|
||||
})
|
||||
.sized(150)
|
||||
.align(Align::BotRight);
|
||||
|
||||
let del_button = rect(Color::RED)
|
||||
.radius(30)
|
||||
.on(CursorSense::click(), move |ctx: &mut Client, _| {
|
||||
ctx.ui[span_add].children.pop();
|
||||
})
|
||||
.sized(150)
|
||||
.align(Align::BotLeft);
|
||||
|
||||
let span_add_test = (span_add, add_button, del_button)
|
||||
.stack()
|
||||
.add_static(&mut ui);
|
||||
|
||||
let main = pad_test.pad(10).add_static(&mut ui);
|
||||
|
||||
let btext = |content| text(content).size(30);
|
||||
|
||||
let text_test = (
|
||||
btext("this is a").align(Align::Left),
|
||||
btext("teeeeeeeest").align(Align::Right),
|
||||
btext("okkk\nokkkkkk!").align(Align::Left),
|
||||
btext("hmm"),
|
||||
btext("a"),
|
||||
(
|
||||
btext("'").family(Family::Monospace).align(Align::Top),
|
||||
btext("'").family(Family::Monospace),
|
||||
btext(":gamer mode").family(Family::Monospace),
|
||||
rect(Color::CYAN).sized(10).center(),
|
||||
rect(Color::RED).sized(100).center(),
|
||||
rect(Color::PURPLE).sized(50).align(Align::Top),
|
||||
)
|
||||
.span(Dir::RIGHT, sized())
|
||||
.center(),
|
||||
text("pretty cool right?").size(50),
|
||||
)
|
||||
.span(Dir::DOWN, sized())
|
||||
.add_static(&mut ui);
|
||||
|
||||
let texts = Span::empty(Dir::DOWN).add_static(&mut ui);
|
||||
let msg_area = (Rect::new(Color::SKY), texts.scroll().masked()).stack();
|
||||
let add_text = text("add")
|
||||
let send_text = text("some stuff idk")
|
||||
.editable()
|
||||
.size(20)
|
||||
.text_align(Align::Left)
|
||||
.size(30)
|
||||
.id_on(CursorSense::click(), |id, client: &mut Client, ctx| {
|
||||
client.ui.text(id).select(ctx.cursor, ctx.size);
|
||||
client.focus = Some(id.clone());
|
||||
})
|
||||
.id_on(Submit, move |id, client: &mut Client, _| {
|
||||
let content = client.ui.text(id).take();
|
||||
let text = text(content)
|
||||
.editable()
|
||||
.size(30)
|
||||
.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 msg_box = (rect(Color::WHITE.darker(0.5)), text)
|
||||
.stack()
|
||||
.size(StackSize::Child(1))
|
||||
.add(&mut client.ui);
|
||||
client.ui[texts].children.push((msg_box.any(), sized()));
|
||||
})
|
||||
.add(&mut ui);
|
||||
let text_edit_scroll = (
|
||||
msg_area,
|
||||
|
||||
let msg_area = Span::empty(Dir::DOWN).add(&mut ui);
|
||||
|
||||
let msg_panel = (
|
||||
rect(Color::BLACK.brighter(0.1)),
|
||||
(
|
||||
Rect::new(Color::WHITE.darker(0.9)),
|
||||
msg_area.clone().align(Align::BotLeft).scroll(),
|
||||
(
|
||||
add_text.clone(),
|
||||
Rect::new(Color::GREEN)
|
||||
.on(CursorSense::click(), move |client: &mut Client, _| {
|
||||
client.run_event(&add_text, Submit, ());
|
||||
rect(Color::BLACK.brighter(0.05)).radius(15),
|
||||
send_text
|
||||
.clone()
|
||||
.id_on(Submit, move |id, client: &mut Client, _| {
|
||||
let content = client.ui.text(id).take();
|
||||
let text = 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());
|
||||
})
|
||||
.add(&mut client.ui);
|
||||
client.ui[&msg_area].children.push((text.any(), sized()));
|
||||
})
|
||||
.sized(40),
|
||||
.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());
|
||||
}),
|
||||
)
|
||||
.span(Dir::RIGHT, [ratio(1), sized()])
|
||||
.pad(10),
|
||||
.stack()
|
||||
.pad(15),
|
||||
)
|
||||
.stack()
|
||||
.size(StackSize::Child(1))
|
||||
.offset_layer(1)
|
||||
.align(Align::Bot),
|
||||
.span(Dir::DOWN, [ratio(1), fixed(80)]),
|
||||
)
|
||||
.span(Dir::DOWN, [ratio(1), sized()])
|
||||
.add_static(&mut ui);
|
||||
.stack();
|
||||
|
||||
let switch_button = |color, to, label| {
|
||||
let rect = rect(color)
|
||||
.id_on(CursorSense::click(), move |id, ui: &mut Ui, _| {
|
||||
ui[main].inner.set_static(to);
|
||||
ui[id].color = color.darker(0.3);
|
||||
})
|
||||
.edit_on(
|
||||
CursorSense::HoverStart | CursorSense::unclick(),
|
||||
move |r, _| {
|
||||
r.color = color.brighter(0.2);
|
||||
},
|
||||
)
|
||||
.edit_on(CursorSense::HoverEnd, move |r, _| {
|
||||
r.color = color;
|
||||
});
|
||||
(rect, text(label).size(30)).stack()
|
||||
};
|
||||
|
||||
let tabs = (
|
||||
switch_button(Color::RED, pad_test.any(), "pad"),
|
||||
switch_button(Color::GREEN, span_test.any(), "span"),
|
||||
switch_button(Color::BLUE, span_add_test.any(), "image span"),
|
||||
switch_button(Color::MAGENTA, text_test.any(), "text layout"),
|
||||
switch_button(
|
||||
Color::YELLOW.mul_rgb(0.5),
|
||||
text_edit_scroll.any(),
|
||||
"text edit scroll",
|
||||
),
|
||||
)
|
||||
.span(Dir::RIGHT, ratio(1));
|
||||
|
||||
let info = text("").add(&mut ui);
|
||||
let info_sect = info.clone().pad(10).align(Align::Right);
|
||||
|
||||
(
|
||||
(tabs, main).span(Dir::DOWN, [fixed(40), ratio(1)]),
|
||||
info_sect,
|
||||
)
|
||||
.stack()
|
||||
(rect(Color::BLACK.brighter(0.05)), msg_panel)
|
||||
.span(Dir::RIGHT, [fixed(80), ratio(1)])
|
||||
.set_root(&mut ui);
|
||||
|
||||
Self {
|
||||
renderer,
|
||||
input: Input::default(),
|
||||
ui,
|
||||
info,
|
||||
focus: None,
|
||||
clipboard: Clipboard::new().unwrap(),
|
||||
}
|
||||
@@ -277,15 +140,6 @@ impl Client {
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
let new = format!(
|
||||
"widgets: {}\nactive:{}\nviews: {}",
|
||||
self.ui.num_widgets(),
|
||||
self.ui.active_widgets(),
|
||||
self.renderer.ui.view_count()
|
||||
);
|
||||
if new != *self.ui[&self.info].content {
|
||||
*self.ui[&self.info].content = new;
|
||||
}
|
||||
if self.ui.needs_redraw() {
|
||||
self.renderer.window().request_redraw();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user