use crate::tokens::DESIGN_TOKENS;
use egui::Ui;
pub struct FormGrid {
id: String,
columns: usize,
h_spacing: f32,
v_spacing: f32,
}
impl FormGrid {
pub fn new(id: impl Into<String>) -> Self {
Self {
id: id.into(),
columns: 2,
h_spacing: DESIGN_TOKENS.spacing.lg,
v_spacing: DESIGN_TOKENS.spacing.md,
}
}
#[must_use]
pub fn columns(mut self, n: usize) -> Self {
self.columns = n;
self
}
#[must_use]
pub fn spacing(mut self, h: f32, v: f32) -> Self {
self.h_spacing = h;
self.v_spacing = v;
self
}
pub fn show(self, ui: &mut Ui, add_contents: impl FnOnce(&mut Ui)) {
egui::Grid::new(self.id)
.num_columns(self.columns)
.spacing([self.h_spacing, self.v_spacing])
.show(ui, add_contents);
}
}