Skip to main content

runmat_plot/gui/
window.rs

1//! Main window management for interactive GUI plotting
2//!
3//! Provides the main application window with integrated plot viewport
4//! and control panels using winit and egui.
5
6/// Configuration for the plot window
7#[derive(Debug, Clone)]
8pub struct WindowConfig {
9    pub title: String,
10    pub width: u32,
11    pub height: u32,
12    pub resizable: bool,
13    pub maximized: bool,
14    pub vsync: bool,
15}
16
17impl Default for WindowConfig {
18    fn default() -> Self {
19        Self {
20            title: "RunMat - Interactive Visualization | Powered by Dystr".to_string(),
21            width: 1200,
22            height: 800,
23            resizable: true,
24            maximized: false,
25            vsync: true,
26        }
27    }
28}
29
30/// Interactive plot window with full WGPU rendering
31#[cfg(feature = "gui")]
32pub struct PlotWindow<'window> {
33    pub window: std::sync::Arc<winit::window::Window>,
34    pub event_loop: Option<winit::event_loop::EventLoop<()>>,
35    pub plot_renderer: crate::core::PlotRenderer,
36    pub plot_overlay: crate::gui::PlotOverlay,
37    pub surface: wgpu::Surface<'window>,
38    pub depth_texture: wgpu::Texture,
39    pub depth_view: wgpu::TextureView,
40    pub egui_ctx: egui::Context,
41    pub egui_state: egui_winit::State,
42    pub egui_renderer: egui_wgpu::Renderer,
43    pub config: WindowConfig,
44    pub mouse_position: glam::Vec2,
45    pub is_mouse_over_plot: bool,
46    /// Ensure we render at least one frame even if no input events request a repaint
47    pub needs_initial_redraw: bool,
48    /// Egui pixels-per-point from the last frame; used to map UI points to physical pixels
49    pub pixels_per_point: f32,
50    /// Whether left mouse button is currently down
51    pub mouse_left_down: bool,
52    /// Which subplot axes is currently captured for drag interactions, if any.
53    pub active_drag_axes: Option<usize>,
54    /// Optional signal that lets external callers request window shutdown.
55    pub close_signal: Option<std::sync::Arc<std::sync::atomic::AtomicBool>>,
56}
57
58// The implementation is in window_impl.rs in the same directory
59
60// Stub implementation for non-GUI builds
61#[cfg(not(feature = "gui"))]
62pub struct PlotWindow;
63
64#[cfg(not(feature = "gui"))]
65impl PlotWindow {
66    pub async fn new(_config: WindowConfig) -> Result<Self, Box<dyn std::error::Error>> {
67        Err("GUI feature not enabled".into())
68    }
69
70    pub fn add_test_plot(&mut self) {
71        // No-op for non-GUI builds
72    }
73
74    pub fn run(self) -> Result<(), Box<dyn std::error::Error>> {
75        Err("GUI feature not enabled".into())
76    }
77
78    pub fn install_close_signal(&mut self, _signal: std::sync::Arc<std::sync::atomic::AtomicBool>) {
79        // No-op for non-GUI builds
80    }
81}