use teksilo_core::build_context::BuildContext;
use teksilo_core::styles::{DropZoneStyle, DropZoneStyleConfig};
use teksilo_core::widget_id::WidgetId;
use teksilo_tokens::CornerRadius;
use crate::primitives::{Center, Padding, RectWidget, ZStack};
pub const DROP_ZONE_CORNER_RADIUS: f32 = 12.0;
pub const DROP_ZONE_BORDER_WIDTH: f32 = 2.0;
pub const DROP_ZONE_PADDING: f32 = 20.0;
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct DropZoneRecipe {
pub corner_radius: f32,
pub border_width: f32,
pub padding: f32,
}
impl Default for DropZoneRecipe {
fn default() -> Self {
Self {
corner_radius: DROP_ZONE_CORNER_RADIUS,
border_width: DROP_ZONE_BORDER_WIDTH,
padding: DROP_ZONE_PADDING,
}
}
}
#[derive(Debug, Default, Clone, Copy)]
pub struct RecipeDropZoneStyle {
pub recipe: DropZoneRecipe,
}
impl RecipeDropZoneStyle {
pub fn new(recipe: DropZoneRecipe) -> Self {
Self { recipe }
}
}
impl DropZoneStyle for RecipeDropZoneStyle {
fn make_body(&self, cfg: &DropZoneStyleConfig, ctx: &mut BuildContext) -> WidgetId {
let bg = cfg.state.map(|s| s.surface_role());
let border = cfg.state.map(|s| s.border_role());
let rect = ctx.add(
RectWidget::new()
.background(bg)
.border_color(border)
.border_width(self.recipe.border_width)
.corner_radius(CornerRadius::uniform(self.recipe.corner_radius)),
);
let centered =
Center::new().child(Padding::uniform(self.recipe.padding).child_id(cfg.content));
ctx.add(ZStack::new().add_child(rect).child(centered))
}
}