teksilo_widgets/styles/
recipe_banner_style.rs1use teksilo_core::build_context::BuildContext;
19use teksilo_core::color_prop::ColorProp;
20use teksilo_core::styles::{BannerStyle, BannerStyleConfig};
21use teksilo_core::widget_id::WidgetId;
22use teksilo_tokens::{CornerRadius, VAlignment};
23
24use crate::primitives::{Expand, HStack, Padding, RectWidget, ZStack};
25
26pub const BANNER_PADDING_HORIZONTAL: f32 = 12.0;
31pub const BANNER_PADDING_VERTICAL: f32 = 10.0;
32pub const BANNER_CORNER_RADIUS: f32 = 8.0;
33pub const BANNER_GLYPH_SIZE: f32 = 16.0;
36pub const BANNER_CONTENT_GAP: f32 = 10.0;
39pub const BANNER_TITLE_DESCRIPTION_GAP: f32 = 2.0;
42
43#[derive(Debug, Clone, Copy, PartialEq)]
47pub struct BannerRecipe {
48 pub padding_horizontal: f32,
49 pub padding_vertical: f32,
50 pub corner_radius: f32,
51 pub glyph_size: f32,
52 pub content_gap: f32,
53 pub title_description_gap: f32,
54}
55
56impl Default for BannerRecipe {
57 fn default() -> Self {
58 Self {
59 padding_horizontal: BANNER_PADDING_HORIZONTAL,
60 padding_vertical: BANNER_PADDING_VERTICAL,
61 corner_radius: BANNER_CORNER_RADIUS,
62 glyph_size: BANNER_GLYPH_SIZE,
63 content_gap: BANNER_CONTENT_GAP,
64 title_description_gap: BANNER_TITLE_DESCRIPTION_GAP,
65 }
66 }
67}
68
69#[derive(Debug, Default, Clone, Copy)]
73pub struct RecipeBannerStyle {
74 pub recipe: BannerRecipe,
75}
76
77impl RecipeBannerStyle {
78 pub fn new(recipe: BannerRecipe) -> Self {
79 Self { recipe }
80 }
81}
82
83impl BannerStyle for RecipeBannerStyle {
84 fn make_body(&self, cfg: &BannerStyleConfig, ctx: &mut BuildContext) -> WidgetId {
85 let radius = CornerRadius::uniform(self.recipe.corner_radius);
86
87 let bg = ctx.add(
89 RectWidget::new()
90 .background(ColorProp::SurfaceRole(cfg.severity.surface()))
91 .corner_radius(radius),
92 );
93
94 let content = ctx.add(Expand::horizontal().child_id(cfg.content));
96 let row = ctx.add(
97 HStack::new()
98 .spacing(self.recipe.content_gap)
99 .alignment(VAlignment::Center)
100 .add_child(cfg.leading_glyph)
101 .add_child(content),
102 );
103 let padded = ctx.add(
104 Padding::symmetric(self.recipe.padding_vertical, self.recipe.padding_horizontal)
105 .child_id(row),
106 );
107
108 ctx.add(ZStack::new().add_child(bg).add_child(padded))
109 }
110}