Skip to main content

ferroui_controls/
theme_variant_scope.rs

1use crate::{ControlImpl, Decorator};
2use ferroui_base::input::InputElementImpl;
3use ferroui_base::interactivity::InteractiveImpl;
4use ferroui_base::layout::LayoutableImpl;
5use ferroui_base::styling::ThemeVariant;
6use ferroui_base::{
7    ferro_class, ferro_class_info, ferro_impl_classes, instantiate, FerroObjectImpl, Ref, StyledElementImpl,
8    StyledProperty, VisualImpl,
9};
10
11/// Decorator control that isolates a subtree of controls with a locally
12/// defined [`ThemeVariant`].
13#[repr(C)]
14pub struct ThemeVariantScope {
15    base: Decorator,
16}
17
18ferro_class!(ThemeVariantScope: Decorator);
19ferro_class_info!(ThemeVariantScope { new: ThemeVariantScope::new });
20ferro_impl_classes!(
21    ThemeVariantScope: FerroObjectImpl,
22    StyledElementImpl,
23    VisualImpl,
24    LayoutableImpl,
25    InteractiveImpl,
26    InputElementImpl,
27    ControlImpl
28);
29
30impl ThemeVariantScope {
31    /// Defines the `ActualThemeVariant` property: the property of
32    /// [`ThemeVariant`], which every styled element owns.
33    pub fn actual_theme_variant_property() -> &'static StyledProperty<Option<ThemeVariant>> {
34        ThemeVariant::actual_theme_variant_property()
35    }
36
37    /// Defines the `RequestedThemeVariant` property: the property of
38    /// [`ThemeVariant`], which every styled element owns.
39    pub fn requested_theme_variant_property() -> &'static StyledProperty<Option<ThemeVariant>> {
40        ThemeVariant::requested_theme_variant_property()
41    }
42
43    /// Creates the class data; see [`ferroui_base::FerroObject::construct`].
44    pub fn construct() -> Self {
45        Self { base: Decorator::construct() }
46    }
47
48    pub fn new() -> Ref<Self> {
49        instantiate(Self::construct())
50    }
51
52    /// The UI theme variant that is used by the control (and its child
53    /// elements) for resource determination. The UI theme specified with it
54    /// can override the app-level theme variant.
55    ///
56    /// Setting it to the default theme variant applies the actual theme
57    /// variant of the parent on the current scope.
58    pub fn requested_theme_variant(&self) -> Option<ThemeVariant> {
59        self.get_value(Self::requested_theme_variant_property())
60    }
61
62    pub fn set_requested_theme_variant(&self, value: Option<ThemeVariant>) {
63        self.set_value(Self::requested_theme_variant_property(), value)
64    }
65}