Skip to main content

paint_layered_shadow

Function paint_layered_shadow 

Source
pub fn paint_layered_shadow(
    canvas: &mut Canvas,
    bounds: Rect,
    radius: CornerRadius,
    outer: &Shadow,
    inner: &Shadow,
    density: f32,
    attached: Option<AttachedSide>,
)
Expand description

Paint a two-layer drop shadow behind a rounded rect.

The outer shadow is drawn unchanged. If density × inner.color.a() is above the sub-perceptual threshold (1/255), the inner shadow is drawn on top with its alpha scaled by density. This gives a “lift” look — a wide soft halo with a sharp close rim.

When attached is Some(side), both shadow draws are clipped so the penumbra on that side is hidden — matching the visual where the surface is attached to its anchor (popover under its trigger, dropdown under its combo box, etc.).

If both layers would be sub-perceptual (e.g. theme has zero alphas or density of 0), this function returns without emitting any draw commands.

// In a widget's paint() method:
use teksilo_widgets::shadow::{paint_layered_shadow, AttachedSide, DENSITY_SURFACE};
paint_layered_shadow(
    canvas, bounds, radius,
    &ctx.theme.shape.shadow_sm, &ctx.theme.shape.shadow_inner_sm,
    DENSITY_SURFACE, None,
);