Compare commits
1 Commits
d6a9711ceb
...
84c460a91f
| Author | SHA1 | Date | |
|---|---|---|---|
| 84c460a91f |
2
TODO
2
TODO
@@ -36,3 +36,5 @@ don't forget I'm streaming
|
|||||||
|
|
||||||
tags
|
tags
|
||||||
vecs for each widget type?
|
vecs for each widget type?
|
||||||
|
|
||||||
|
POTENTIAL BUG: closures that store IDs will not decrement the id!!! need to not increment id if moved into closure somehow??? wait no, need to decrement ID every time an event fn is added...... only if the id is used in it..??
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ impl Client {
|
|||||||
.stack()
|
.stack()
|
||||||
.add_static(&mut ui);
|
.add_static(&mut ui);
|
||||||
|
|
||||||
let btext = |content| text(content).size(30);
|
let btext = |content| wtext(content).size(30);
|
||||||
|
|
||||||
let text_test = (
|
let text_test = (
|
||||||
btext("this is a").align(Align::LEFT),
|
btext("this is a").align(Align::LEFT),
|
||||||
@@ -160,21 +160,21 @@ impl Client {
|
|||||||
)
|
)
|
||||||
.span(Dir::RIGHT)
|
.span(Dir::RIGHT)
|
||||||
.center(),
|
.center(),
|
||||||
text("pretty cool right?").size(50),
|
wtext("pretty cool right?").size(50),
|
||||||
)
|
)
|
||||||
.span(Dir::DOWN)
|
.span(Dir::DOWN)
|
||||||
.add_static(&mut ui);
|
.add_static(&mut ui);
|
||||||
|
|
||||||
let texts = Span::empty(Dir::DOWN).gap(10).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 msg_area = texts.scroll().masked().background(rect(Color::SKY));
|
||||||
let add_text = text("add")
|
let add_text = wtext("add")
|
||||||
.editable(false)
|
.editable(false)
|
||||||
.text_align(Align::LEFT)
|
.text_align(Align::LEFT)
|
||||||
.size(30)
|
.size(30)
|
||||||
.attr::<Selectable>(())
|
.attr::<Selectable>(())
|
||||||
.id_on(Submit, move |id, client: &mut Client, _| {
|
.id_on(Submit, move |id, client: &mut Client, _| {
|
||||||
let content = client.ui.text(id).take();
|
let content = client.ui.text(id).take();
|
||||||
let text = text(content)
|
let text = wtext(content)
|
||||||
.editable(false)
|
.editable(false)
|
||||||
.size(30)
|
.size(30)
|
||||||
.text_align(Align::LEFT)
|
.text_align(Align::LEFT)
|
||||||
@@ -226,7 +226,7 @@ impl Client {
|
|||||||
.edit_on(CursorSense::HoverEnd, move |r, _| {
|
.edit_on(CursorSense::HoverEnd, move |r, _| {
|
||||||
r.color = color;
|
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 = (
|
let tabs = (
|
||||||
@@ -242,7 +242,7 @@ impl Client {
|
|||||||
)
|
)
|
||||||
.span(Dir::RIGHT);
|
.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);
|
let info_sect = info.clone().pad(10).align(Align::RIGHT);
|
||||||
|
|
||||||
((tabs.height(40), main).span(Dir::DOWN), info_sect)
|
((tabs.height(40), main).span(Dir::DOWN), info_sect)
|
||||||
|
|||||||
@@ -39,6 +39,13 @@ pub struct Padding {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl 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 {
|
pub fn uniform(amt: impl UiNum) -> Self {
|
||||||
let amt = amt.to_f32();
|
let amt = amt.to_f32();
|
||||||
Self {
|
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 {
|
pub fn with_top(mut self, amt: impl UiNum) -> Self {
|
||||||
self.top = amt.to_f32();
|
self.top = amt.to_f32();
|
||||||
self
|
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 {
|
TextBuilder {
|
||||||
content: content.into(),
|
content: content.into(),
|
||||||
attrs: TextAttrs::default(),
|
attrs: TextAttrs::default(),
|
||||||
|
|||||||
@@ -15,7 +15,9 @@ pub trait CoreWidget<W, Tag> {
|
|||||||
fn scroll(self) -> impl WidgetIdFn<Scroll>;
|
fn scroll(self) -> impl WidgetIdFn<Scroll>;
|
||||||
fn masked(self) -> impl WidgetFn<Masked>;
|
fn masked(self) -> impl WidgetFn<Masked>;
|
||||||
fn background<T>(self, w: impl WidgetLike<T>) -> impl WidgetFn<Stack>;
|
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 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 {
|
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> {
|
fn layer_offset(self, offset: usize) -> impl WidgetFn<LayerOffset> {
|
||||||
move |ui| LayerOffset {
|
move |ui| LayerOffset {
|
||||||
inner: self.add(ui).any(),
|
inner: self.add(ui).any(),
|
||||||
offset,
|
offset,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn to_any(self) -> impl WidgetRet {
|
||||||
|
|ui| self.add(ui).any()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait CoreWidgetArr<const LEN: usize, Wa: WidgetArrLike<LEN, Tag>, Tag> {
|
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> {}
|
pub trait WidgetIdFn<W>: FnOnce(&mut Ui) -> WidgetId<W> {}
|
||||||
impl<W, F: FnOnce(&mut Ui) -> WidgetId<W>> WidgetIdFn<W> for F {}
|
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> {
|
impl<W: 'static> WidgetLike<IdTag> for WidgetId<W> {
|
||||||
type Widget = W;
|
type Widget = W;
|
||||||
fn add(self, _: &mut Ui) -> WidgetId<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};
|
use std::{any::Any, marker::PhantomData};
|
||||||
|
|
||||||
@@ -48,6 +51,12 @@ pub trait WidgetLike<Tag> {
|
|||||||
{
|
{
|
||||||
ui.set_root(self);
|
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.
|
/// A function that returns a widget given a UI.
|
||||||
|
|||||||
Reference in New Issue
Block a user