pub mod grid;
use crate::styles::typography;
use crate::tokens::DESIGN_TOKENS;
use egui::{RichText, Ui};
use egui_extras::{Size, StripBuilder};
pub use grid::FormGrid;
pub struct FormRow<'a> {
label: &'a str,
description: Option<&'a str>,
label_width: f32,
}
impl<'a> FormRow<'a> {
pub fn new(label: &'a str) -> Self {
Self {
label,
description: None,
label_width: DESIGN_TOKENS.sizing.settings_dialog.label_width,
}
}
pub fn description(mut self, desc: &'a str) -> Self {
self.description = Some(desc);
self
}
pub fn label_width(mut self, width: f32) -> Self {
self.label_width = width;
self
}
pub fn show(self, ui: &mut Ui, add_widget: impl FnOnce(&mut Ui)) {
StripBuilder::new(ui)
.size(Size::exact(self.label_width))
.size(Size::remainder())
.horizontal(|mut strip| {
strip.cell(|ui| {
ui.vertical(|ui| {
ui.label(self.label);
if let Some(desc) = self.description {
ui.label(
RichText::new(desc)
.size(typography::SM)
.color(DESIGN_TOKENS.semantic.ui.text_muted_dark),
);
}
});
});
strip.cell(|ui| {
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
add_widget(ui);
});
});
});
ui.add_space(DESIGN_TOKENS.spacing.sm);
}
}