Enum Class UI.ShadowType
- All Implemented Interfaces:
Serializable,Comparable<UI.ShadowType>,Constable,ShadowFractionsSupplier,UIEnum<UI.ShadowType>
- Enclosing class:
UI
ShadowConf.
Pass one of these to ShadowConf.type(swingtree.UI.ShadowType)
as part of the style API (see UIForAnySwing.withStyle(Styler)).
Real world shadows are produced by very different optical situations, and they
rarely fade in a perfectly straight line. Each transition therefore corresponds to a
particular real world phenomenon and is backed by a specific mathematical
falloff function f(t), which describes the shadow intensity
(1 = full shadow color, 0 = fully transparent) as a function of the
normalized distance t in [0, 1] away from the solid edge of the shadow
(t = 0 at the solid edge, t = 1 at the far, transparent end of the blur).
A quick guide to picking one:
- For a natural soft drop shadow, use
BLUR(most authentic) orPENUMBRA(cheaper, visually almost identical). - For an object resting on a surface, use
CONTACT. - For a diffuse glow or light bleed, use
GLOW. - For the cheapest, non-physical fade, use
FLAT. - For stylized, decorative effects, see the eccentric transitions
STAIRS,RIPPLE,SAWTOOTHandBOUNCE.
frac(x) denotes the
fractional part x - floor(x).- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>> -
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionThe exact edge profile you get by convolving a hard shadow edge with a Gaussian blur kernel.An eccentric, non-physical transition: an "ease-out-bounce" where the shadow settles toward transparency with a few diminishing rebounds, like a ball bouncing to rest.A sharp drop right at the element followed by a long, faint tail.A constant rate fade from full shadow color to transparency, producing a perfectly straight falloff.A bell-shaped falloff that holds full strength right at the element and then rolls off following a Gaussian curve, giving a soft, diffuse, evenly spreading look.A smooth, symmetric S-curve that holds the shadow strong near the element, fades fastest through the midpoint and then eases gently into transparency.An eccentric, non-physical transition: a cosine wave under a linear decay envelope, so the shadow oscillates between strong and transparent while fading out.An eccentric, non-physical transition: repeating linear ramps under a decay envelope, producing louvered, venetian-blind-like banding that fades with distance.An eccentric, non-physical transition that posterizes the falloff into a fixed number of discrete bands (N = 5) instead of fading smoothly, producing a stepped, "cel-shaded" or contour-map look. -
Method Summary
Modifier and TypeMethodDescriptionsprouts.Tuple<Float> Supplies the shadow falloff fractions, that is the shadow intensities (1= full shadow color,0= fully transparent) sampled at evenly spaced positionst = i / naway from the solid edge of the shadow, wherenis one less than the size of the returned tuple.static UI.ShadowTypeReturns the enum constant of this class with the specified name.static UI.ShadowType[]values()Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
FLAT
A constant rate fade from full shadow color to transparency, producing a perfectly straight falloff. This does not correspond to any real world shadow, it is simply the most neutral and the cheapest transition to render: it needs only a 2 or 3 stop gradient and no curve sampling, which is why it is the historical default.Falloff:
f(t) = 1 - t -
PENUMBRA
A smooth, symmetric S-curve that holds the shadow strong near the element, fades fastest through the midpoint and then eases gently into transparency. This mimics the penumbra of a shadow cast by an area light source (a window, an overcast sky, a softbox), where the soft edge comes from the light source being partially occluded across a finite angular width.It is a cheap polynomial approximation of
BLUR(the two are visually almost indistinguishable) and so makes an excellent, performant default for soft UI shadows.Falloff (the "smoothstep" function):
f(t) = 1 - t2(3 - 2t) -
BLUR
The exact edge profile you get by convolving a hard shadow edge with a Gaussian blur kernel. This is what classical CSSbox-shadowand design tools such as Figma or Photoshop produce, making it the most authentic and most familiar looking soft drop shadow.Note that, perhaps counter-intuitively, blurring a sharp edge with a (bell shaped) Gaussian kernel does not yield a bell shaped falloff but rather the integral of the Gaussian, the error function
erf, which is a symmetric S-curve. (For a bell shaped falloff, seeGLOWinstead.)Falloff (normalized error function, with steepness
k):
f(t) = (erf(k/2) - erf(k(t - 1/2))) / (2 * erf(k/2)) -
GLOW
A bell-shaped falloff that holds full strength right at the element and then rolls off following a Gaussian curve, giving a soft, diffuse, evenly spreading look. This does not mimic a cast shadow edge (seeBLURfor that), but rather a glow, a halo or light bleed radiating from the element, and works well for neon, highlights or emissive surfaces.Falloff (normalized Gaussian bell, with width
k):
f(t) = (exp(-k t2) - exp(-k)) / (1 - exp(-k)) -
CONTACT
A sharp drop right at the element followed by a long, faint tail. This mimics a contact shadow (ambient occlusion): the darkening where an object rests on or nearly touches a surface, which is most intense at the contact line and fades away with distance. It gives objects a grounded, tangible feel.Falloff (normalized exponential decay, with rate
k):
f(t) = (exp(-k t) - exp(-k)) / (1 - exp(-k)) -
STAIRS
An eccentric, non-physical transition that posterizes the falloff into a fixed number of discrete bands (N = 5) instead of fading smoothly, producing a stepped, "cel-shaded" or contour-map look. Useful for retro, poster or technical drawing aesthetics.Falloff (quantized linear, with
Nbands):
f(t) = round((1 - t) * (N - 1)) / (N - 1) -
RIPPLE
An eccentric, non-physical transition: a cosine wave under a linear decay envelope, so the shadow oscillates between strong and transparent while fading out. This produces concentric shadow rings, like ripples spreading on water or a radar ping.Falloff (damped cosine, with
kripples):
f(t) = (1 - t) * (1/2 + 1/2 * cos(2*Math.PI*k*t)), withk = 3 -
SAWTOOTH
An eccentric, non-physical transition: repeating linear ramps under a decay envelope, producing louvered, venetian-blind-like banding that fades with distance.Falloff (decaying sawtooth, with
klouvers):
f(t) = (1 - t) * (1 - frac(k t)), withk = 4 -
BOUNCE
An eccentric, non-physical transition: an "ease-out-bounce" where the shadow settles toward transparency with a few diminishing rebounds, like a ball bouncing to rest. The classic easing curve, repurposed as a shadow falloff.Falloff:
f(t) = 1 - easeOutBounce(t)
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum class has no constant with the specified nameNullPointerException- if the argument is null
-
getFractions
Description copied from interface:ShadowFractionsSupplierSupplies the shadow falloff fractions, that is the shadow intensities (1= full shadow color,0= fully transparent) sampled at evenly spaced positionst = i / naway from the solid edge of the shadow, wherenis one less than the size of the returned tuple.- Specified by:
getFractionsin interfaceShadowFractionsSupplier- Returns:
- A
Tupleof at least two falloff fractions, ordered from the solid edge of the shadow (t = 0) to the far, transparent end of the blur (t = 1).
-