Skip to main content

tui_lipan/widgets/
theme_provider.rs

1//! Theme provider widget.
2
3use crate::core::element::{Element, ElementKind};
4use crate::style::Theme;
5
6/// Provide a theme for a subtree.
7#[derive(Clone)]
8pub struct ThemeProvider {
9    theme: Theme,
10    child: Element,
11}
12
13impl ThemeProvider {
14    /// Create a new theme provider.
15    pub fn new(theme: Theme) -> Self {
16        Self {
17            theme,
18            child: crate::widgets::Spacer::new().into(),
19        }
20    }
21
22    /// Set child content.
23    pub fn child(mut self, child: impl Into<Element>) -> Self {
24        self.child = child.into();
25        self
26    }
27}
28
29impl From<ThemeProvider> for Element {
30    fn from(provider: ThemeProvider) -> Self {
31        use crate::core::element::ThemeProviderElement;
32        Element::new(ElementKind::ThemeProvider(Box::new(ThemeProviderElement {
33            theme: provider.theme,
34            child: provider.child,
35        })))
36    }
37}