Gin
Loading...
Searching...
No Matches
BoxShadow Class Reference

CSS-style box shadows, painted by the PARENT under its children, because a shadow lies outside the component and would be clipped by it. More...

#include <gin_shadows.h>

Public Types

using Renderer = std::function<void (juce::Graphics&, const juce::Path& outline, const ShadowSpec&)>

Static Public Member Functions

static std::optional< ShadowList > parse (const juce::var &shadow)
 Parses a box shadow: a string of comma separated layers or an array of layer strings.
static void setRenderer (Renderer renderer)
 The renderer for every container that has none of its own; nullptr = no shadows.
static void setRenderer (juce::Component &container, Renderer renderer)
 A renderer for the shadows of this container's children; nullptr = the global one.
static void set (juce::Component &c, const juce::var &shadow)
 The component's shadow, as the layout's "boxShadow" entry sets it; void clears.
static void setRadius (juce::Component &c, float radius)
 The corner radius of the outline the shadow follows, as "borderRadius" sets it.
static void paintChildShadows (juce::Graphics &g, juce::Component &container)
 Paints the shadows of the container's children in its coordinates, as its layer does.

Detailed Description

CSS-style box shadows, painted by the PARENT under its children, because a shadow lies outside the component and would be clipped by it.

JSON Format

{ "id": "card", "boxShadow": "0 4 8 0.45, 0 12 30 0.6", "borderRadius": 14,
"states": { "hover": { "boxShadow": "0 6 10 0.5, 0 16 36 0.65" } },
"transition": { "boxShadow": "60 inOutQuad" } }
  • "boxShadow": one or more layers separated by commas (or a json array of strings), each "<x> <y> <blur> <opacity> [<spread>] [<colour>]": offset and blur in pixels, opacity 0..1 multiplying the colour's alpha, the colour black by default ("#ff3366", "ff00ff00" or a JUCE colour name like "red"). "none" or "" for no shadow.
  • "borderRadius": the corner radius of the outline the shadow follows, number or expression (e.g. "pillH / 2").
  • Animated with the "boxShadow" transition, usable in "states" like "alpha" and "scale".
  • The outline is the component's bounds with that radius, following its scale transform, its bounds transitions and its alpha.

Painting

The first shadow in a container adds an invisible layer as its first child (at the back, taking no clicks, ignored by the layout's maxX/maxY), which paints the shadows of all its siblings; so "zorder" indices count it. A container that clips (most do) needs room around shadowed children for the blur.

Renderer

Gin draws no blur itself: install a renderer once, e.g. at app start, otherwise no shadows are drawn at all:

gin::BoxShadow::setRenderer ([] (juce::Graphics& g, const juce::Path& outline, const gin::ShadowSpec& s)
{
// a blur library's drop shadow for outline with s.offset, s.blur, s.spread, s.colour
});

Code

gin::BoxShadow::set (tile, "0 3 6 0.45, 0 8 24 0.6");
gin::BoxShadow::setRadius (tile, 14.0f);

Member Typedef Documentation

◆ Renderer

using BoxShadow::Renderer = std::function<void (juce::Graphics&, const juce::Path& outline, const ShadowSpec&)>

Member Function Documentation

◆ parse()

std::optional< ShadowList > BoxShadow::parse ( const juce::var & shadow)
static

Parses a box shadow: a string of comma separated layers or an array of layer strings.

Returns
std::nullopt when malformed; an empty list for "none", "" or void

◆ setRenderer() [1/2]

void BoxShadow::setRenderer ( Renderer renderer)
static

The renderer for every container that has none of its own; nullptr = no shadows.

◆ setRenderer() [2/2]

void BoxShadow::setRenderer ( juce::Component & container,
Renderer renderer )
static

A renderer for the shadows of this container's children; nullptr = the global one.

◆ set()

void BoxShadow::set ( juce::Component & c,
const juce::var & shadow )
static

The component's shadow, as the layout's "boxShadow" entry sets it; void clears.

◆ setRadius()

void BoxShadow::setRadius ( juce::Component & c,
float radius )
static

The corner radius of the outline the shadow follows, as "borderRadius" sets it.

◆ paintChildShadows()

void BoxShadow::paintChildShadows ( juce::Graphics & g,
juce::Component & container )
static

Paints the shadows of the container's children in its coordinates, as its layer does.


The documentation for this class was generated from the following file: