use std::collections::HashMap;
#[derive(Debug)]
pub struct CreationContext<'a> {
pub config: HashMap<String, String>,
pub plugin_id: &'a str,
}
impl<'a> CreationContext<'a> {
pub fn new(plugin_id: &'a str) -> Self {
Self {
config: HashMap::new(),
plugin_id,
}
}
pub fn with_config(plugin_id: &'a str, config: HashMap<String, String>) -> Self {
Self { config, plugin_id }
}
}
#[derive(Debug)]
pub struct Context {
pub plugin_id: String,
pub theme: Theme,
pub ui_state: UiState,
pub ui_event_data: HashMap<String, String>,
}
impl Context {
pub fn new(plugin_id: String) -> Self {
Self {
plugin_id,
theme: Theme::default(),
ui_state: UiState::default(),
ui_event_data: HashMap::new(),
}
}
pub fn with_ui_event_data(plugin_id: String, ui_event_data: HashMap<String, String>) -> Self {
Self {
plugin_id,
theme: Theme::default(),
ui_state: UiState::default(),
ui_event_data,
}
}
pub fn get_ui_event_data(&self, component_id: &str) -> Option<&String> {
self.ui_event_data.get(component_id)
}
}
#[derive(Debug, Clone)]
pub struct Theme {
pub is_dark: bool,
}
impl Default for Theme {
fn default() -> Self {
Self { is_dark: false }
}
}
#[derive(Debug, Default)]
pub struct UiState {
pub frame_count: u64,
pub time: f64,
}