Package swingtree

Enum Class UI.ShadowType

All Implemented Interfaces:
Serializable, Comparable<UI.ShadowType>, Constable, ShadowFractionsSupplier, UIEnum<UI.ShadowType>
Enclosing class:
UI

@Immutable public static enum UI.ShadowType extends Enum<UI.ShadowType> implements UIEnum<UI.ShadowType>, ShadowFractionsSupplier
Defines the shape of the "falloff curve" of a shadow, that is to say, the way in which the shadow color fades from its full strength into full transparency across the blur region of a 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) or PENUMBRA (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, SAWTOOTH and BOUNCE.
See the individual constants below for the purpose, the real world analogue and the exact math of each falloff. In all formulas below 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 Constants
    Enum Constant
    Description
    The 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 Type
    Method
    Description
    sprouts.Tuple<Float>
    Supplies the shadow falloff fractions, that is the shadow intensities (1 = full shadow color, 0 = fully transparent) sampled at evenly spaced positions t = i / n away from the solid edge of the shadow, where n is one less than the size of the returned tuple.
    Returns the enum constant of this class with the specified name.
    static UI.ShadowType[]
    Returns an array containing the constants of this enum class, in the order they are declared.

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface swingtree.UIEnum

    isNoneOf, isNoneOf, isNoneOf, isOneOf, isOneOf, isOneOf
  • Enum Constant Details

    • FLAT

      public static final UI.ShadowType 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

      public static final UI.ShadowType 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

      public static final UI.ShadowType BLUR
      The exact edge profile you get by convolving a hard shadow edge with a Gaussian blur kernel. This is what classical CSS box-shadow and 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, see GLOW instead.)

      Falloff (normalized error function, with steepness k):
      f(t) = (erf(k/2) - erf(k(t - 1/2))) / (2 * erf(k/2))

    • GLOW

      public static final UI.ShadowType 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 (see BLUR for 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

      public static final UI.ShadowType 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

      public static final UI.ShadowType 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 N bands):
      f(t) = round((1 - t) * (N - 1)) / (N - 1)

    • RIPPLE

      public static final UI.ShadowType 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 k ripples):
      f(t) = (1 - t) * (1/2 + 1/2 * cos(2*Math.PI*k*t)), with k = 3

    • SAWTOOTH

      public static final UI.ShadowType 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 k louvers):
      f(t) = (1 - t) * (1 - frac(k t)), with k = 4

    • BOUNCE

      public static final UI.ShadowType 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

      public static UI.ShadowType[] 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

      public static UI.ShadowType valueOf(String name)
      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 name
      NullPointerException - if the argument is null
    • getFractions

      public sprouts.Tuple<Float> getFractions()
      Description copied from interface: ShadowFractionsSupplier
      Supplies the shadow falloff fractions, that is the shadow intensities (1 = full shadow color, 0 = fully transparent) sampled at evenly spaced positions t = i / n away from the solid edge of the shadow, where n is one less than the size of the returned tuple.
      Specified by:
      getFractions in interface ShadowFractionsSupplier
      Returns:
      A Tuple of 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).