pagetop/src/core/theme/definition.rs
Manuel Cillero 86e4c4f110 Añade soporte a temas en la API de extensiones
- Incluye una opción de configuración para definir el tema por defecto.
- Añade un tema básico predeterminado.
2025-07-20 23:51:15 +02:00

30 lines
1 KiB
Rust

use crate::core::extension::ExtensionTrait;
/// Representa una referencia a un tema.
///
/// Los temas son también extensiones. Por tanto se deben definir igual, es decir, como instancias
/// estáticas globales que implementan [`ThemeTrait`], pero también [`ExtensionTrait`].
pub type ThemeRef = &'static dyn ThemeTrait;
/// Interfaz común que debe implementar cualquier tema de `PageTop`.
///
/// Un tema implementará [`ThemeTrait`] y los métodos que sean necesarios de [`ExtensionTrait`],
/// aunque el único obligatorio es [`theme()`](crate::core::extension::ExtensionTrait#method.theme).
///
/// ```rust
/// use pagetop::prelude::*;
///
/// pub struct MyTheme;
///
/// impl ExtensionTrait for MyTheme {
/// fn name(&self) -> L10n { L10n::n("My theme") }
/// fn description(&self) -> L10n { L10n::n("Un tema personal") }
///
/// fn theme(&self) -> Option<ThemeRef> {
/// Some(&Self)
/// }
/// }
///
/// impl ThemeTrait for MyTheme {}
/// ```
pub trait ThemeTrait: ExtensionTrait + Send + Sync {}