Class Ripple

java.lang.Object
me.hackware.api.gui.Ripple

public final class Ripple extends Object
Port of nextui's Ripple.tsx (JoshMerlino/nextui, new-components): on press, a circle of the element's text colour (bg-current at the container's opacity-20) emits from the click point and grows to (max(w,h) + distFromCenter * 1.875) * 1.1 over 500ms along cubic-bezier(0, .5, 0, .75); it holds while pressed and fades out over 2 × duration on release. Clipped to the pressed element's rounded surface.

Multiple ripples can be live at once — rapid presses each spawn their own instance, and earlier ones keep growing/fading independently.

The bezier's x control points are both 0, so x(t) = t³ — progress inverts exactly via t = ∛x, no iterative solve needed.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Z-layers a ripple can belong to.
    static final int
     
    static final int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Begins the fade-out (mouseup) for every held ripple; growth keeps animating.
    void
    Renders every live ripple regardless of layer — the single-pass default.
    void
    render(UiContext ui, int layer)
    Renders the ripples on z-layer (or all layers when layer < 0).
    void
    render(UiContext ui, int layer, float alphaScale)
    render(UiContext, int) with every ripple on this layer scaled by alphaScale — so ripples on a surface that is itself fading (a closing confirm dialog) go with it instead of hanging at full strength over it.
    void
    trigger(int x, int y, int w, int h, double clickX, double clickY, int color, int surfaceRadiusPx)
    Starts a ripple on press.
    void
    trigger(int x, int y, int w, int h, double clickX, double clickY, int color, int layer, int surfaceRadiusPx)
    Single-radius variant on an explicit z-layer (LAYER_CONTENT etc).
    void
    trigger(int x, int y, int w, int h, double clickX, double clickY, int color, int tlPx, int trPx, int blPx, int brPx)
    Per-corner radii (tl, tr, bl, br) for the clip surface, on LAYER_CONTENT.
    void
    trigger(int x, int y, int w, int h, double clickX, double clickY, int color, int layer, int tlPx, int trPx, int blPx, int brPx)
    Canonical trigger: per-corner clip radii on an explicit z-layer.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • LAYER_CONTENT

      public static final int LAYER_CONTENT
      Z-layers a ripple can belong to. A ripple renders in the pass for the surface it was pressed on, so its clicked control keeps a Material ripple even when a higher layer (a popover it opens, a modal it lives in) draws over that control: the popover covers a LAYER_CONTENT ripple, while a LAYER_MODAL button's ripple still lands over the modal. Values are pass identifiers only, not a magnitude — screens choose when each runs.
      See Also:
    • LAYER_OVERLAY

      public static final int LAYER_OVERLAY
      See Also:
    • LAYER_MODAL

      public static final int LAYER_MODAL
      See Also:
  • Constructor Details

    • Ripple

      public Ripple()
  • Method Details

    • trigger

      public void trigger(int x, int y, int w, int h, double clickX, double clickY, int color, int surfaceRadiusPx)
      Starts a ripple on press. color is the element's text colour (bg-current); surfaceRadiusPx is the pressed surface's corner radius so the ripple clips to its rounded shape (overflow-hidden).
    • trigger

      public void trigger(int x, int y, int w, int h, double clickX, double clickY, int color, int layer, int surfaceRadiusPx)
      Single-radius variant on an explicit z-layer (LAYER_CONTENT etc).
    • trigger

      public void trigger(int x, int y, int w, int h, double clickX, double clickY, int color, int tlPx, int trPx, int blPx, int brPx)
      Per-corner radii (tl, tr, bl, br) for the clip surface, on LAYER_CONTENT.
    • trigger

      public void trigger(int x, int y, int w, int h, double clickX, double clickY, int color, int layer, int tlPx, int trPx, int blPx, int brPx)
      Canonical trigger: per-corner clip radii on an explicit z-layer.
    • release

      public void release()
      Begins the fade-out (mouseup) for every held ripple; growth keeps animating.
    • render

      public void render(UiContext ui)
      Renders every live ripple regardless of layer — the single-pass default.
    • render

      public void render(UiContext ui, int layer)
      Renders the ripples on z-layer (or all layers when layer < 0). Split a screen's single render(ui) into one call per layer, each at that layer's depth in the frame, and a control's ripple stays with its surface. A pass whose layer has no live ripples draws nothing.

      Fade-out and expiry are layer-independent: every pass prunes fully-faded instances across all layers, so a released ripple whose layer stopped rendering (its popover closed) can't linger — provided some pass runs each frame, which the always-present content pass guarantees.

    • render

      public void render(UiContext ui, int layer, float alphaScale)
      render(UiContext, int) with every ripple on this layer scaled by alphaScale — so ripples on a surface that is itself fading (a closing confirm dialog) go with it instead of hanging at full strength over it. Draw this pass inside that surface's transform and the ripples scale with it too.