alignment!!!
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
use super::*;
|
||||
use crate::layout::{
|
||||
Dir, UiPos, UiRegion, Vec2, WidgetArrLike, WidgetFnRet, WidgetIdFnRet, WidgetLike,
|
||||
};
|
||||
use crate::prelude::*;
|
||||
|
||||
pub trait CoreWidget<W, Tag> {
|
||||
fn pad(self, padding: impl Into<Padding>) -> WidgetFnRet!(Regioned);
|
||||
fn center(self, size: impl Into<Vec2>) -> WidgetFnRet!(Regioned);
|
||||
fn align(self, align: Align) -> WidgetFnRet!(Aligned);
|
||||
fn center(self) -> WidgetFnRet!(Aligned);
|
||||
fn region(self, region: UiRegion) -> WidgetFnRet!(Regioned);
|
||||
fn label(self, label: impl Into<String>) -> WidgetIdFnRet!(W);
|
||||
fn sized(self, size: impl Into<Vec2>) -> WidgetFnRet!(Sized);
|
||||
}
|
||||
|
||||
impl<W: WidgetLike<Tag>, Tag> CoreWidget<W::Widget, Tag> for W {
|
||||
@@ -18,13 +18,17 @@ impl<W: WidgetLike<Tag>, Tag> CoreWidget<W::Widget, Tag> for W {
|
||||
}
|
||||
}
|
||||
|
||||
fn center(self, size: impl Into<Vec2>) -> WidgetFnRet!(Regioned) {
|
||||
|ui| Regioned {
|
||||
region: UiPos::center().expand(size.into()),
|
||||
fn align(self, align: Align) -> WidgetFnRet!(Aligned) {
|
||||
move |ui| Aligned {
|
||||
inner: self.add(ui).erase_type(),
|
||||
align,
|
||||
}
|
||||
}
|
||||
|
||||
fn center(self) -> WidgetFnRet!(Aligned) {
|
||||
self.align(Align::Center)
|
||||
}
|
||||
|
||||
fn region(self, region: UiRegion) -> WidgetFnRet!(Regioned) {
|
||||
move |ui| Regioned {
|
||||
region,
|
||||
@@ -39,19 +43,26 @@ impl<W: WidgetLike<Tag>, Tag> CoreWidget<W::Widget, Tag> for W {
|
||||
id
|
||||
}
|
||||
}
|
||||
|
||||
fn sized(self, size: impl Into<Vec2>) -> WidgetFnRet!(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 Into<SpanLen>; LEN]) -> WidgetFnRet!(Span);
|
||||
fn span(self, dir: Dir, lengths: impl IntoSpanLens<LEN>) -> WidgetFnRet!(Span);
|
||||
fn stack(self) -> WidgetFnRet!(Stack);
|
||||
}
|
||||
|
||||
impl<const LEN: usize, Wa: WidgetArrLike<LEN, Tag>, Tag> CoreWidgetArr<LEN, Tag> for Wa {
|
||||
fn span(self, dir: Dir, lengths: [impl Into<SpanLen>; LEN]) -> WidgetFnRet!(Span) {
|
||||
let lengths = lengths.map(Into::into);
|
||||
fn span(self, dir: Dir, lengths: impl IntoSpanLens<LEN>) -> WidgetFnRet!(Span) {
|
||||
let lengths = lengths.into_lens();
|
||||
move |ui| Span {
|
||||
dir,
|
||||
children: self.ui(ui).arr.into_iter().zip(lengths).collect(),
|
||||
dir,
|
||||
}
|
||||
}
|
||||
fn stack(self) -> WidgetFnRet!(Stack) {
|
||||
@@ -60,3 +71,37 @@ impl<const LEN: usize, Wa: WidgetArrLike<LEN, Tag>, Tag> CoreWidgetArr<LEN, Tag>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// pub struct SpanBuilder<const LEN: usize, Tag, Wa: WidgetArrLike<LEN, Tag>> {
|
||||
// children: Wa,
|
||||
// dir: Dir,
|
||||
// align: Align,
|
||||
// }
|
||||
//
|
||||
// impl WidgetLike<FnTag> for SpanBuilder {
|
||||
// type Widget = Span;
|
||||
//
|
||||
// fn add(self, ui: &mut Ui) -> WidgetId<Self::Widget> {
|
||||
// ui.add_widget(Span {
|
||||
// children: self.children,
|
||||
// dir: self.dir,
|
||||
// align: self.align,
|
||||
// })
|
||||
// }
|
||||
// }
|
||||
|
||||
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