plugin_interfaces/pluginui/
context.rs

1//! Context types for the plugin UI framework
2
3use std::collections::HashMap;
4
5/// Creation context passed to plugins during initialization
6#[derive(Debug)]
7pub struct CreationContext<'a> {
8    /// Plugin configuration data
9    pub config: HashMap<String, String>,
10    /// Plugin ID
11    pub plugin_id: &'a str,
12}
13
14impl<'a> CreationContext<'a> {
15    pub fn new(plugin_id: &'a str) -> Self {
16        Self {
17            config: HashMap::new(),
18            plugin_id,
19        }
20    }
21
22    pub fn with_config(plugin_id: &'a str, config: HashMap<String, String>) -> Self {
23        Self { config, plugin_id }
24    }
25}
26
27/// Runtime context for UI operations
28#[derive(Debug)]
29pub struct Context {
30    /// Current plugin ID
31    pub plugin_id: String,
32    /// Theme information
33    pub theme: Theme,
34    /// UI state
35    pub ui_state: UiState,
36    /// UI event data from frontend
37    pub ui_event_data: HashMap<String, String>,
38}
39
40impl Context {
41    pub fn new(plugin_id: String) -> Self {
42        Self {
43            plugin_id,
44            theme: Theme::default(),
45            ui_state: UiState::default(),
46            ui_event_data: HashMap::new(),
47        }
48    }
49
50    /// Create context with UI event data
51    pub fn with_ui_event_data(plugin_id: String, ui_event_data: HashMap<String, String>) -> Self {
52        Self {
53            plugin_id,
54            theme: Theme::default(),
55            ui_state: UiState::default(),
56            ui_event_data,
57        }
58    }
59
60    /// Get UI event data for a specific component
61    pub fn get_ui_event_data(&self, component_id: &str) -> Option<&String> {
62        self.ui_event_data.get(component_id)
63    }
64}
65
66/// Theme information
67#[derive(Debug, Clone)]
68pub struct Theme {
69    pub is_dark: bool,
70}
71
72impl Default for Theme {
73    fn default() -> Self {
74        Self { is_dark: false }
75    }
76}
77
78/// UI state information
79#[derive(Debug, Default)]
80pub struct UiState {
81    pub frame_count: u64,
82    pub time: f64,
83}