app work
This commit is contained in:
@@ -142,7 +142,7 @@ impl Client {
|
||||
.stack()
|
||||
.add_static(&mut ui);
|
||||
|
||||
let btext = |content| text(content).size(30);
|
||||
let btext = |content| wtext(content).size(30);
|
||||
|
||||
let text_test = (
|
||||
btext("this is a").align(Align::LEFT),
|
||||
@@ -160,21 +160,21 @@ impl Client {
|
||||
)
|
||||
.span(Dir::RIGHT)
|
||||
.center(),
|
||||
text("pretty cool right?").size(50),
|
||||
wtext("pretty cool right?").size(50),
|
||||
)
|
||||
.span(Dir::DOWN)
|
||||
.add_static(&mut ui);
|
||||
|
||||
let texts = Span::empty(Dir::DOWN).gap(10).add_static(&mut ui);
|
||||
let msg_area = texts.scroll().masked().background(rect(Color::SKY));
|
||||
let add_text = text("add")
|
||||
let add_text = wtext("add")
|
||||
.editable(false)
|
||||
.text_align(Align::LEFT)
|
||||
.size(30)
|
||||
.attr::<Selectable>(())
|
||||
.id_on(Submit, move |id, client: &mut Client, _| {
|
||||
let content = client.ui.text(id).take();
|
||||
let text = text(content)
|
||||
let text = wtext(content)
|
||||
.editable(false)
|
||||
.size(30)
|
||||
.text_align(Align::LEFT)
|
||||
@@ -226,7 +226,7 @@ impl Client {
|
||||
.edit_on(CursorSense::HoverEnd, move |r, _| {
|
||||
r.color = color;
|
||||
});
|
||||
(rect, text(label).size(30).text_align(Align::CENTER)).stack()
|
||||
(rect, wtext(label).size(30).text_align(Align::CENTER)).stack()
|
||||
};
|
||||
|
||||
let tabs = (
|
||||
@@ -242,7 +242,7 @@ impl Client {
|
||||
)
|
||||
.span(Dir::RIGHT);
|
||||
|
||||
let info = text("").add(&mut ui);
|
||||
let info = wtext("").add(&mut ui);
|
||||
let info_sect = info.clone().pad(10).align(Align::RIGHT);
|
||||
|
||||
((tabs.height(40), main).span(Dir::DOWN), info_sect)
|
||||
|
||||
@@ -39,6 +39,13 @@ pub struct Padding {
|
||||
}
|
||||
|
||||
impl Padding {
|
||||
pub const ZERO: Self = Self {
|
||||
left: 0.0,
|
||||
right: 0.0,
|
||||
top: 0.0,
|
||||
bottom: 0.0,
|
||||
};
|
||||
|
||||
pub fn uniform(amt: impl UiNum) -> Self {
|
||||
let amt = amt.to_f32();
|
||||
Self {
|
||||
@@ -75,6 +82,30 @@ impl Padding {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn top(amt: impl UiNum) -> Self {
|
||||
let mut s = Self::ZERO;
|
||||
s.top = amt.to_f32();
|
||||
s
|
||||
}
|
||||
|
||||
pub fn bottom(amt: impl UiNum) -> Self {
|
||||
let mut s = Self::ZERO;
|
||||
s.bottom = amt.to_f32();
|
||||
s
|
||||
}
|
||||
|
||||
pub fn left(amt: impl UiNum) -> Self {
|
||||
let mut s = Self::ZERO;
|
||||
s.left = amt.to_f32();
|
||||
s
|
||||
}
|
||||
|
||||
pub fn right(amt: impl UiNum) -> Self {
|
||||
let mut s = Self::ZERO;
|
||||
s.right = amt.to_f32();
|
||||
s
|
||||
}
|
||||
|
||||
pub fn with_top(mut self, amt: impl UiNum) -> Self {
|
||||
self.top = amt.to_f32();
|
||||
self
|
||||
|
||||
@@ -114,7 +114,7 @@ impl<O: TextBuilderOutput, H: WidgetOption> FnOnce<(&mut Ui,)> for TextBuilder<O
|
||||
}
|
||||
}
|
||||
|
||||
pub fn text(content: impl Into<String>) -> TextBuilder {
|
||||
pub fn wtext(content: impl Into<String>) -> TextBuilder {
|
||||
TextBuilder {
|
||||
content: content.into(),
|
||||
attrs: TextAttrs::default(),
|
||||
|
||||
@@ -15,7 +15,9 @@ pub trait CoreWidget<W, Tag> {
|
||||
fn scroll(self) -> impl WidgetIdFn<Scroll>;
|
||||
fn masked(self) -> impl WidgetFn<Masked>;
|
||||
fn background<T>(self, w: impl WidgetLike<T>) -> impl WidgetFn<Stack>;
|
||||
fn foreground<T>(self, w: impl WidgetLike<T>) -> impl WidgetFn<Stack>;
|
||||
fn layer_offset(self, offset: usize) -> impl WidgetFn<LayerOffset>;
|
||||
fn to_any(self) -> impl WidgetRet;
|
||||
}
|
||||
|
||||
impl<W: WidgetLike<Tag>, Tag> CoreWidget<W::Widget, Tag> for W {
|
||||
@@ -120,12 +122,23 @@ impl<W: WidgetLike<Tag>, Tag> CoreWidget<W::Widget, Tag> for W {
|
||||
}
|
||||
}
|
||||
|
||||
fn foreground<T>(self, w: impl WidgetLike<T>) -> impl WidgetFn<Stack> {
|
||||
move |ui| Stack {
|
||||
children: vec![self.add(ui).any(), w.add(ui).any()],
|
||||
size: StackSize::Child(0),
|
||||
}
|
||||
}
|
||||
|
||||
fn layer_offset(self, offset: usize) -> impl WidgetFn<LayerOffset> {
|
||||
move |ui| LayerOffset {
|
||||
inner: self.add(ui).any(),
|
||||
offset,
|
||||
}
|
||||
}
|
||||
|
||||
fn to_any(self) -> impl WidgetRet {
|
||||
|ui| self.add(ui).any()
|
||||
}
|
||||
}
|
||||
|
||||
pub trait CoreWidgetArr<const LEN: usize, Wa: WidgetArrLike<LEN, Tag>, Tag> {
|
||||
|
||||
@@ -141,6 +141,9 @@ pub struct IdFnTag;
|
||||
pub trait WidgetIdFn<W>: FnOnce(&mut Ui) -> WidgetId<W> {}
|
||||
impl<W, F: FnOnce(&mut Ui) -> WidgetId<W>> WidgetIdFn<W> for F {}
|
||||
|
||||
pub trait WidgetRet: FnOnce(&mut Ui) -> WidgetId<AnyWidget> {}
|
||||
impl<F: FnOnce(&mut Ui) -> WidgetId<AnyWidget>> WidgetRet for F {}
|
||||
|
||||
impl<W: 'static> WidgetLike<IdTag> for WidgetId<W> {
|
||||
type Widget = W;
|
||||
fn add(self, _: &mut Ui) -> WidgetId<W> {
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
use crate::layout::{Len, Painter, SizeCtx, StaticWidgetId, Ui, WidgetId, WidgetIdFn};
|
||||
use crate::{
|
||||
core::WidgetPtr,
|
||||
layout::{Len, Painter, SizeCtx, StaticWidgetId, Ui, WidgetId, WidgetIdFn},
|
||||
};
|
||||
|
||||
use std::{any::Any, marker::PhantomData};
|
||||
|
||||
@@ -48,6 +51,12 @@ pub trait WidgetLike<Tag> {
|
||||
{
|
||||
ui.set_root(self);
|
||||
}
|
||||
fn set_ptr(self, ptr: &WidgetId<WidgetPtr>, ui: &mut Ui)
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
ui[ptr].inner = Some(self.add(ui).any());
|
||||
}
|
||||
}
|
||||
|
||||
/// A function that returns a widget given a UI.
|
||||
|
||||
Reference in New Issue
Block a user