beamer_core/
editor.rs

1//! Editor and GUI-related traits.
2
3use crate::types::Size;
4
5/// Size constraints for the plugin editor.
6#[derive(Debug, Clone, Copy)]
7pub struct EditorConstraints {
8    /// Minimum size.
9    pub min: Size,
10    /// Maximum size.
11    pub max: Size,
12    /// Whether the editor is resizable.
13    pub resizable: bool,
14}
15
16impl Default for EditorConstraints {
17    fn default() -> Self {
18        Self {
19            min: Size::new(400, 300),
20            max: Size::new(1600, 1200),
21            resizable: true,
22        }
23    }
24}
25
26/// Trait for plugin editor/GUI callbacks.
27///
28/// Implement this trait to provide GUI-related configuration and callbacks.
29/// The actual WebView creation and management is handled by the framework;
30/// this trait just provides configuration and lifecycle hooks.
31pub trait EditorDelegate: Send {
32    /// Get the initial editor size.
33    ///
34    /// This is the size the editor window will have when first opened.
35    /// Default is 800x600.
36    fn editor_size(&self) -> Size {
37        Size::new(800, 600)
38    }
39
40    /// Get the editor size constraints.
41    ///
42    /// These constraints determine the minimum and maximum sizes the editor
43    /// can be resized to, and whether resizing is allowed at all.
44    fn editor_constraints(&self) -> EditorConstraints {
45        EditorConstraints::default()
46    }
47
48    /// Called when the editor is opened.
49    ///
50    /// Use this to initialize any editor-specific state.
51    fn editor_opened(&mut self) {}
52
53    /// Called when the editor is closed.
54    ///
55    /// Use this to clean up editor-specific state.
56    fn editor_closed(&mut self) {}
57
58    /// Called when the editor is resized.
59    ///
60    /// The new size has already been constrained to the editor constraints.
61    fn editor_resized(&mut self, _new_size: Size) {}
62}
63
64/// Trait for plugins that don't need an editor.
65///
66/// Implement this for plugins that don't have a GUI. This is the default
67/// for the basic `AudioProcessor` trait, but can be explicitly implemented
68/// to opt out of editor support.
69pub trait NoEditor {}