Copy a mockup
A mockup gives every position, size, color and text style of a screen. This guide turns those values into nodes without conversion, then lays the mockup over the result to check every edge.
What you will build
Section titled “What you will build”
Before you start
Section titled “Before you start”- The design canvas and design pixels: The design canvas.
- Positions and sizes of nodes: Position and size.
- Text styles: Text.
- Rounded corners and shadows: Effects.
- The mockup, drawn on a frame of 1920 × 1080, and an export of that frame as a PNG of the same size.
1. Draw the mockup on a 1920 × 1080 frame
Section titled “1. Draw the mockup on a 1920 × 1080 frame”A UI places its nodes on a design canvas of 1920 × 1080 design pixels, which JOID scales to the window. When the frame of the mockup has the same size, every value of the mockup is a value of JOID.
Check: the frame of the mockup measures 1920 × 1080.
2. Turn each part of the mockup into a node
Section titled “2. Turn each part of the mockup into a node”Give the position and the size of each layer to create(x, y, width, height).
The position of a child is relative to its parent: subtract the position of the parent layer.
A hexadecimal color goes through Color.decode, in a constant of the UI:
private static final Color TEXT = Color.decode("#E7E9EE").lock();private static final Color MUTED = Color.decode("#8B93A3").lock();private static final Color ACCENT = Color.decode("#5B8CFF").lock();private static final Color ELEMENT = Color.decode("#262B35").lock();private static final Color SURFACE = Color.decode("#171A21").lock();private static final Color SHADOW = Color.decode("#00000099").lock();private static final Color ON_ACCENT = Color.decode("#0E1014").lock();A corner radius becomes a RoundedNodeEffect, and a shadow becomes a ShadowNodeEffect with the same color, blur and offset:
RectNode.create(660, 290, 600, 500).color(MockupGuideUI.SURFACE).effect(RoundedNodeEffect.create(24F)).effect(ShadowNodeEffect.create(MockupGuideUI.SHADOW, 30F).offsetY(8D)).body(card -> { CircleNode.create(240, 60, 120).color(MockupGuideUI.ELEMENT).attach(card); TextNode.create(300, 230).text(Text.create("Ada Lovelace", name)).anchorX(Align.CENTER).attach(card); TextNode.create(300, 290).text(Text.create("Analyst", role)).anchorX(Align.CENTER).attach(card); RectNode .create(200, 380, 200, 64) .color(MockupGuideUI.ACCENT) .effect(RoundedNodeEffect.create(32F)) .label(Text.create("Follow", role.withColor(MockupGuideUI.ON_ACCENT))) .attach(card);}).attach(this);Here the card sits at 660, 290 on the frame, and the avatar at 900, 350: inside the card, the avatar is at 240, 60.
Check: the card has the size, the corners and the shadow of the mockup.
3. Copy the text styles
Section titled “3. Copy the text styles”The font size of the mockup is the font size of the TextInfo.
Letter spacing and line height are written as shares, where 1F is 100 %: a letter spacing of -2 % is -0.02F, a line height of 140 % is 1.4F.
final TextInfo name = TextInfo.create(ExampleFont.REGULAR, 32F).weight(FontWeight.BOLD).letterSpacing(-0.02F).color(MockupGuideUI.TEXT);final TextInfo role = TextInfo.create(ExampleFont.REGULAR, 22F).lineHeight(1.4F).color(MockupGuideUI.MUTED);Use the font of the mockup, in the same weights (Replace a font).
Check: the name and the role have the width and the height of the texts of the mockup.
4. Lay the mockup over the UI
Section titled “4. Lay the mockup over the UI”Hold whether the mockup shows in a BooleanSignal, false at first:
final BooleanSignal mockup = new BooleanSignal(false);Draw the exported mockup over the whole canvas at half opacity, let the mouse through it, and toggle it with a Shortcut on F2:
ResourceNode.create(0, 0, 1920, 1080).resource(Resource.of("/guides/mockup.png")).color(Color.WHITE.withAlpha(0.5F)).visible(mockup).interactive(false).attach(this);
Shortcut.create(Key.F2).onTrigger(event -> mockup.toggle()).attach(this);color(Color.WHITE.withAlpha(0.5F)) tints the image at 50 % opacity, and interactive(false) lets clicks reach the nodes under it.
Check: press F2.
Where the copy matches, the edges of the UI and of the mockup overlap exactly; a node that is off shows a double edge.
Resize the window: the mockup and the UI scale together, because both live on the design canvas.
F2 shows and hides the mockup over the UI: a shape that keeps a single edge is copied pixel for pixel.
The mockup marks each text with a bar, so the text only has to sit on its bar.
With the dev jar, a click on a node with Inspect on locks it, and the dev panel lists its bounds (Inspect a UI). Pixel alignment explains where each edge lands on the screen.
If it does not work
Section titled “If it does not work”- Everything is shifted or scaled: the frame of the mockup is not 1920 × 1080; resize the frame, or scale every value by the same factor.
- A child is offset by the position of its parent: its position was copied from the frame; subtract the position of the parent layer.
- A text is wider or narrower than in the mockup: the font or the weight differs, or the letter spacing was written as a percentage (
-2Finstead of-0.02F). - A magenta and black checkerboard covers the canvas, or nothing shows with the prod jar: the path of the PNG is wrong, and the dev jar prints the cause.
- Clicks stop working while the mockup shows: the image misses
interactive(false).
