TAG TECHNOLOGY
This commit is contained in:
39
src/core/trait_fns.rs
Normal file
39
src/core/trait_fns.rs
Normal file
@@ -0,0 +1,39 @@
|
||||
use super::*;
|
||||
use crate::{UiRegion, Vec2, WidgetArrLike, WidgetFn, WidgetLike};
|
||||
|
||||
pub trait CoreWidget<Ctx: 'static, Tag> {
|
||||
fn pad(self, padding: impl Into<Padding>) -> impl WidgetFn<Regioned, Ctx>;
|
||||
fn center(self, size: impl Into<Vec2>) -> impl WidgetFn<Regioned, Ctx>;
|
||||
}
|
||||
|
||||
impl<W: WidgetLike<Ctx, Tag>, Ctx: 'static, Tag> CoreWidget<Ctx, Tag> for W {
|
||||
fn pad(self, padding: impl Into<Padding>) -> impl WidgetFn<Regioned, Ctx> {
|
||||
|ui| Regioned {
|
||||
region: padding.into().region(),
|
||||
inner: self.add(ui).erase_type(),
|
||||
}
|
||||
}
|
||||
|
||||
fn center(self, size: impl Into<Vec2>) -> impl WidgetFn<Regioned, Ctx> {
|
||||
|ui| Regioned {
|
||||
region: UiRegion::center(size.into()),
|
||||
inner: self.add(ui).erase_type(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait CoreWidgetArr<const LEN: usize, Ctx: 'static, Tag> {
|
||||
fn span(self, dir: Dir, lengths: [impl Into<SpanLen>; LEN]) -> impl WidgetFn<Span, Ctx>;
|
||||
}
|
||||
|
||||
impl<const LEN: usize, Wa: WidgetArrLike<LEN, Ctx, Tag>, Ctx: 'static, Tag> CoreWidgetArr<LEN, Ctx, Tag>
|
||||
for Wa
|
||||
{
|
||||
fn span(self, dir: Dir, lengths: [impl Into<SpanLen>; LEN]) -> impl WidgetFn<Span, Ctx> {
|
||||
let lengths = lengths.map(Into::into);
|
||||
move |ui| Span {
|
||||
dir,
|
||||
children: self.ui(ui).arr.into_iter().zip(lengths).collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user