use teksilo_canvas::EdgeInsets;
use teksilo_core::build_context::BuildContext;
use teksilo_core::styles::{PopoverStyle, PopoverStyleConfig, PopoverVariant};
use teksilo_core::widget::PendingChild;
use teksilo_core::widget_id::WidgetId;
use teksilo_tokens::SurfaceRole;
use crate::popover_surface::PopoverSurface;
pub const POPOVER_PADDING: f32 = 16.0;
pub const POPOVER_CORNER_RADIUS: f32 = 8.0;
pub const POPOVER_BORDER_WIDTH: f32 = 1.0;
pub const MENU_POPUP_CORNER_RADIUS: f32 = 8.0;
pub const POPOVER_SHADOW_DENSITY: f32 = 0.5;
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct PopoverRecipe {
pub padding: f32,
pub corner_radius: f32,
pub border_width: f32,
pub menu_popup_corner_radius: f32,
pub shadow_density: f32,
}
impl Default for PopoverRecipe {
fn default() -> Self {
Self {
padding: POPOVER_PADDING,
corner_radius: POPOVER_CORNER_RADIUS,
border_width: POPOVER_BORDER_WIDTH,
menu_popup_corner_radius: MENU_POPUP_CORNER_RADIUS,
shadow_density: POPOVER_SHADOW_DENSITY,
}
}
}
#[derive(Debug, Default, Clone, Copy)]
pub struct RecipePopoverStyle {
pub recipe: PopoverRecipe,
}
impl RecipePopoverStyle {
pub fn new(recipe: PopoverRecipe) -> Self {
Self { recipe }
}
}
impl PopoverStyle for RecipePopoverStyle {
fn make_body(&self, cfg: &PopoverStyleConfig, ctx: &mut BuildContext) -> WidgetId {
let (content_padding, background, corner_radius, presentational) = match cfg.variant {
PopoverVariant::Menu => (
EdgeInsets::ZERO,
SurfaceRole::Raised,
self.recipe.menu_popup_corner_radius,
true,
),
PopoverVariant::Default | PopoverVariant::Tooltip => (
EdgeInsets::uniform(self.recipe.padding),
SurfaceRole::Main,
self.recipe.corner_radius,
false,
),
};
ctx.add(PopoverSurface::new(
PendingChild::Id(cfg.content),
cfg.placement.clone(),
cfg.show_caret,
cfg.caret_size,
cfg.name.clone(),
content_padding,
background,
corner_radius,
presentational,
))
}
}