BREP_app 0.4.0

The BREP CAD application: an eframe (egui + wgpu) host that draws the brep-render 3D engine into an egui frame — native + wasm from one codebase.
Documentation
//! Transient toast notifications — a small overlay for engine notices (e.g. a
//! sketch solve that failed after an edit). The engine only QUEUES notices
//! ([`brep_render::engine_state::EngineState::take_notices`]); this drains them
//! and shows each as an auto-expiring card anchored bottom-center. Time comes
//! from egui (`ctx.input().time`) — never `std::time::Instant`, which aborts on
//! wasm.

use eframe::egui;

/// Seconds a toast stays on screen before it fades out of the list.
const TTL: f64 = 6.0;
/// Most toasts kept on screen at once (older ones drop off the top).
const MAX_ON_SCREEN: usize = 6;

/// A queue of transient messages, each stamped with its egui birth time.
#[derive(Default)]
pub struct Toasts {
    items: Vec<(String, f64)>,
}

impl Toasts {
    /// Drop every queued toast (an automation host does this before a
    /// deterministic capture; the texts were already published as notices).
    pub fn dismiss_all(&mut self) -> usize {
        let n = self.items.len();
        self.items.clear();
        n
    }

    pub fn new() -> Self {
        Self::default()
    }

    /// Queue `messages` (drained from the engine this frame), stamped with `now`
    /// (`ctx.input().time`).
    pub fn extend(&mut self, messages: impl IntoIterator<Item = String>, now: f64) {
        for message in messages {
            self.items.push((message, now));
        }
        let overflow = self.items.len().saturating_sub(MAX_ON_SCREEN);
        if overflow > 0 {
            self.items.drain(0..overflow);
        }
    }

    /// The queued toast texts, oldest first, as a JSON array — the
    /// `__brepNotices` global the headed verifier reads to see a refusal the
    /// app only ever shows as a transient card.
    pub fn texts_json(&self) -> String {
        serde_json::Value::Array(
            self.items
                .iter()
                .map(|(text, _)| serde_json::Value::String(text.clone()))
                .collect(),
        )
        .to_string()
    }

    /// Draw the unexpired toasts. Call once per frame at ctx level (after the
    /// panels, so the cards float over the shell).
    pub fn show(&mut self, ctx: &egui::Context) {
        let now = ctx.input(|i| i.time);
        self.items.retain(|(_, born)| now - born < TTL);
        if self.items.is_empty() {
            return;
        }
        // Keep the frame loop alive so a toast expires on time without new input.
        ctx.request_repaint();

        egui::Area::new(egui::Id::new("brep-toasts"))
            .anchor(egui::Align2::CENTER_BOTTOM, egui::vec2(0.0, -28.0))
            .order(egui::Order::Foreground)
            .interactable(false)
            .show(ctx, |ui| {
                for (message, _) in &self.items {
                    egui::Frame::popup(ui.style())
                        .fill(egui::Color32::from_rgb(0x3a, 0x24, 0x24))
                        .stroke(egui::Stroke::new(
                            1.0,
                            egui::Color32::from_rgb(0xff, 0x6b, 0x6b),
                        ))
                        .show(ui, |ui| {
                            ui.set_max_width(460.0);
                            ui.label(
                                egui::RichText::new(message)
                                    .color(egui::Color32::from_rgb(0xff, 0x9b, 0x9b)),
                            );
                        });
                    ui.add_space(6.0);
                }
            });
    }
}