euv-ui 0.51.0

Cross-platform UI component library and 17-scheme design system for the euv framework with pixel-consistent rendering across Web, Android, iOS, iPadOS, macOS, Windows, and Linux.
Documentation
use super::*;

/// Reactive 3D orbit/pan/zoom/keyboard camera state synchronized with `Camera3D`.
#[derive(Clone, Copy, Data, Debug, PartialEq)]
pub struct EuvViewport3DCameraState {
    /// World-space focus point orbited by the camera.
    #[get(type(copy))]
    pub(crate) target: Vec3,
    /// Horizontal orbit yaw angle in radians.
    #[get(type(copy))]
    pub(crate) yaw_rad: f32,
    /// Vertical orbit pitch angle in radians (`[-1.42, 1.42]`).
    #[get(type(copy))]
    pub(crate) pitch_rad: f32,
    /// Distance from eye to `target` in meters.
    #[get(type(copy))]
    pub(crate) distance: f32,
    /// Vertical field of view in degrees.
    #[get(type(copy))]
    pub(crate) fov_deg: f32,
    /// Near clipping plane distance in meters.
    #[get(type(copy))]
    pub(crate) near: f32,
    /// Far clipping plane distance in meters.
    #[get(type(copy))]
    pub(crate) far: f32,
    /// Orbit rotation sensitivity in radians per pixel.
    #[get(type(copy))]
    pub(crate) orbit_sensitivity: f32,
    /// Pan translation sensitivity scaled by distance.
    #[get(type(copy))]
    pub(crate) pan_sensitivity: f32,
    /// Scroll wheel zoom sensitivity factor.
    #[get(type(copy))]
    pub(crate) zoom_sensitivity: f32,
    /// Keyboard movement step speed in meters.
    #[get(type(copy))]
    pub(crate) move_speed: f32,
    /// Active pointer drag navigation mode (`Orbit`, `Pan`, or `Fly`).
    #[get(type(copy))]
    pub(crate) navigation_mode: EuvViewport3DNavigationMode,
}

/// Single scene hierarchy row displayed in the Studio Scene inspector tab.
#[derive(Clone, Data, Debug, Eq, New, PartialEq)]
pub struct EuvViewport3DNodeItem {
    /// Node index inside `SceneGraph3D` or `World3D`.
    #[get(type(copy))]
    pub(crate) index: u32,
    /// Human-readable Blender object or node name.
    pub(crate) name: String,
    /// Tree indentation depth (`0` = root).
    #[get(type(copy))]
    pub(crate) depth: u16,
    /// Whether the node is visible in the viewport.
    #[get(type(copy))]
    pub(crate) visible: bool,
    /// Whether a mesh is attached to this node.
    #[get(type(copy))]
    pub(crate) has_mesh: bool,
    /// Whether a camera is attached to this node.
    #[get(type(copy))]
    pub(crate) has_camera: bool,
    /// Whether a light is attached to this node.
    #[get(type(copy))]
    pub(crate) has_light: bool,
}

/// Lightweight Principled BSDF material summary displayed and edited in the Studio Materials tab.
#[derive(Clone, Data, Debug, Default, PartialEq)]
pub struct EuvViewport3DMaterialItem {
    /// Material slot index inside the scene material table.
    #[get(type(copy))]
    pub(crate) index: usize,
    /// Human-readable Blender material name.
    pub(crate) name: String,
    /// Linear RGBA base color multiplier.
    #[get(type(copy))]
    pub(crate) base_color: [f32; 4],
    /// Metallic factor in `[0.0, 1.0]`.
    #[get(type(copy))]
    pub(crate) metallic: f32,
    /// Perceptual roughness factor in `[0.04, 1.0]`.
    #[get(type(copy))]
    pub(crate) roughness: f32,
    /// Dielectric index of refraction (`1.5` default).
    #[get(type(copy))]
    pub(crate) ior: f32,
    /// Clearcoat layer weight in `[0.0, 1.0]`.
    #[get(type(copy))]
    pub(crate) clearcoat: f32,
    /// Optical transmission factor in `[0.0, 1.0]`.
    #[get(type(copy))]
    pub(crate) transmission: f32,
    /// HDR emissive strength multiplier.
    #[get(type(copy))]
    pub(crate) emissive_strength: f32,
}

/// Lightweight scene inventory powering the optional collapsible Studio inspector rail.
#[derive(Clone, Data, Debug, Default, PartialEq)]
pub struct EuvViewport3DSceneSummary {
    /// Scene or root asset name.
    pub(crate) scene_name: String,
    /// Generator tool identifier (e.g., `"Khronos glTF Blender I/O"`).
    pub(crate) generator: String,
    /// Ordered scene hierarchy rows.
    pub(crate) nodes: Vec<EuvViewport3DNodeItem>,
    /// Principled BSDF materials available in the scene.
    pub(crate) materials: Vec<EuvViewport3DMaterialItem>,
    /// Named Blender Collections present in the scene.
    pub(crate) collections: Vec<String>,
    /// Named cameras present in the scene.
    pub(crate) cameras: Vec<String>,
    /// Total `LOD0` vertices across all scene meshes.
    #[get(type(copy))]
    pub(crate) total_vertices: usize,
    /// Total `LOD0` triangles across all scene meshes.
    #[get(type(copy))]
    pub(crate) total_triangles: usize,
    /// Total imported animation clips.
    #[get(type(copy))]
    pub(crate) animation_count: usize,
}

/// Reactive Live-Link connection telemetry shown in the Studio Live-Link inspector tab.
#[derive(Clone, Data, Debug, Eq, PartialEq)]
pub struct EuvViewport3DLiveLinkState {
    /// SSE endpoint URL (defaults to `http://127.0.0.1:9877/blender/events`).
    pub(crate) endpoint_url: String,
    /// Active connection status.
    #[get(type(copy))]
    pub(crate) status: EuvViewport3DLiveLinkStatus,
    /// Latest monotonic sequence received from `euv blender live-sync`.
    #[get(type(copy))]
    pub(crate) last_seq: u64,
    /// Total JSON scene deltas applied during this session.
    #[get(type(copy))]
    pub(crate) delta_count: u64,
    /// Total binary `.glb` / `.euv3d` hot-swaps applied during this session.
    #[get(type(copy))]
    pub(crate) asset_count: u64,
    /// Short human-readable status message.
    pub(crate) last_message: String,
}

/// Internal pointer drag tracking state shared across inline and fullscreen viewport canvases.
#[derive(Clone, Copy, Data, Debug, Default, PartialEq)]
pub(crate) struct EuvViewport3DDragState {
    /// Whether a pointer button or touch drag is currently active.
    #[get(type(copy))]
    pub(crate) dragging: bool,
    /// Last observed logical pointer position during the active drag.
    #[get(type(copy))]
    pub(crate) last_pos: Point,
}

/// Internal bundled parameters for mounting an interactive 3D viewport canvas surface.
#[derive(Clone)]
pub(crate) struct Viewport3DCanvasSpec {
    /// Reactive camera state mutated on pointer drag, wheel zoom, and keyboard controls.
    pub(crate) camera: Signal<EuvViewport3DCameraState>,
    /// Reactive fullscreen toggle state (`F` key shortcut).
    pub(crate) fullscreen: Signal<bool>,
    /// Optional live `World3D` rendered through `Renderer3D`.
    pub(crate) world: Option<Rc<RefCell<World3D>>>,
    /// Shared lazily allocated `Renderer3D` instance reused across inline and fullscreen viewports.
    pub(crate) renderer: Rc<RefCell<Option<Box<Renderer3D>>>>,
    /// Optional reactive quality configuration for `Renderer3D`.
    pub(crate) quality: Option<Signal<RenderQualityConfig>>,
    /// Optional custom canvas painter override.
    pub(crate) painter: Option<Viewport3DPainter>,
    /// Optional keyboard event forwarding hook.
    pub(crate) on_key_input: Option<Viewport3DKeyCallback>,
    /// Accessible label for the interactive 3D viewport canvas.
    pub(crate) title: String,
    /// Base theme tokens.
    pub(crate) tokens: ThemeTokens,
}

/// Internal bundled parameters for mounting the optional collapsible Studio inspector rail.
#[derive(Clone)]
pub(crate) struct Viewport3DInspectorSpec {
    /// Reactive open/collapsed signal.
    pub(crate) inspector_open: Signal<bool>,
    /// Reactive active inspector tab signal.
    pub(crate) active_tab: Signal<EuvViewport3DInspectorTab>,
    /// Reactive camera state signal for Camera presets and telemetry.
    pub(crate) camera: Signal<EuvViewport3DCameraState>,
    /// Reactive selected node index signal.
    pub(crate) selected_node: Signal<Option<u32>>,
    /// Reactive selected material index signal.
    pub(crate) selected_material: Signal<Option<usize>>,
    /// Optional reactive scene summary.
    pub(crate) scene_summary: Option<Signal<EuvViewport3DSceneSummary>>,
    /// Optional reactive Live-Link telemetry state.
    pub(crate) live_link: Option<Signal<EuvViewport3DLiveLinkState>>,
    /// Optional scene node selection hook.
    pub(crate) on_select_node: Option<Viewport3DNodeCallback>,
    /// Optional Principled BSDF material change hook.
    pub(crate) on_material_change: Option<Viewport3DMaterialCallback>,
    /// Optional Live-Link connect/disconnect toggle hook.
    pub(crate) on_live_link_toggle: Option<Viewport3DLiveLinkCallback>,
    /// Base theme tokens.
    pub(crate) tokens: ThemeTokens,
}

/// Reusable cross-platform 3D viewport component supporting direct orbit/pan/zoom + keyboard controls, edge-to-edge fullscreen, and optional Blender Studio inspector hooks.
#[derive(Clone, CustomDebug, Data, Props)]
pub struct EuvViewport3D {
    /// Accessible title and Studio viewport label.
    pub(crate) title: String,
    /// Presentation mode (`Game` default exposes ONLY screen+keyboard controls and a single fullscreen toggle button; `Studio` enables the optional collapsible inspector rail).
    #[get(type(copy))]
    #[prop(custom)]
    pub(crate) mode: EuvViewport3DMode,
    /// Reactive camera state synchronized with pointer orbit/pan/zoom and keyboard controls.
    #[get(type(copy))]
    pub(crate) camera: Signal<EuvViewport3DCameraState>,
    /// Two-way reactive fullscreen portal toggle state.
    #[get(type(copy))]
    pub(crate) fullscreen: Signal<bool>,
    /// Explicitly enables the optional collapsible Studio inspector rail (`false` by default for unobstructed game viewports).
    #[get(type(copy))]
    #[prop(custom)]
    pub(crate) show_inspector: bool,
    /// Reactive collapsed/expanded toggle for the Studio inspector rail.
    #[get(type(copy))]
    pub(crate) inspector_open: Signal<bool>,
    /// Reactive active tab inside the Studio inspector rail.
    #[get(type(copy))]
    pub(crate) active_tab: Signal<EuvViewport3DInspectorTab>,
    /// Reactive selected node index inside the Scene inspector tab.
    #[get(type(copy))]
    pub(crate) selected_node: Signal<Option<u32>>,
    /// Reactive selected material index inside the Materials inspector tab.
    #[get(type(copy))]
    pub(crate) selected_material: Signal<Option<usize>>,
    /// Optional reactive Blender/glTF scene summary powering the Scene and Materials inspector tabs.
    #[get(type(copy))]
    pub(crate) scene_summary: Option<Signal<EuvViewport3DSceneSummary>>,
    /// Optional reactive Live-Link telemetry state powering the Live-Link inspector tab.
    #[get(type(copy))]
    pub(crate) live_link: Option<Signal<EuvViewport3DLiveLinkState>>,
    /// Optional live `World3D` rendered directly into the viewport via `Renderer3D` with synced camera.
    #[debug(skip)]
    #[get(skip)]
    pub(crate) world: Option<Rc<RefCell<World3D>>>,
    /// Optional reactive quality settings used when rendering `world`.
    #[get(type(copy))]
    pub(crate) quality: Option<Signal<RenderQualityConfig>>,
    /// Optional custom 3D canvas painter replacing the built-in studio grid / `Renderer3D` pass.
    #[debug(skip)]
    #[get(skip)]
    #[prop(custom)]
    pub(crate) painter: Option<Viewport3DPainter>,
    /// Optional keyboard hook invoked on every key press while the viewport has focus.
    #[debug(skip)]
    #[get(skip)]
    #[prop(custom)]
    pub(crate) on_key_input: Option<Viewport3DKeyCallback>,
    /// Optional hook invoked when a node row is clicked in the Studio Scene inspector.
    #[debug(skip)]
    #[get(skip)]
    #[prop(custom)]
    pub(crate) on_select_node: Option<Viewport3DNodeCallback>,
    /// Optional hook invoked when a Principled BSDF material slider/stepper changes in the Studio Materials inspector.
    #[debug(skip)]
    #[get(skip)]
    #[prop(custom)]
    pub(crate) on_material_change: Option<Viewport3DMaterialCallback>,
    /// Optional hook invoked when the user clicks Connect/Disconnect in the Studio Live-Link inspector.
    #[debug(skip)]
    #[get(skip)]
    #[prop(custom)]
    pub(crate) on_live_link_toggle: Option<Viewport3DLiveLinkCallback>,
    /// Resolved `euv-ui` design system theme tokens.
    #[get(type(copy))]
    pub(crate) tokens: ThemeTokens,
    /// Optional style overrides controlling viewport height and container appearance.
    #[get(type(copy))]
    pub(crate) style: Option<Style>,
}