switch to element defined span lens + better size fn
This commit is contained in:
@@ -2,19 +2,21 @@ use super::*;
|
||||
use crate::prelude::*;
|
||||
|
||||
pub trait CoreWidget<W, Tag> {
|
||||
fn pad(self, padding: impl Into<Padding>) -> impl WidgetFn<Padded>;
|
||||
fn pad(self, padding: impl Into<Padding>) -> impl WidgetFn<Pad>;
|
||||
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 sized(self, size: impl Into<Size>) -> impl WidgetFn<Sized>;
|
||||
fn width(self, len: impl Into<Len>) -> impl WidgetFn<Sized>;
|
||||
fn height(self, len: impl Into<Len>) -> 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 {
|
||||
fn pad(self, padding: impl Into<Padding>) -> impl WidgetFn<Pad> {
|
||||
|ui| Pad {
|
||||
padding: padding.into(),
|
||||
inner: self.add(ui).any(),
|
||||
}
|
||||
@@ -39,10 +41,30 @@ impl<W: WidgetLike<Tag>, Tag> CoreWidget<W::Widget, Tag> for W {
|
||||
}
|
||||
}
|
||||
|
||||
fn sized(self, size: impl Into<Vec2>) -> impl WidgetFn<Sized> {
|
||||
fn sized(self, size: impl Into<Size>) -> impl WidgetFn<Sized> {
|
||||
let size = size.into();
|
||||
move |ui| Sized {
|
||||
inner: self.add(ui).any(),
|
||||
size: size.into(),
|
||||
x: Some(size.x),
|
||||
y: Some(size.y),
|
||||
}
|
||||
}
|
||||
|
||||
fn width(self, len: impl Into<Len>) -> impl WidgetFn<Sized> {
|
||||
let len = len.into();
|
||||
move |ui| Sized {
|
||||
inner: self.add(ui).any(),
|
||||
x: Some(len),
|
||||
y: None,
|
||||
}
|
||||
}
|
||||
|
||||
fn height(self, len: impl Into<Len>) -> impl WidgetFn<Sized> {
|
||||
let len = len.into();
|
||||
move |ui| Sized {
|
||||
inner: self.add(ui).any(),
|
||||
x: None,
|
||||
y: Some(len),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,15 +90,14 @@ impl<W: WidgetLike<Tag>, Tag> CoreWidget<W::Widget, Tag> for W {
|
||||
}
|
||||
|
||||
pub trait CoreWidgetArr<const LEN: usize, Wa: WidgetArrLike<LEN, Tag>, Tag> {
|
||||
fn span(self, dir: Dir, lengths: impl IntoSpanLens<LEN>) -> impl WidgetFn<Span>;
|
||||
fn span(self, dir: Dir) -> 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();
|
||||
fn span(self, dir: Dir) -> impl WidgetFn<Span> {
|
||||
move |ui| Span {
|
||||
children: self.ui(ui).arr.into_iter().zip(lengths).collect(),
|
||||
children: self.ui(ui).arr.to_vec(),
|
||||
dir,
|
||||
spacing: 0.0,
|
||||
}
|
||||
@@ -85,19 +106,3 @@ impl<const LEN: usize, Wa: WidgetArrLike<LEN, Tag>, Tag> CoreWidgetArr<LEN, Wa,
|
||||
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]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user