80 lines
2.0 KiB
Rust
80 lines
2.0 KiB
Rust
use super::*;
|
|
use std::marker::Unsize;
|
|
|
|
pub trait WidgetLike<Tag> {
|
|
type Widget: Widget + ?Sized + Unsize<dyn Widget> + 'static;
|
|
|
|
fn add(self, ui: &mut Ui) -> WidgetRef<Self::Widget>;
|
|
|
|
fn with_id<W2>(
|
|
self,
|
|
f: impl FnOnce(&mut Ui, WidgetRef<Self::Widget>) -> WidgetRef<W2>,
|
|
) -> impl WidgetIdFn<W2>
|
|
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<const LEN: usize> {
|
|
pub arr: [WidgetRef; LEN],
|
|
}
|
|
|
|
impl<const LEN: usize> WidgetArr<LEN> {
|
|
pub fn new(arr: [WidgetRef; LEN]) -> Self {
|
|
Self { arr }
|
|
}
|
|
}
|
|
|
|
pub trait WidgetArrLike<const LEN: usize, Tag> {
|
|
fn ui(self, ui: &mut Ui) -> WidgetArr<LEN>;
|
|
}
|
|
|
|
impl<const LEN: usize> WidgetArrLike<LEN, ArrTag> for WidgetArr<LEN> {
|
|
fn ui(self, _: &mut Ui) -> WidgetArr<LEN> {
|
|
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);
|