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 refreshed UI's components (section 5).
//!
//! STATUS: rollout step 1. The components exist and are shown in the developer
//! gallery ([`gallery`](crate::ui_kit::gallery)); no panel calls them yet. `form.rs`'s helpers become
//! wrappers over them in step 3, after the owner has signed off on the look.
//!
//! Every component reads its colours, sizes and durations from the
//! [`crate::theme::Theme`] of its `Ui` ([`crate::theme::Theme::of`]) and returns
//! the `egui::Response` of the control, so a caller publishes its automation
//! hit key from the rect exactly as it does for the egui widget it replaces.
//! Enumerations are [`dropdown`](crate::ui_kit::dropdown())s; there is no radio row here by design.
pub mod button;
pub mod chips;
pub mod dropdown;
pub mod gallery;
pub mod icon_button;
pub mod input;
pub mod paint;
pub mod preview;
pub mod surface;
pub mod tabs;
pub mod toggle;

pub use button::{Button, Size, Variant};
pub use chips::{reference_field, Chip, ReferenceField, ReferenceOutput};
pub use dropdown::{dropdown, Dropdown};
pub use icon_button::{BarSide, IconButton};
pub use input::{number_input, search_input, text_input, NumberInput, TextInput};
pub use tabs::{document_tabs, tab_bar, DocumentTab, DocumentTabsOutput};
pub use toggle::{checkbox, slider, switch, Check};

use eframe::egui;

/// A state a component is DRAWN in whatever the pointer is doing: the gallery
/// uses it to show hover, pressed and focus side by side. Panels leave it at
/// [`Show::Live`].
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum Show {
    #[default]
    Live,
    Hover,
    Pressed,
    Focus,
}

/// What a control is doing this frame, with [`Show`] folded in.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub(crate) struct Interact {
    pub hovered: bool,
    pub pressed: bool,
    pub focused: bool,
}

impl Interact {
    pub fn of(response: &egui::Response, show: Show, enabled: bool) -> Self {
        if !enabled {
            return Interact::default();
        }
        Interact {
            hovered: response.hovered() || matches!(show, Show::Hover | Show::Pressed),
            pressed: response.is_pointer_button_down_on() || show == Show::Pressed,
            focused: response.has_focus() || show == Show::Focus,
        }
    }
}

/// Run `contents` with `theme` as the theme of every component in it and its
/// egui style on the `Ui`, whatever the app's own style is.
pub fn themed<R>(ui: &mut egui::Ui, theme: std::sync::Arc<crate::theme::Theme>, contents: impl FnOnce(&mut egui::Ui) -> R) -> R {
    let before = crate::theme::stored(ui.ctx());
    crate::theme::set(ui.ctx(), theme.clone());
    let out = ui
        .scope(|ui| {
            let style = theme.style(ui.style());
            ui.set_style(style);
            contents(ui)
        })
        .inner;
    match before {
        Some(theme) => crate::theme::set(ui.ctx(), theme),
        None => crate::theme::clear(ui.ctx()),
    }
    out
}