NodeEffect
abstract class NodeEffect<T extends Node>
Implements: Cloneable
Known subtypes: BlurNodeEffect, BorderNodeEffect, CircleNodeEffect, MaskNodeEffect, RoundedNodeEffect, ShadowNodeEffect, TransformNodeEffect
Package: dev.joid.lib.ui.node.effect · Module: core · Source: NodeEffect.java
Base of every effect, an object added to a node that changes how the node is drawn, never its layout nor the area that receives the mouse.
Description
Section titled “Description”A NodeEffect changes how its node is drawn: it draws around the node, changes the matrix or the render state for it, or processes its pixels with shader passes.
Node.effect adds one to any node, and a node holds one effect per class.
Use the built-in effects first: RoundedNodeEffect, CircleNodeEffect, BorderNodeEffect, ShadowNodeEffect, BlurNodeEffect, MaskNodeEffect and TransformNodeEffect.
Extend NodeEffect for a treatment that none of them gives: Draw around a node writes one.
Every frame, JOID keeps the effects whose shouldApply returns true and orders them by priority: the lowest priority wraps the others, and its passes run first.
The type parameter limits the nodes that take the effect: a NodeEffect<RectNode> goes on a RectNode and its subclasses only.
Learn more
Section titled “Learn more”Creation
Section titled “Creation”| Returns | Signature | Summary |
|---|---|---|
| NodeEffect() protected | Called by a subclass for an effect of priority 0. | |
| NodeEffect(int priority) protected | Called by a subclass for an effect of the given priority. |
Properties
Section titled “Properties”| Property | Type | Default | Summary |
|---|---|---|---|
| priority signal | int | set at creation | Place of the effect among the effects of its node: a lower priority starts earlier and wraps the effects of higher priority, and its shader passes run before theirs. |
| scope signal | NodeEffectScope | NodeEffectScope.SELF | What the shader passes of the effect process: SELF, the drawing of the node alone, or CHILDREN, the node with its children and its layers. |
Methods
Section titled “Methods”| Returns | Signature | Summary |
|---|---|---|
void | draw(T node, Runnable body) | Hook that JOID calls on every frame while the effect applies, in the coordinates of the parent: the node sits at getX(), getY(). |
boolean | shouldApply(T node) | Hook that JOID calls on every frame before the node draws: false skips draw and the shader passes for this frame. |
IShaderPass | toShaderPass(T node) | Hook that returns the single IShaderPass that processes the pixels of the node on this frame, or null for an effect without pass. |
List<IShaderPass> | toShaderPasses(T node) | Hook that returns every pass of the effect for this frame, in order. |
E | copy() | Returns a shallow copy of the effect: the copy shares the values and the suppliers of the original. |
For subclasses
Section titled “For subclasses”| Returns | Signature | Summary |
|---|---|---|
void | init(T node, UI ui) hook | Hook that JOID calls when the node joins a UI, and when the effect is added to a node that is already in one. |
void | detach(T node) hook | Hook that JOID calls when the node leaves its UI, and when the effect is removed or replaced on a node that is in one. |
Creation details
Section titled “Creation details”NodeEffect
Section titled “NodeEffect”NodeEffect() protected
Called by a subclass for an effect of priority 0.
NodeEffect(int priority) protected
Called by a subclass for an effect of the given priority.
Property details
Section titled “Property details”priority
Section titled “priority”this priority(int priority)fluentthis priority(Supplier<Integer> priority)fluent signalint getPriority()
Default: set at creation
Place of the effect among the effects of its node: a lower priority starts earlier and wraps the effects of higher priority, and its shader passes run before theirs. Two effects of the same priority keep the order in which they were added.
this scope(NodeEffectScope scope)fluentthis scope(Supplier<NodeEffectScope> scope)fluent signalNodeEffectScope getScope()
Default: NodeEffectScope.SELF
What the shader passes of the effect process: SELF, the drawing of the node alone, or CHILDREN, the node with its children and its layers.
It has no effect on draw, which always wraps the node and its children.
Method details
Section titled “Method details”void draw(T node, Runnable body)
Hook that JOID calls on every frame while the effect applies, in the coordinates of the parent: the node sits at getX(), getY().
An override draws before or after body, or changes the matrix or the render state around it and restores them; it runs body once, or the node disappears.
By default, it runs body alone.
shouldApply
Section titled “shouldApply”boolean shouldApply(T node)
Hook that JOID calls on every frame before the node draws: false skips draw and the shader passes for this frame.
The built-in effects return false when they would change nothing, such as a border of width 0.
toShaderPass
Section titled “toShaderPass”IShaderPass toShaderPass(T node)
Hook that returns the single IShaderPass that processes the pixels of the node on this frame, or null for an effect without pass.
JOID calls it on every frame while the effect applies, so the pass can carry the current values of the effect.
An effect with passes draws its node off screen first (Performance).
toShaderPasses
Section titled “toShaderPasses”List<IShaderPass> toShaderPasses(T node)
Hook that returns every pass of the effect for this frame, in order.
By default, it returns the pass of toShaderPass, or no pass; override it for an effect that needs several passes, such as a blur in two directions.
<E extends NodeEffect<T>> E copy()
Throws:
IllegalStateException: …
Returns a shallow copy of the effect: the copy shares the values and the suppliers of the original.
Node.copy copies the effects of a node with it.
void init(T node, UI ui) hook
Hook that JOID calls when the node joins a UI, and when the effect is added to a node that is already in one. Override it to create what the effect needs for this node; it does nothing by default.
detach
Section titled “detach”void detach(T node) hook
Hook that JOID calls when the node leaves its UI, and when the effect is removed or replaced on a node that is in one.
Override it to release what init created; it does nothing by default.
An instance added to several nodes receives it once for each node.
fluent returns the instance, typed for chaining · factory creates an instance · signal also accepts a value that follows signals, as a signal, an expression or a lambda (When does JOID compute this value again?) · hook called by JOID, override it · abstract you implement it · default interface method with a body · static called on the class · protected visible to subclasses
