Skip to content

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.

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.

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.

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.

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.

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.

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.

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.

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.

Report a problem with this page