Gunnar

mikronova/kyokkou

src/common.rs

/// Shared traits and types used across all scene categories.

/// Validation result for a scene config.
#[derive(Debug, Clone, PartialEq)]
pub enum ValidationStatus {
    Ok,
    Warning(String),
    Error(String),
}

/// Every scene category implements this trait.
pub trait Scene {
    fn name(&self) -> &str;
    fn validate(&self) -> Vec<ValidationStatus>;
    fn is_renderable(&self) -> bool {
        self.validate()
            .iter()
            .all(|s| !matches!(s, ValidationStatus::Error(_)))
    }
    fn show(&mut self, ui: &mut egui::Ui) -> Option<String>;
}

/// Show validation badges inline — green / yellow / red.
pub fn show_validation(ui: &mut egui::Ui, statuses: &[ValidationStatus]) {
    for status in statuses {
        match status {
            ValidationStatus::Ok => {
                ui.colored_label(egui::Color32::GREEN, "✔ ok");
            }
            ValidationStatus::Warning(msg) => {
                ui.colored_label(egui::Color32::YELLOW, format!("⚠ {msg}"));
            }
            ValidationStatus::Error(msg) => {
                ui.colored_label(egui::Color32::RED, format!("✘ {msg}"));
            }
        }
    }
}

/// Render button — locked when validation has errors.
pub fn render_button(ui: &mut egui::Ui, renderable: bool) -> bool {
    ui.add_enabled(renderable, egui::Button::new("▶  Create image")).clicked()
}