use super::*; use std::marker::Unsize; pub trait WidgetLike { type Widget: Widget + ?Sized + Unsize + 'static; fn add(self, ui: &mut Ui) -> WidgetRef; fn with_id( self, f: impl FnOnce(&mut Ui, WidgetRef) -> WidgetRef, ) -> impl WidgetIdFn where Self: Sized, { move |ui| { let id = self.add(ui); f(ui, id) } } fn set_root(self, ui: &mut Ui) where Self: Sized, { ui.set_root(self); } } pub struct WidgetArr { pub arr: [WidgetRef; LEN], } impl WidgetArr { pub fn new(arr: [WidgetRef; LEN]) -> Self { Self { arr } } } pub trait WidgetArrLike { fn ui(self, ui: &mut Ui) -> WidgetArr; } impl WidgetArrLike for WidgetArr { fn ui(self, _: &mut Ui) -> WidgetArr { self } } // I hate this language it's so bad why do I even use it macro_rules! impl_widget_arr { ($n:expr;$($W:ident)*) => { impl_widget_arr!($n;$($W)*;$(${concat($W,Tag)})*); }; ($n:expr;$($W:ident)*;$($Tag:ident)*) => { impl<$($W: WidgetLike<$Tag>,$Tag,)*> WidgetArrLike<$n, ($($Tag,)*)> for ($($W,)*) { fn ui(self, ui: &mut Ui) -> WidgetArr<$n> { #[allow(non_snake_case)] let ($($W,)*) = self; WidgetArr::new( [$($W.add(ui),)*], ) } } }; } impl_widget_arr!(1;A); impl_widget_arr!(2;A B); impl_widget_arr!(3;A B C); impl_widget_arr!(4;A B C D); impl_widget_arr!(5;A B C D E); impl_widget_arr!(6;A B C D E F); impl_widget_arr!(7;A B C D E F G); impl_widget_arr!(8;A B C D E F G H); impl_widget_arr!(9;A B C D E F G H I); impl_widget_arr!(10;A B C D E F G H I J); impl_widget_arr!(11;A B C D E F G H I J K); impl_widget_arr!(12;A B C D E F G H I J K L);