Describing the UI
Before an interface reacts or animates, it has to exist: screens, the shapes and texts on them, their places and their sizes. This chapter shows how you describe all of it in Java, as a tree of nodes inside a UI, on a canvas that JOID fits to any window. The Catalog shows every node with a capture, when you look for one.
A UI is a class that builds its nodes in init(); you open it, and JOID draws it until you close it.
JOID.open(new MenuUI());Read UIs to learn the life of a UI, how to keep it open and how to configure it.
Nodes and the tree
Section titled “Nodes and the tree”Everything a UI shows is a node, created by a factory, configured by setters and attached to the UI or to another node.
RectNode.create(660, 490, 600, 100).color(ToolbarUI.SURFACE).attach(this);Read Nodes and the tree to learn how to nest nodes and how positions follow the tree.
Node lifecycle
Section titled “Node lifecycle”A node joins a UI, lives there for many frames and leaves; listeners run your code at each of these moments.
.onInit(event -> this.frames = 0L).onUpdate(event -> this.frames++)Read Node lifecycle to learn when each listener runs and what to release when a node leaves.
The design canvas
Section titled “The design canvas”You place every node on a 1920 × 1080 canvas of design pixels, and JOID fits it to the window.
RectNode.create(0, 0, 0, 0).color(EdgesUI.ELEMENT).x(() -> super.getViewX()).y(() -> super.getViewY()).width(() -> super.getViewWidth()).height(() -> super.getViewHeight()).attach(this);Read The design canvas to learn how the canvas fits windows of any shape, how to reach their edges and how to zoom.
Position and size
Section titled “Position and size”A node is placed and sized from its parent; anchors, zindex, visibility and copies refine it.
RectNode.create(60, 60, 200, 200).color(OrderUI.MUTED).zindex(1).attach(card);RectNode.create(160, 100, 200, 200).color(OrderUI.ACCENT).attach(card);RectNode.create(340, 140, 200, 200).color(OrderUI.ELEMENT).body(front -> RectNode.create(-40, -40, 120, 120).color(OrderUI.MUTED).zindex(-1).attach(front)).attach(card);Read Position and size to learn how to size from a parent, keep a point fixed and choose what is on top.
Overlays and popups
Section titled “Overlays and popups”A popup opens above the current screen and keeps the input until it closes; an overlay stays open while screens open and close.
@UIDataPopup(active = true)public class ConfirmPopup extends UI {Read Overlays and popups to learn how UIs stack, how a popup dims the screen and how an overlay takes input.
Layout
Section titled “Layout”A node never moves its children; a layout node does, and any node can clip or scroll what goes beyond it.
RectNode.create(20, 20, 360, 260).color(OverflowUI.ELEMENT).overflow(OverflowProperty.HIDDEN).body(area -> RectNode.create(40, 60, 360, 140).color(OverflowUI.ACCENT).attach(area)).attach(card);Read Layout to learn the layout rule, groups, clipping and scrolling.
Flex layout
Section titled “Flex layout”A flex node lines its children up in a column or a row, and grows to fit them.
FlexNode.vertical(20, 20, 360).margin(10D).body(flex -> { RectNode.create(0, 0, 200, 50).color(FlexCasesUI.ACCENT).attach(flex); RectNode.create(0, 0, 120, 50).color(FlexCasesUI.ACCENT).attach(flex); RectNode.create(0, 0, 280, 50).color(FlexCasesUI.ACCENT).attach(flex); RectNode.create(0, 0, 160, 50).color(FlexCasesUI.ACCENT).attach(flex);}).attach(card);Read Flex layout to learn its rule, case by case.
Grid layout
Section titled “Grid layout”A grid node fills rows of cells and wraps at its width.
GridNode.create(20, 20, 360, 0).margin(10D).body(grid -> { for (int i = 0; i < 9; i++) { RectNode.create(0, 0, 80, 80).color(GridCasesUI.ACCENT).attach(grid); }}).attach(card);Read Grid layout to learn its rule, case by case.
A text node draws a text in a style that names its font, size and color.
TextNode.create(50, 50).text(Text.create("Hello JOID", title)).attach(card);Read Text to learn styles, alignment, long texts and measures.
Your application loads its own fonts, once.
public final class AppFonts {
public static final MsdfFont MONTSERRAT = MsdfFontLoader.load( "fonts/Montserrat/Montserrat-Regular.ttf", "fonts/Montserrat/Montserrat-Bold.ttf" ).join();
private AppFonts() {}
}Read Fonts to learn how weights are picked and which kind of font to choose.
Text markup and effects
Section titled “Text markup and effects”Markup styles parts of a string, and effects change its glyphs as they are drawn.
final TextInfo tagged = info.withMarkups(MarkupUI.MARKUP);TextNode.create(50, 50).text(Text.create("Read the <b>terms</b>, then <em>accept</em> them", tagged)).attach(card);Read Text markup and effects to learn how to write a markup, an effect, a modifier and a converter.
Images and media
Section titled “Images and media”A resource is an image, an animation or a video that a node draws or plays.
final Resource image = Resource.of("images/placeholder.png");Read Images and media to learn how to fit, tint and crop images, play videos, and which formats JOID reads.
