#[derive(Debug, Clone, Copy)]
pub struct ArtifactTheme {
pub tokens: &'static str,
pub extra_css: &'static str,
}
impl ArtifactTheme {
pub const fn new(tokens: &'static str) -> Self {
Self {
tokens,
extra_css: "",
}
}
pub const fn with_extra_css(mut self, css: &'static str) -> Self {
self.extra_css = css;
self
}
}
#[derive(Debug, Clone, Copy)]
pub struct ArtifactThemeRegistration {
pub name: &'static str,
pub factory: fn() -> ArtifactTheme,
}
inventory::collect!(ArtifactThemeRegistration);
#[macro_export]
macro_rules! register_artifact_theme {
($factory:expr, name = $name:expr $(,)?) => {
::inventory::submit! {
$crate::services::ui_renderer::ArtifactThemeRegistration {
name: $name,
factory: $factory,
}
}
};
}
pub fn active_theme() -> Option<ArtifactTheme> {
let mut found: Vec<&ArtifactThemeRegistration> =
inventory::iter::<ArtifactThemeRegistration>().collect();
found.sort_by_key(|registration| registration.name);
let last = found.last()?;
if found.len() > 1 {
let names: Vec<&str> = found.iter().map(|registration| registration.name).collect();
tracing::warn!(
themes = ?names,
chosen = last.name,
"more than one artifact theme registered; the last by name wins"
);
}
Some((last.factory)())
}