BREP_app 0.35.0

The next.BREP.io CAD application on the Rust B-rep kernel: an eframe (egui + wgpu) host that draws the brep-render 3D engine into an egui frame, native + wasm from one codebase.
Documentation
//! The developer UI gallery (`ui.gallery`): the UI refresh's components, the
//! four open decisions and the whole-app preview of the theme.
use crate::automation::command::{app_command, parse_args, CommandSpec, Ctx, Outcome};
use crate::ui_kit::preview::{FontChoice, LightScope, View};
use serde::Deserialize;
use serde_json::{json, Value};

/// The default density (decision 3).
#[derive(Debug, Clone, Copy, Deserialize, schemars::JsonSchema)]
#[serde(rename_all = "lowercase")]
pub enum DensityArg {
    Compact,
    Comfortable,
}

#[derive(Deserialize, schemars::JsonSchema)]
#[serde(deny_unknown_fields)]
pub struct GalleryArgs {
    /// Open or close the gallery window. Absent keeps it as it is.
    pub open: Option<bool>,
    /// Preview the theme on the whole app (never saved; off at start-up). Off
    /// restores the styles and fonts the app had.
    pub preview: Option<bool>,
    /// Decision 1, the font: A ships a UI font (previewed from the file
    /// `BREP_UI_PREVIEW_FONT` names, or an installed Inter), B is the OS's UI font.
    pub font: Option<FontChoice>,
    /// Decision 2, the accent colour: blue (proposed), brand, teal, violet, orange, green.
    pub accent: Option<String>,
    /// Decision 3, the default density.
    pub density: Option<DensityArg>,
    /// Decision 4, the light theme: `now` (in the first release) or `later`
    /// (dark only first; light keeps today's look in the preview).
    pub light: Option<LightScope>,
    /// The theme the gallery window is drawn in: `app` (the app's), `dark`, `light`.
    pub view: Option<View>,
    /// Fill the whole window with the gallery (captures).
    pub maximized: Option<bool>,
    /// Turn every transition off.
    pub reduce_motion: Option<bool>,
}

fn gallery_result_schema() -> Value {
    let string = || json!({"type":"string"});
    let boolean = || json!({"type":"boolean"});
    let number = || json!({"type":"number"});
    let object = |properties: Value| {
        let required: Vec<String> = properties.as_object().map(|o| o.keys().cloned().collect()).unwrap_or_default();
        json!({"type":"object","properties":properties,"required":required,"additionalProperties":false})
    };
    object(json!({
        "open": boolean(),
        "preview": boolean(),
        "previewApplied": boolean(),
        "font": {"type":"string","enum":["A","B"]},
        "fontDescription": string(),
        "accent": object(json!({"key": string(), "label": string(), "hex": string()})),
        "density": {"type":"string","enum":["compact","comfortable"]},
        "light": {"type":"string","enum":["now","later"]},
        "view": {"type":"string","enum":["app","dark","light"]},
        "mode": {"type":"string","enum":["dark","light"]},
        "maximized": boolean(),
        "reduceMotion": boolean(),
        "summary": string(),
        "tokens": object(json!({
            "bgApp": string(), "bgPanel": string(), "bgRaised": string(), "bgInput": string(),
            "textPrimary": string(), "textSecondary": string(),
            "accent": string(), "accentFill": string(), "accentText": string(), "accentRing": string(),
            "controlHeight": number(), "whiteOnAccent": number(), "whiteOnAccentFill": number(),
        })),
        "demo": object(json!({
            "clicks": {"type":"integer"}, "tab": {"type":"integer"}, "switchOn": boolean(), "checked": boolean(),
            "operation": string(), "material": string(), "search": string(), "depth": number(),
        })),
    }))
}

fn gallery(ctx: &mut Ctx<'_>, args: Value) -> Result<Outcome, String> {
    let a: GalleryArgs = parse_args(args)?;
    // Refuse before changing anything.
    let accent = match &a.accent {
        Some(key) => Some(crate::theme::ACCENTS.iter().position(|c| c.key == key).ok_or_else(|| {
            let keys: Vec<&str> = crate::theme::ACCENTS.iter().map(|c| c.key).collect();
            format!("unknown accent `{key}` ({})", keys.join(" | "))
        })?),
        None => None,
    };
    let g = &mut ctx.app.ui_gallery;
    if let Some(open) = a.open {
        g.open = open;
    }
    if let Some(preview) = a.preview {
        g.preview = preview;
    }
    if let Some(font) = a.font {
        g.choices.font = font;
    }
    if let Some(index) = accent {
        g.choices.accent = index;
    }
    if let Some(density) = a.density {
        g.choices.density = match density {
            DensityArg::Compact => crate::theme::Density::Compact,
            DensityArg::Comfortable => crate::theme::Density::Comfortable,
        };
    }
    if let Some(light) = a.light {
        g.choices.light = light;
    }
    if let Some(view) = a.view {
        g.view = view;
    }
    if let Some(maximized) = a.maximized {
        g.maximized = maximized;
    }
    if let Some(reduce) = a.reduce_motion {
        g.reduce_motion = reduce;
    }
    // Apply now, so the reply (and the next frame's layout) reflects the change.
    g.sync(ctx.egui);
    Ok(Outcome::Done(g.state_json(ctx.egui)))
}

pub static COMMANDS: &[CommandSpec] = &[
    app_command!("ui", "gallery", "The developer UI gallery of the UI refresh (not in any menu): every new component in every state, the four open decisions as dropdowns, and a preview of the theme on the whole app. Every argument is optional and sets one thing: `open`, `preview` (the theme on the whole app; never saved), `font` (A | B), `accent` (blue | brand | teal | violet | orange | green), `density` (compact | comfortable), `light` (now | later), `view` (the gallery's own theme: app | dark | light), `maximized`, `reduce_motion`. Answers the gallery's state: the choices, the tokens they resolve to and the live samples' values. Widget keys: `uigallery/…`.", GalleryArgs, gallery, Mutate, MUTATE_NOWAIT, gallery_result_schema),
];