54 lines
1.8 KiB
Rust
54 lines
1.8 KiB
Rust
use super::*;
|
|
use crate::{UiRegion, Vec2, WidgetArrLike, WidgetFnRet, WidgetLike};
|
|
|
|
pub trait CoreWidget<W: 'static, Ctx: 'static, Tag> {
|
|
fn pad(self, padding: impl Into<Padding>) -> WidgetFnRet!(Regioned, Ctx);
|
|
fn center(self, size: impl Into<Vec2>) -> WidgetFnRet!(Regioned, Ctx);
|
|
fn region(self, region: UiRegion) -> WidgetFnRet!(Regioned, Ctx);
|
|
}
|
|
|
|
impl<W: WidgetLike<Ctx, Tag>, Ctx: 'static, Tag> CoreWidget<W::Widget, Ctx, Tag> for W {
|
|
fn pad(self, padding: impl Into<Padding>) -> WidgetFnRet!(Regioned, Ctx) {
|
|
|ui| Regioned {
|
|
region: padding.into().region(),
|
|
inner: self.add(ui).erase_type(),
|
|
}
|
|
}
|
|
|
|
fn center(self, size: impl Into<Vec2>) -> WidgetFnRet!(Regioned, Ctx) {
|
|
|ui| Regioned {
|
|
region: UiRegion::center().size(size.into()),
|
|
inner: self.add(ui).erase_type(),
|
|
}
|
|
}
|
|
|
|
fn region(self, region: UiRegion) -> WidgetFnRet!(Regioned, Ctx) {
|
|
move |ui| Regioned {
|
|
region,
|
|
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]) -> WidgetFnRet!(Span, Ctx);
|
|
fn stack(self) -> WidgetFnRet!(Stack, 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]) -> WidgetFnRet!(Span, Ctx) {
|
|
let lengths = lengths.map(Into::into);
|
|
move |ui| Span {
|
|
dir,
|
|
children: self.ui(ui).arr.into_iter().zip(lengths).collect(),
|
|
}
|
|
}
|
|
fn stack(self) -> WidgetFnRet!(Stack, Ctx) {
|
|
move |ui| Stack {
|
|
children: self.ui(ui).arr.to_vec(),
|
|
}
|
|
}
|
|
}
|