82 lines
2.3 KiB
Rust
82 lines
2.3 KiB
Rust
use super::*;
|
|
use crate::prelude::*;
|
|
|
|
pub trait CoreWidget<W, Tag> {
|
|
fn pad(self, padding: impl Into<Padding>) -> impl WidgetFn<Padded>;
|
|
fn align(self, align: Align) -> impl WidgetFn<Aligned>;
|
|
fn center(self) -> impl WidgetFn<Aligned>;
|
|
fn label(self, label: impl Into<String>) -> impl WidgetIdFn<W>;
|
|
fn size(self, size: impl Into<Vec2>) -> impl WidgetFn<Sized>;
|
|
}
|
|
|
|
impl<W: WidgetLike<Tag>, Tag> CoreWidget<W::Widget, Tag> for W {
|
|
fn pad(self, padding: impl Into<Padding>) -> impl WidgetFn<Padded> {
|
|
|ui| Padded {
|
|
padding: padding.into(),
|
|
inner: self.add(ui).erase_type(),
|
|
}
|
|
}
|
|
|
|
fn align(self, align: Align) -> impl WidgetFn<Aligned> {
|
|
move |ui| Aligned {
|
|
inner: self.add(ui).erase_type(),
|
|
align,
|
|
}
|
|
}
|
|
|
|
fn center(self) -> impl WidgetFn<Aligned> {
|
|
self.align(Align::Center)
|
|
}
|
|
|
|
fn label(self, label: impl Into<String>) -> impl WidgetIdFn<W::Widget> {
|
|
|ui| {
|
|
let id = self.add(ui);
|
|
ui.set_label(&id, label.into());
|
|
id
|
|
}
|
|
}
|
|
|
|
fn size(self, size: impl Into<Vec2>) -> impl WidgetFn<Sized> {
|
|
move |ui| Sized {
|
|
inner: self.add(ui).erase_type(),
|
|
size: size.into(),
|
|
}
|
|
}
|
|
}
|
|
|
|
pub trait CoreWidgetArr<const LEN: usize, Tag> {
|
|
fn span(self, dir: Dir, lengths: impl IntoSpanLens<LEN>) -> impl WidgetFn<Span>;
|
|
fn stack(self) -> impl WidgetFn<Stack>;
|
|
}
|
|
|
|
impl<const LEN: usize, Wa: WidgetArrLike<LEN, Tag>, Tag> CoreWidgetArr<LEN, Tag> for Wa {
|
|
fn span(self, dir: Dir, lengths: impl IntoSpanLens<LEN>) -> impl WidgetFn<Span> {
|
|
let lengths = lengths.into_lens();
|
|
move |ui| Span {
|
|
children: self.ui(ui).arr.into_iter().zip(lengths).collect(),
|
|
dir,
|
|
}
|
|
}
|
|
fn stack(self) -> impl WidgetFn<Stack> {
|
|
move |ui| Stack {
|
|
children: self.ui(ui).arr.to_vec(),
|
|
}
|
|
}
|
|
}
|
|
|
|
pub trait IntoSpanLens<const LEN: usize> {
|
|
fn into_lens(self) -> [SpanLen; LEN];
|
|
}
|
|
|
|
impl<const LEN: usize, T: Into<SpanLen>> IntoSpanLens<LEN> for [T; LEN] {
|
|
fn into_lens(self) -> [SpanLen; LEN] {
|
|
self.map(Into::into)
|
|
}
|
|
}
|
|
|
|
impl<const LEN: usize> IntoSpanLens<LEN> for SpanLen {
|
|
fn into_lens(self) -> [SpanLen; LEN] {
|
|
[self; LEN]
|
|
}
|
|
}
|