Effects
An effect changes how a node is drawn: rounded corners, a border, a shadow, a blur, a mask or a transform. It never changes the layout, and it works on every node, built-in or yours. This page shows how to add effects, drive them with changing values, and predict the result when several of them stack.
You will learn
- How to add effects to a node and stack them
- How to drive an effect with a value that changes
- How to round a node together with its children
- In which order JOID applies effects, and how to change it
- How to clip your own drawing to a rectangle or an image
Add effects to a node
Section titled “Add effects to a node”Node.effect adds an effect to a node and returns the node, so effects chain like any other setter:
RectNode.create(150, 100, 300, 180).color(EffectsUI.SURFACE).effect(RoundedNodeEffect.create(24F)).effect(BorderNodeEffect.create(EffectsUI.ACCENT, 2F)).effect(ShadowNodeEffect.create(EffectsUI.ACCENT, 24F).offsetY(8D)).attach(this);
A node holds one effect per class: a second RoundedNodeEffect replaces the first.
Node.getEffect returns the effect of a class, or null, and hasEffect, removeEffect and clearEffects manage the others.
JOID ships seven effects; the catalog shows each one.
| You want | Effect |
|---|---|
| Rounded corners, on every corner or on some of them | RoundedNodeEffect |
| A round node cut from a square one | CircleNodeEffect |
| An outline that follows the drawn shape | BorderNodeEffect |
| A drop shadow or a glow | ShadowNodeEffect |
| A blurred node | BlurNodeEffect |
| Only part of a node visible, cut by a rectangle or an image | MaskNodeEffect |
| A node moved, rotated or scaled without touching the layout | TransformNodeEffect |
Each effect takes its main values in create(...) and the others through setters:
RoundedNodeEffect.create(radius)rounds every corner;top(false),bottom(false),left(false)andright(false)keep a side square, and a corner is rounded only when both of its sides are. The radius never goes past half the shorter side, socreate(1000F)turns a rectangle into a pill.BorderNodeEffect.create(color, width)outlines the pixels that the node draws: rounded corners, circles, glyphs, the opaque part of an image.mode(...)takes aBorderShader.BorderMode:BorderMode.OUT, the default, draws it outside the shape, andBorderMode.INinside;corners(false)leaves the corners of anOUTborder open.ShadowNodeEffect.create(color, blur)draws a shadow of the shape of the node, moved byoffsetX(...)andoffsetY(...)in design pixels. It does not read the pixels of the node: it draws a rounded rectangle with the radius of theRoundedNodeEffectof the node, a disc for aCircleNodeor a node with aCircleNodeEffect, and a plain rectangle otherwise.BlurNodeEffect.create(radius)blurs the node, by a radius in design pixels.MaskNodeEffect.create()keeps the whole node visible;x(...),y(...),width(...)andheight(...)place the rectangle that stays visible, from the top-left corner of the node, andresource(...)cuts it to the opaque part of an image stretched over that rectangle.TransformNodeEffect.create(transformation)applies aTransformationaround the center of the node (Drawing resources and transforms).
A border, a blur or a rounding of 0 does nothing, so a value that drops to 0 turns the effect off.
Drive an effect with a changing value
Section titled “Drive an effect with a changing value”Every setting of an effect takes a value or a Supplier, like a node setter (Signals).
Build the suppliers that read the node inside Node.self, which hands you the node:
RectNode.create(610, 100, 300, 180).color(EffectsUI.SURFACE).self(rect -> { rect.effect(RoundedNodeEffect.create(() -> 8F + rect.hoverValue(40F))); rect.effect(BorderNodeEffect.create(EffectsUI.ACCENT, 1F).width(() -> 1F + rect.hoverValue(5F)));}).attach(this);hoverValue(max) is the hover progress of the node scaled to max (Hover, tooltips and cursors).
An animator drives an effect through an expression: RoundedNodeEffect.create(40F * appear.get()).
Round a node with its children
Section titled “Round a node with its children”By default, an effect applies to the node alone, and its children draw on top of the result, untouched.
NodeEffect.NodeEffectScope.CHILDREN, given to scope(...), applies the effect to the node and its children together:
RectNode.create(1070, 80, 300, 220).color(EffectsUI.SURFACE).effect(RoundedNodeEffect.create(30F)).body(card -> { RectNode.create(0, 0, 300, 70).color(EffectsUI.ACCENT).attach(card);}).attach(this);
RectNode.create(1470, 80, 300, 220).color(EffectsUI.SURFACE).effect(RoundedNodeEffect.create(30F).scope(NodeEffectScope.CHILDREN)).body(card -> { RectNode.create(0, 0, 300, 70).color(EffectsUI.ACCENT).attach(card);}).attach(this);
SELF, the default, the rounded corners cut only the card; with CHILDREN, they cut its header too.
Use CHILDREN for a card whose content reaches its edges, such as an image header or a list that scrolls.
The scope matters for the effects that work on pixels (rounded, circle, blur and border): a shadow, a mask or a transform always covers the children.
Control the order of effects
Section titled “Control the order of effects”Each effect has a priority, and JOID applies the effects of a node in a fixed frame, whatever the order you add them in:

- The effects that wrap the drawing (
TransformNodeEffect,ShadowNodeEffect,MaskNodeEffectand most effects of your own) start, the lowest priority first. - The node draws itself.
- Its
SELFeffects that work on pixels run on that drawing, by priority: rounded or circle, then blur, then border. A border outlines the rounded corners whatever the order you add them in. - The children draw on top.
- The
CHILDRENeffects that work on pixels run on the node and its children together. - The wrapping effects end, in reverse order.
priority(...) changes the priority of an effect, and two effects of the same priority keep the order in which you added them.
In the example below, the Transformation turns each node by 20 degrees with Rotation.ROLL, in the plane of the screen (Rotate and scale a drawing).
A transform, at -100, wraps the mask, at 0, so the mask turns with the node; a mask given a priority under -100 wraps the transform, and stays in place while the node turns under it:
RectNode.create(250, 480, 200, 200).color(EffectsUI.ACCENT.withAlpha(0.3F)).effect(TransformNodeEffect.create(Transformation.create().rotate(20D, Rotation.ROLL))).attach(this);
RectNode.create(650, 480, 200, 200).color(EffectsUI.ACCENT.withAlpha(0.3F)).effect(TransformNodeEffect.create(Transformation.create().rotate(20D, Rotation.ROLL))).attach(this);
RectNode.create(250, 480, 200, 200).color(EffectsUI.ACTIVE).effect(TransformNodeEffect.create(Transformation.create().rotate(20D, Rotation.ROLL))).effect(MaskNodeEffect.create().y(70D).height(60D)).attach(this);
RectNode.create(650, 480, 200, 200).color(EffectsUI.ACTIVE).effect(TransformNodeEffect.create(Transformation.create().rotate(20D, Rotation.ROLL))).effect(MaskNodeEffect.create().y(70D).height(60D).priority(-200)).attach(this);
priority(-200) starts the mask before the transform, so it stays horizontal.
The faint rectangles, two other nodes, show the whole node.
The same rule places a shadow: at its own -50, it turns and moves with the node; with a priority under -100, it stays where the layout puts the node.
Custom effects shows how to write an effect of your own, and where its priority places it.
Clip your own drawing
Section titled “Clip your own drawing”MaskNodeEffect clips a node; the same clipping is open to your own drawing code.
UI.mask runs a drawing with everything outside a rectangle hidden:
RectNode.create(1270, 480, 300, 200).onDraw(event -> { final Node node = event.getNode(); final double centerX = node.getX() + node.getWidth() / 2D; final double centerY = node.getY() + node.getHeight() / 2D; super.mask(node.getX(), node.getY(), node.getWidth(), node.getHeight() / 2D, () -> { DrawUtils.SHAPE.drawCircle(centerX, centerY, EffectsUI.ACCENT, 90D); });}).attach(this);
The overload that takes a Resource first keeps the pixels where the image is opaque (alpha above 0.5F), to cut a drawing to a star, a logo or a rounded frame.
Masks nest: a mask started inside another one shows only what both of them keep.
Call mask while JOID draws, such as in Node.onDraw or in the draw of a custom node: outside a frame, drawing throws.
Drawing shapes and text explains the drawing calls.
effect(...)adds an effect to any node; effects stack, one per class.- An effect never changes the layout nor the area that receives the mouse.
- Every setting takes a value or a supplier;
self(...)gives the node to build suppliers on it. - Effects apply to the node alone;
CHILDRENapplies them to the node and its children together. - Wrapping effects run by priority, the lowest outermost; the pixel effects always run rounded or circle, then blur, then border.
- Give a
RectNodeits border through its setters or through aBorderNodeEffect, never both. UI.maskclips your own drawing to a rectangle or to the opaque part of an image.
Try it
Section titled “Try it”A pill button. Turn a 200 × 60 rectangle into a pill with a 2 design pixel blue border inside the shape.
Solution
.effect(RoundedNodeEffect.create(30F)).effect(BorderNodeEffect.create(EffectsUI.ACCENT, 2F).mode(BorderMode.IN))A radius of half the height gives round ends.
A shadow that stays on the ground.
A card turns with a TransformNodeEffect, and its shadow must stay upright under it.
What do you change?
Solution
The priority of the shadow: ShadowNodeEffect.create(color, 24F).priority(-200) starts it before the transform, so the transform leaves it in place.
