use std::cell::OnceCell;
use waft_embedder::{Clip, Color, Radius, TextDirection};
use waft_foundation::App;
use waft_painting::{BorderRadiusDirectional, BorderSide, RoundedRectangleBorder, ShapeBorderRef};
use waft_widgets::{BuildContext, Directionality};
use crate::colors::Colors;
use crate::drawer_theme::{DrawerThemeData, DrawerThemeDataGetters};
use crate::theme::Theme;
pub(crate) struct DrawerDefaultsM3 {
drawer_theme_data: DrawerThemeData,
context: BuildContext,
direction: OnceCell<TextDirection>,
}
impl DrawerDefaultsM3 {
pub(crate) fn new(context: BuildContext) -> DrawerDefaultsM3 {
DrawerDefaultsM3 {
drawer_theme_data: DrawerThemeData::new()
.elevation(1.0)
.clip_behavior(Clip::HardEdge),
context,
direction: OnceCell::new(),
}
}
fn direction(&self, app: &mut App) -> TextDirection {
*self
.direction
.get_or_init(|| Directionality::of(app, self.context))
}
}
impl DrawerThemeDataGetters for DrawerDefaultsM3 {
fn drawer_theme_data(&self) -> &DrawerThemeData {
&self.drawer_theme_data
}
fn background_color(&self, app: &mut App) -> Option<Color> {
Some(
Theme::of(app, self.context)
.color_scheme
.surface_container_low(),
)
}
fn surface_tint_color(&self, _app: &mut App) -> Option<Color> {
Some(Colors::TRANSPARENT)
}
fn shadow_color(&self, _app: &mut App) -> Option<Color> {
Some(Colors::TRANSPARENT)
}
fn shape(&self, app: &mut App) -> Option<ShapeBorderRef> {
Some(ShapeBorderRef::new(RoundedRectangleBorder::new(
BorderSide::NONE,
BorderRadiusDirectional::horizontal(Radius::ZERO, Radius::circular(16.0))
.resolve(Some(self.direction(app)))
.into(),
)))
}
fn end_shape(&self, app: &mut App) -> Option<ShapeBorderRef> {
Some(ShapeBorderRef::new(RoundedRectangleBorder::new(
BorderSide::NONE,
BorderRadiusDirectional::horizontal(Radius::circular(16.0), Radius::ZERO)
.resolve(Some(self.direction(app)))
.into(),
)))
}
}