104 lines
3.0 KiB
Rust
104 lines
3.0 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 sized(self, size: impl Into<Vec2>) -> impl WidgetFn<Sized>;
|
|
fn offset(self, amt: impl Into<UiVec2>) -> impl WidgetFn<Offset>;
|
|
fn scroll(self) -> impl WidgetIdFn<Offset>;
|
|
fn masked(self) -> impl WidgetFn<Masked>;
|
|
}
|
|
|
|
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).any(),
|
|
}
|
|
}
|
|
|
|
fn align(self, align: Align) -> impl WidgetFn<Aligned> {
|
|
move |ui| Aligned {
|
|
inner: self.add(ui).any(),
|
|
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 sized(self, size: impl Into<Vec2>) -> impl WidgetFn<Sized> {
|
|
move |ui| Sized {
|
|
inner: self.add(ui).any(),
|
|
size: size.into(),
|
|
}
|
|
}
|
|
|
|
fn offset(self, amt: impl Into<UiVec2>) -> impl WidgetFn<Offset> {
|
|
move |ui| Offset {
|
|
inner: self.add(ui).any(),
|
|
amt: amt.into(),
|
|
}
|
|
}
|
|
|
|
fn scroll(self) -> impl WidgetIdFn<Offset> {
|
|
self.offset(UiVec2::ZERO)
|
|
.edit_on(CursorSense::Scroll, |w, data| {
|
|
w.amt += UiVec2::abs(data.scroll_delta * 50.0);
|
|
})
|
|
}
|
|
|
|
fn masked(self) -> impl WidgetFn<Masked> {
|
|
move |ui| Masked {
|
|
inner: self.add(ui).any(),
|
|
}
|
|
}
|
|
}
|
|
|
|
pub trait CoreWidgetArr<const LEN: usize, Wa: WidgetArrLike<LEN, Tag>, Tag> {
|
|
fn span(self, dir: Dir, lengths: impl IntoSpanLens<LEN>) -> impl WidgetFn<Span>;
|
|
fn stack(self) -> StackBuilder<LEN, Wa, Tag>;
|
|
}
|
|
|
|
impl<const LEN: usize, Wa: WidgetArrLike<LEN, Tag>, Tag> CoreWidgetArr<LEN, Wa, 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,
|
|
spacing: 0.0,
|
|
}
|
|
}
|
|
fn stack(self) -> StackBuilder<LEN, Wa, Tag> {
|
|
StackBuilder::new(self)
|
|
}
|
|
}
|
|
|
|
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]
|
|
}
|
|
}
|