use crate::styles::Theme;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum LayoutDirection {
#[default]
LeftToRight,
RightToLeft,
}
#[derive(Debug, Clone)]
pub struct Environment {
pub theme: Theme,
pub layout_direction: LayoutDirection,
pub scale_factor: f32,
pub prefers_high_contrast: bool,
pub prefers_reduced_motion: bool,
pub prefers_large_text: bool,
}
impl Environment {
pub fn new(theme: Theme) -> Self {
Self {
theme,
layout_direction: LayoutDirection::default(),
scale_factor: 1.0,
prefers_high_contrast: false,
prefers_reduced_motion: false,
prefers_large_text: false,
}
}
pub fn with_theme_override(&self, f: &dyn Fn(&mut Theme)) -> Self {
let mut env = self.clone();
f(&mut env.theme);
env
}
}
impl Default for Environment {
fn default() -> Self {
Self::new(crate::presets::intui::light())
}
}
pub(crate) struct ThemeOverride {
pub func: Box<dyn Fn(&mut Theme)>,
}
impl std::fmt::Debug for ThemeOverride {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("ThemeOverride(..)")
}
}