Interactivity
An interface that only draws is a picture. This chapter makes it answer the user: nodes react to the mouse and the keyboard, show values that change, follow the pointer, move under a drag, take text and hold values. Each page builds on the previous one.
Events
Section titled “Events”A node reports what happens to it through listeners that you give to its methods. An input travels through the node tree from the front to the back, and the first listener that consumes it keeps it.
RectNode.create(100, 80, 200, 60).color(ClickUI.ELEMENT).onClick(event -> clicks.increment()).attach(card);Read Events to learn the three kinds of events, how to consume an input and how to refuse a change.
Signals
Section titled “Signals”A signal holds a value that changes; a setter given an expression that reads it follows it.
TextNode.create(60, 160).text(Text.create("Clicks: " + this.clicks.get(), info)).attach(card);Read Signals to learn when JOID computes a value again, what an expression can follow, and which signal type to pick.
Hover, tooltips and cursors
Section titled “Hover, tooltips and cursors”A node tracks whether the pointer is over it, and can change its look, show a tooltip or set the cursor.
button.hoveredColor(HoverUI.HOVER).hover(() -> "Opens the shop").cursor(Cursor.POINTER);Read Hover, tooltips and cursors to learn the hover animation, the tooltips and the cursors.
Drag and drop
Section titled “Drag and drop”One setter makes a node draggable inside an area, and a list of nodes gives it targets to drop on.
square.draggable(DraggableProperty.parent().snap(left, middle, right));Read Drag and drop to learn the areas, the drop targets and the copies.
Keyboard and shortcuts
Section titled “Keyboard and shortcuts”The keyboard sends keys and typed characters to the nodes, then to the UI and its shortcuts.
Shortcut.create(Key.S).ctrl(true).onTrigger(event -> this.save()).attach(this);Read Keyboard and shortcuts to learn who receives the keys, how to tell a letter from its place, and how to bind shortcuts.
Controls
Section titled “Controls”Every control follows the same pattern: options, a value bound to a signal, beforeChange and onChange.
new IntegerSliderNode(240, 140, 300, 40) {}.range(0, 10).track(...).thumb(...).value(this.volume).attach(card);Read Controls to learn the pattern, the order of a change and the options of each control.
Text fields
Section titled “Text fields”A text field turns what the user types into a value: a text, a number, or a type of your own.
IntegerFieldNode.create(60, 60, 240, 60).info(info).value(this.players).attach(card);Read Text fields to learn the focus, the rules on the text and your own fields.
Reorderable lists
Section titled “Reorderable lists”A ReorderableFlexNode is a row or a column whose items the user drags into a new order.
ReorderableFlexNode.vertical(60, 40, 480).onReorderEnd(event -> this.save()).attach(card);Read Reorderable lists to learn the reorder events, the handles and the pinned items.
