use super::SocketLayout;
pub struct SocketGrid<'a> {
layout: &'a mut SocketLayout,
}
impl SocketLayout {
pub fn grid<R>(
&mut self,
grid: egui::Grid,
ui: &mut egui::Ui,
content: impl FnOnce(&mut SocketGrid<'_>, &mut egui::Ui) -> R,
) -> egui::InnerResponse<R> {
grid.show(ui, |ui| {
let mut sg = SocketGrid { layout: self };
content(&mut sg, ui)
})
}
}
impl SocketGrid<'_> {
pub fn row<R>(
&mut self,
ui: &mut egui::Ui,
input: Option<usize>,
output: Option<usize>,
content: impl FnOnce(&mut egui::Ui) -> R,
) -> R {
let row_top = ui.cursor().top();
let r = content(ui);
ui.end_row();
let next_row_top = ui.cursor().top();
let spacing = ui.spacing().item_spacing.y;
let cross = row_top + (next_row_top - row_top - spacing) / 2.0;
if let Some(ix) = input {
self.layout.input_at(ix, cross);
}
if let Some(ix) = output {
self.layout.output_at(ix, cross);
}
r
}
}