Skip to content

ui::ShadowRecipe

Header: winui/render/OverlayShadow.hpp.

The two superimposed black shadows that make up a drop shadow: an omnidirectional ambient and a downward-offset directional. Both are pure black, and only their alpha varies. Blur and offsets are in DIPs, alphas 0..1. Anything below Z 4 casts nothing, which is why a Fluent button has no shadow.

Example:

// A card-like Border at Z = 8, drawn under its own background.
const ui::Rect         bounds{16, 16, 240, 120};
const ui::Color        card_background = ui::colors::White;
const ui::ShadowRecipe recipe = ui::ShadowRecipe::for_elevation(ui::elevation_z::Card, theme.dark);
if (recipe.casts())
{
    ui::draw_drop_shadow(renderer, bounds, 8.0f, recipe);
}
renderer.fill_rounded_rect(bounds, 8.0f, card_background);

ambient_blur

float ambient_blur = 0.0f

Blur radius of the ambient shadow.

ambient_y

float ambient_y = 0.0f

Downward offset of the ambient shadow.

ambient_alpha

float ambient_alpha = 0.0f

Opacity of the ambient shadow; 0 draws none.

directional_blur

float directional_blur = 0.0f

Blur radius of the directional (key-light) shadow.

directional_y

float directional_y = 0.0f

Downward offset of the directional shadow.

directional_alpha

float directional_alpha = 0.0f

Opacity of the directional shadow; 0 draws none.

casts

bool casts() const

Whether either shadow is visible at all.

for_elevation

static ShadowRecipe for_elevation(float elevation, bool dark)

The drop-shadow recipe for elevation elevation, with the alphas for a light or dark theme. A dark theme's alphas are roughly double. Up to Z 32 there is no ambient shadow. In a light theme the directional alpha stops growing at Z 16, so a ToolTip and a Flyout have the same opacity and differ only in blur and offset. A dark theme uses a flat 0.26 up to Z 32.