111 lines
3.4 KiB
Rust
111 lines
3.4 KiB
Rust
use super::{_ConstMutSwitchUiCallback, ConstMutSwitchUi, ConstRef, ConstUI, MutRef, MutUI, RefType};
|
|
use eframe::egui::Ui;
|
|
use egui_extras::{Column, TableBuilder, TableRow};
|
|
use std::marker::PhantomData;
|
|
|
|
pub trait _ConstMutSwitchUiTableBaseCallback<RefType: super::RefType> {
|
|
type Header: _ConstMutSwitchUiTableRowCallback<RefType>;
|
|
type Body: _ConstMutSwitchUiTableRowCallback<RefType>;
|
|
|
|
fn header_to_body<'a>(
|
|
header: &mut <Self::Header as _ConstMutSwitchUiTableRowCallback<RefType>>::Clojure<'a>,
|
|
) -> impl Iterator<Item = <Self::Body as _ConstMutSwitchUiTableRowCallback<RefType>>::Clojure<'a>>;
|
|
}
|
|
|
|
pub trait _ConstMutSwitchUiTableRowCallback<RefType: super::RefType> {
|
|
type Clojure<'a>;
|
|
|
|
fn render_row<Row: ConstMutSwitchUiTableRow<RefType = RefType>>(
|
|
row: &mut Row,
|
|
clojure: &mut Self::Clojure<'_>,
|
|
);
|
|
}
|
|
|
|
pub trait ConstMutSwitchUiTableRow {
|
|
type RefType: RefType;
|
|
|
|
fn cell<F: _ConstMutSwitchUiCallback<Self::RefType>>(&mut self, clojure: &mut F::Clojure<'_>);
|
|
}
|
|
|
|
pub(super) struct ConstMutSwitchUiTableRowImpl<
|
|
'a,
|
|
'b,
|
|
RefType: super::RefType,
|
|
Constructor: __SwitchUiConstructor1<RefType>,
|
|
> {
|
|
row: TableRow<'a, 'b>,
|
|
__phantom: PhantomData<(Constructor, RefType)>,
|
|
}
|
|
|
|
impl<RefType: super::RefType, Constructor: __SwitchUiConstructor1<RefType>> ConstMutSwitchUiTableRow
|
|
for ConstMutSwitchUiTableRowImpl<'_, '_, RefType, Constructor>
|
|
{
|
|
type RefType = RefType;
|
|
|
|
fn cell<F: _ConstMutSwitchUiCallback<Self::RefType>>(&mut self, clojure: &mut F::Clojure<'_>) {
|
|
self.row
|
|
.col(|ui| F::render(&mut Constructor::__wrap(ui), clojure));
|
|
}
|
|
}
|
|
|
|
trait __SwitchUiConstructor1<RefType: super::RefType> {
|
|
type Ctx<'a>: ConstMutSwitchUi<RefType = RefType>;
|
|
|
|
fn __wrap<'a>(ui: &'a mut Ui) -> Self::Ctx<'a>;
|
|
}
|
|
|
|
impl __SwitchUiConstructor1<ConstRef> for ConstUI<'_> {
|
|
type Ctx<'a> = ConstUI<'a>;
|
|
|
|
fn __wrap<'a>(ui: &'a mut Ui) -> Self::Ctx<'a> {
|
|
todo!()
|
|
}
|
|
}
|
|
impl __SwitchUiConstructor1<MutRef> for MutUI<'_> {
|
|
type Ctx<'a> = MutUI<'a>;
|
|
|
|
fn __wrap<'a>(ui: &'a mut Ui) -> Self::Ctx<'a> {
|
|
todo!()
|
|
}
|
|
}
|
|
|
|
pub(super) fn render_table<
|
|
'a,
|
|
Ctx: ConstMutSwitchUi,
|
|
F: _ConstMutSwitchUiTableBaseCallback<Ctx::RefType>,
|
|
Constructor: __SwitchUiConstructor1<Ctx::RefType>,
|
|
>(
|
|
ui: &mut Ui,
|
|
vscroll: bool,
|
|
columnsCount: usize,
|
|
headerClojure: &mut <F::Header as _ConstMutSwitchUiTableRowCallback<Ctx::RefType>>::Clojure<'_>,
|
|
) {
|
|
TableBuilder::new(ui)
|
|
.striped(true) // Alternating row colors
|
|
.resizable(true)
|
|
.vscroll(vscroll)
|
|
.columns(Column::remainder(), columnsCount)
|
|
.header(20.0, |row| {
|
|
F::Header::render_row(
|
|
&mut ConstMutSwitchUiTableRowImpl::<_, Constructor> {
|
|
row,
|
|
__phantom: PhantomData::default(),
|
|
},
|
|
headerClojure,
|
|
)
|
|
})
|
|
.body(|mut body| {
|
|
for mut rowData in F::header_to_body(headerClojure) {
|
|
body.row(20.0, |row| {
|
|
F::Body::render_row(
|
|
&mut ConstMutSwitchUiTableRowImpl::<_, Constructor> {
|
|
row,
|
|
__phantom: PhantomData::default(),
|
|
},
|
|
&mut rowData,
|
|
)
|
|
});
|
|
}
|
|
});
|
|
}
|