RE ADD CONTEXT

This commit is contained in:
2025-12-15 21:50:53 -05:00
parent dc2be7f688
commit 0b8a93c5ce
39 changed files with 925 additions and 713 deletions

View File

@@ -1,48 +1,48 @@
use super::*;
use std::marker::Unsize;
pub trait WidgetLike<Tag>: Sized {
type Widget: Widget + ?Sized + Unsize<dyn Widget> + 'static;
pub trait WidgetLike<State: 'static, Tag>: Sized {
type Widget: Widget<State> + ?Sized + Unsize<dyn Widget<State>> + 'static;
fn add(self, ui: &mut Ui) -> WidgetHandle<Self::Widget>;
fn add(self, ui: &mut Ui<State>) -> WidgetHandle<State, Self::Widget>;
fn with_id<W2>(
self,
f: impl FnOnce(&mut Ui, WidgetHandle<Self::Widget>) -> WidgetHandle<W2>,
) -> impl WidgetIdFn<W2> {
f: impl FnOnce(&mut Ui<State>, WidgetHandle<State, Self::Widget>) -> WidgetHandle<State, W2>,
) -> impl WidgetIdFn<State, W2> {
move |ui| {
let id = self.add(ui);
f(ui, id)
}
}
fn set_root(self, ui: &mut Ui) {
fn set_root(self, ui: &mut Ui<State>) {
ui.set_root(self);
}
fn handles(self, ui: &mut Ui) -> WidgetHandles<Self::Widget> {
fn handles(self, ui: &mut Ui<State>) -> WidgetHandles<State, Self::Widget> {
self.add(ui).handles()
}
}
pub trait WidgetArrLike<const LEN: usize, Tag> {
fn ui(self, ui: &mut Ui) -> WidgetArr<LEN>;
pub trait WidgetArrLike<State, const LEN: usize, Tag> {
fn ui(self, ui: &mut Ui<State>) -> WidgetArr<State, LEN>;
}
impl<const LEN: usize> WidgetArrLike<LEN, ArrTag> for WidgetArr<LEN> {
fn ui(self, _: &mut Ui) -> WidgetArr<LEN> {
impl<State, const LEN: usize> WidgetArrLike<State, LEN, ArrTag> for WidgetArr<State, LEN> {
fn ui(self, _: &mut Ui<State>) -> WidgetArr<State, LEN> {
self
}
}
// I hate this language it's so bad why do I even use it
// variadic generics please save us
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> {
impl<State: 'static, $($W: WidgetLike<State, $Tag>,$Tag,)*> WidgetArrLike<State, $n, ($($Tag,)*)> for ($($W,)*) {
fn ui(self, ui: &mut Ui<State>) -> WidgetArr<State, $n> {
#[allow(non_snake_case)]
let ($($W,)*) = self;
WidgetArr::new(