use teksilo_core::build_context::BuildContext;
use teksilo_core::color_prop::ColorProp;
use teksilo_core::styles::{BadgeStyle, BadgeStyleConfig};
use teksilo_core::widget_id::WidgetId;
use teksilo_tokens::{CornerRadius, SurfaceRole};
use crate::primitives::{Padding, RectWidget, ZStack};
pub const BADGE_PADDING_HORIZONTAL: f32 = 6.0;
pub const BADGE_PADDING_VERTICAL: f32 = 1.0;
pub const BADGE_CORNER_RADIUS: f32 = 9999.0;
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct BadgeRecipe {
pub padding_horizontal: f32,
pub padding_vertical: f32,
pub corner_radius: f32,
}
impl Default for BadgeRecipe {
fn default() -> Self {
Self {
padding_horizontal: BADGE_PADDING_HORIZONTAL,
padding_vertical: BADGE_PADDING_VERTICAL,
corner_radius: BADGE_CORNER_RADIUS,
}
}
}
#[derive(Debug, Default, Clone, Copy)]
pub struct RecipeBadgeStyle {
pub recipe: BadgeRecipe,
}
impl RecipeBadgeStyle {
pub fn new(recipe: BadgeRecipe) -> Self {
Self { recipe }
}
}
impl BadgeStyle for RecipeBadgeStyle {
fn make_body(&self, cfg: &BadgeStyleConfig, ctx: &mut BuildContext) -> WidgetId {
let bg: ColorProp = cfg
.background_override
.clone()
.unwrap_or(ColorProp::SurfaceRole(SurfaceRole::AccentSubtle));
let bg_rect = ctx.add(
RectWidget::new()
.background(bg)
.corner_radius(CornerRadius::uniform(self.recipe.corner_radius)),
);
let padding_id = ctx.add(
Padding::symmetric(self.recipe.padding_vertical, self.recipe.padding_horizontal)
.child_id(cfg.content),
);
ctx.add(ZStack::new().add_child(bg_rect).add_child(padding_id))
}
}