use super::element::ElementPresentation;
use crate::{Margin, ThemeResources};
use waft_embedder::Radius;
use waft_foundation::App;
use waft_painting::{AlignmentGeometry, BorderRadius};
use waft_widgets::*;
#[derive(Clone, Debug, Default)]
pub struct AppBarSeparator {
pub dynamic_overflow_order: i32,
pub(crate) presentation: ElementPresentation,
pub key: Option<KeyRef>,
}
impl AppBarSeparator {
pub fn new() -> Self {
Self::default()
}
pub fn dynamic_overflow_order(mut self, order: i32) -> Self {
self.dynamic_overflow_order = order;
self
}
pub fn key(mut self, key: KeyRef) -> Self {
self.key = Some(key);
self
}
}
impl StatelessWidget for AppBarSeparator {
fn key(&self) -> Option<&KeyRef> {
self.key.as_ref()
}
fn build(&self, app: &mut App, context: BuildContext) -> WidgetRef {
let r = ThemeResources::of(app, context);
let radius = Radius::circular(r.app_bar_separator_corner_radius);
let line = |width: Option<f64>, height: Option<f64>| {
let mut sized = SizedBox::new();
if let Some(width) = width {
sized = sized.width(width);
}
if let Some(height) = height {
sized = sized.height(height);
}
ClipRRect::new()
.border_radius(BorderRadius::all(radius).into())
.child(sized.child(ColoredBox::new(r.app_bar_separator_foreground)))
};
let presentation = self.presentation;
if presentation.use_overflow_style {
return Margin::new(
r.app_bar_overflow_separator_margin,
line(None, Some(r.app_bar_overflow_separator_height)),
)
.into_widget();
}
let rectangle = Margin::new(
r.app_bar_separator_margin,
line(Some(r.app_bar_separator_width), None),
);
if presentation.is_compact {
Align::new()
.alignment(AlignmentGeometry::TOP_CENTER)
.height_factor(1.0)
.child(
SizedBox::new()
.height(r.app_bar_theme_compact_height)
.child(rectangle),
)
.into_widget()
} else {
rectangle.into_widget()
}
}
}