Skip to main content

plot_redactor/
lib.rs

1//! Tiny, embeddable plot redactor crate.
2//!
3//! Architecture summary:
4//! - `model`: domain data structures (`DataTable`, plot configuration, styles).
5//! - `controller`: action handling, validation, undo/redo, import/export orchestration.
6//! - `view`: egui UI composition and action emission.
7//!
8//! Dataflow:
9//! `View -> Action -> Controller -> Model`, then View re-renders from model snapshot.
10
11pub mod controller;
12pub mod model;
13pub mod view;
14
15use controller::PlotController;
16use eframe::egui;
17use view::PlotEditorView;
18
19/// EN: Embeddable editor app object for host applications.
20/// RU: Vstraivaemy obekt redaktora dlya host-prilozheniy.
21pub struct PlotEditorApp {
22    controller: PlotController,
23    view: PlotEditorView,
24}
25
26impl PlotEditorApp {
27    /// Creates an editor app with empty data and default plot settings.
28    pub fn new() -> Self {
29        Self {
30            controller: PlotController::new(),
31            view: PlotEditorView::new(),
32        }
33    }
34
35    /// Gives mutable access to controller for host-application integration.
36    pub fn controller_mut(&mut self) -> &mut PlotController {
37        &mut self.controller
38    }
39}
40
41impl Default for PlotEditorApp {
42    fn default() -> Self {
43        Self::new()
44    }
45}
46
47impl eframe::App for PlotEditorApp {
48    fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
49        let actions = self.view.draw(ctx, &self.controller);
50        for action in actions {
51            let _ = self.controller.dispatch(action);
52        }
53    }
54}
55
56/// EN: Convenience runner for standalone usage.
57/// RU: Udobny zapusk dlya standalone-ispolzovaniya.
58pub fn run_native() -> Result<(), eframe::Error> {
59    let native_options = eframe::NativeOptions::default();
60    eframe::run_native(
61        "KiThe Plot Redactor",
62        native_options,
63        Box::new(|cc| {
64            cc.egui_ctx.set_visuals(eframe::egui::Visuals::light());
65            Ok(Box::new(PlotEditorApp::new()))
66        }),
67    )
68}