TAG TECHNOLOGY

This commit is contained in:
2025-08-14 12:21:26 -04:00
parent 4d68fa476d
commit e41970287d
19 changed files with 267 additions and 165 deletions

39
src/core/trait_fns.rs Normal file
View 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(),
}
}
}