widget fn ret macro
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use super::*;
|
||||
use crate::{UIRegion, Ui, Vec2, WidgetArrLike, WidgetFn, WidgetLike};
|
||||
use crate::{UIRegion, Ui, Vec2, WidgetArrLike, WidgetFn, WidgetFnRet, WidgetLike};
|
||||
|
||||
pub trait BaseWidget {
|
||||
fn pad(self, padding: impl Into<Padding>) -> impl WidgetLike<Widget = Regioned>;
|
||||
@@ -23,19 +23,11 @@ impl<W: WidgetLike> BaseWidget for W {
|
||||
}
|
||||
|
||||
pub trait BaseWidgetArr<const LEN: usize> {
|
||||
fn span(
|
||||
self,
|
||||
dir: Dir,
|
||||
lengths: [impl Into<SpanLen>; LEN],
|
||||
) -> WidgetFn<impl FnOnce(&mut Ui) -> Span, Span>;
|
||||
fn span(self, dir: Dir, lengths: [impl Into<SpanLen>; LEN]) -> WidgetFnRet!(Span);
|
||||
}
|
||||
|
||||
impl<const LEN: usize, Wa: WidgetArrLike<LEN>> BaseWidgetArr<LEN> for Wa {
|
||||
fn span(
|
||||
self,
|
||||
dir: Dir,
|
||||
lengths: [impl Into<SpanLen>; LEN],
|
||||
) -> WidgetFn<impl FnOnce(&mut Ui) -> Span, Span> {
|
||||
fn span(self, dir: Dir, lengths: [impl Into<SpanLen>; LEN]) -> WidgetFnRet!(Span) {
|
||||
let lengths = lengths.map(Into::into);
|
||||
WidgetFn(move |ui| Span {
|
||||
dir,
|
||||
|
||||
@@ -59,9 +59,17 @@ pub trait WidgetLike {
|
||||
/// A function that returns a widget given a UI.
|
||||
/// Useful for defining trait functions on widgets that create a parent widget so that the children
|
||||
/// don't need to be IDs yet
|
||||
pub trait WFn<W> = FnOnce(&mut Ui) -> W;
|
||||
pub struct WidgetFn<F: FnOnce(&mut Ui) -> W, W>(pub F);
|
||||
pub struct WidgetIdFn<F: FnOnce(&mut Ui) -> WidgetId<W>, W>(pub F);
|
||||
|
||||
macro_rules! WidgetFnRet {
|
||||
($W:ident) => {
|
||||
WidgetFn<impl FnOnce(&mut Ui) -> $W, $W>
|
||||
};
|
||||
}
|
||||
pub(crate) use WidgetFnRet;
|
||||
|
||||
pub trait _WidgetFn<W: Widget> {
|
||||
fn call(ui: &mut Ui) -> W;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user