use crate::gui::content::Content;
use crate::gui::window::{CommandSender, WindowRegistry};
use egui::TextureHandle;
use std::collections::HashMap;
pub struct ControllerContext<'a> {
pub command_sender: &'a CommandSender,
pub registry: &'a mut WindowRegistry,
pub icon_cache: &'a mut HashMap<String, TextureHandle>,
pub egui_ctx: &'a egui::Context,
pub controller_background: &'a mut Option<Content>,
}
impl<'a> ControllerContext<'a> {
pub fn request_repaint(&self) {
self.egui_ctx.request_repaint();
}
pub fn has_controller_background(&self) -> bool {
self.controller_background.is_some()
}
pub fn set_controller_background(&mut self, content: Option<Content>) {
*self.controller_background = content;
}
pub fn get_or_create_texture<F>(&mut self, key: &str, create_fn: F) -> Option<&TextureHandle>
where
F: FnOnce(&egui::Context) -> Option<TextureHandle>,
{
if !self.icon_cache.contains_key(key) {
if let Some(texture) = create_fn(self.egui_ctx) {
self.icon_cache.insert(key.to_string(), texture);
}
}
self.icon_cache.get(key)
}
}