plugin_interfaces/pluginui/
context.rs1use std::collections::HashMap;
4
5#[derive(Debug)]
7pub struct CreationContext<'a> {
8 pub config: HashMap<String, String>,
10 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#[derive(Debug)]
29pub struct Context {
30 pub plugin_id: String,
32 pub theme: Theme,
34 pub ui_state: UiState,
36 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 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 pub fn get_ui_event_data(&self, component_id: &str) -> Option<&String> {
62 self.ui_event_data.get(component_id)
63 }
64}
65
66#[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#[derive(Debug, Default)]
80pub struct UiState {
81 pub frame_count: u64,
82 pub time: f64,
83}