spans now good (other than direction) + refactor
This commit is contained in:
37
src/base/trait_fns.rs
Normal file
37
src/base/trait_fns.rs
Normal file
@@ -0,0 +1,37 @@
|
||||
use super::*;
|
||||
use crate::{UIRegion, Vec2, WidgetArrLike, WidgetFn, WidgetLike};
|
||||
|
||||
pub trait WidgetUtil {
|
||||
fn pad(self, padding: impl Into<Padding>) -> impl WidgetLike<Widget = Regioned>;
|
||||
fn center(self, size: impl Into<Vec2>) -> impl WidgetLike<Widget = Regioned>;
|
||||
}
|
||||
|
||||
impl<W: WidgetLike> WidgetUtil for W {
|
||||
fn pad(self, padding: impl Into<Padding>) -> impl WidgetLike<Widget = Regioned> {
|
||||
WidgetFn(|ui| Regioned {
|
||||
region: padding.into().region(),
|
||||
inner: self.add(ui).erase_type(),
|
||||
})
|
||||
}
|
||||
|
||||
fn center(self, size: impl Into<Vec2>) -> impl WidgetLike<Widget = Regioned> {
|
||||
WidgetFn(|ui| Regioned {
|
||||
region: UIRegion::center(size.into()),
|
||||
inner: self.add(ui).erase_type(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub trait WidgetArrUtil<const LEN: usize> {
|
||||
fn span(self, dir: Dir, lengths: [impl Into<SpanLen>; LEN]) -> impl WidgetLike<Widget = Span>;
|
||||
}
|
||||
|
||||
impl<const LEN: usize, Wa: WidgetArrLike<LEN>> WidgetArrUtil<LEN> for Wa {
|
||||
fn span(self, dir: Dir, lengths: [impl Into<SpanLen>; LEN]) -> impl WidgetLike<Widget = Span> {
|
||||
let lengths = lengths.map(Into::into);
|
||||
WidgetFn(move |ui| Span {
|
||||
dir,
|
||||
children: self.ui(ui).arr.into_iter().zip(lengths).collect(),
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user