mirror of
https://github.com/danbulant/cushy
synced 2026-06-15 12:31:11 +00:00
31 lines
858 B
Rust
31 lines
858 B
Rust
use crate::context::EventContext;
|
|
use crate::value::{IntoValue, Value};
|
|
use crate::widget::{MakeWidget, WidgetRef, WrapperWidget};
|
|
use crate::window::ThemeMode;
|
|
|
|
/// A widget that applies a set of [`ThemeMode`] to all contained widgets.
|
|
#[derive(Debug)]
|
|
pub struct ThemedMode {
|
|
mode: Value<ThemeMode>,
|
|
child: WidgetRef,
|
|
}
|
|
|
|
impl ThemedMode {
|
|
/// Returns a new widget that applies `mode` to all of its children.
|
|
pub fn new(mode: impl IntoValue<ThemeMode>, child: impl MakeWidget) -> Self {
|
|
Self {
|
|
mode: mode.into_value(),
|
|
child: WidgetRef::new(child),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl WrapperWidget for ThemedMode {
|
|
fn child_mut(&mut self) -> &mut WidgetRef {
|
|
&mut self.child
|
|
}
|
|
|
|
fn mounted(&mut self, context: &mut EventContext<'_, '_>) {
|
|
context.attach_theme_mode(self.mode.clone());
|
|
}
|
|
}
|