tessera_ui/
entry_registry.rs

1//! Entry package registry for renderer startup.
2use std::sync::Arc;
3
4use parking_lot::RwLock;
5
6use crate::{
7    plugin::{Plugin, register_plugin, register_plugin_boxed},
8    render_module::RenderModule,
9};
10
11/// Registers modules and plugins for a Tessera entry point.
12pub trait TesseraPackage {
13    /// Registers this package into the provided registry.
14    fn register(self, registry: &mut EntryRegistry);
15}
16
17/// Collects modules and registers plugins for an application entry.
18pub struct EntryRegistry {
19    modules: Vec<Box<dyn RenderModule>>,
20}
21
22impl EntryRegistry {
23    /// Creates a new registry for entry-time registration.
24    pub fn new() -> Self {
25        Self {
26            modules: Vec::new(),
27        }
28    }
29
30    /// Adds a render module to the entry registry.
31    pub fn add_module(&mut self, module: impl RenderModule + 'static) {
32        self.modules.push(Box::new(module));
33    }
34
35    /// Registers a plugin instance with the global plugin registry.
36    pub fn register_plugin<P: Plugin>(&mut self, plugin: P) {
37        register_plugin(plugin);
38    }
39
40    /// Registers a boxed plugin instance with the global plugin registry.
41    pub fn register_plugin_boxed<P: Plugin>(&mut self, plugin: Arc<RwLock<P>>) {
42        register_plugin_boxed(plugin);
43    }
44
45    /// Registers a package into the entry registry.
46    pub fn register_package<P: TesseraPackage>(&mut self, package: P) {
47        package.register(self);
48    }
49
50    /// Finalizes the registry into a module list for the renderer.
51    pub fn finish(self) -> Vec<Box<dyn RenderModule>> {
52        self.modules
53    }
54}
55
56impl Default for EntryRegistry {
57    fn default() -> Self {
58        Self::new()
59    }
60}