Skip to content
View source

uiGenerated

Category: Packages · Manifest: use "kernels/";

A screen drawn per pixel.

A screen drawn per pixel: rectangles laid out, shapes painted, text written, and navigation through a list by the hands controls reads. What a program’s widgets look like is its own.

Layer: Interaction. Uses: text, controls.

use "ui.entpkg";
  • kernels/layout.ent — Rectangles a screen is laid out in, in its pixels, y down.
  • kernels/navigation.ent — Moving through a list of rows by a person’s hands as controls reads them. Kernels: ui.navigation_start@1, ui.navigation_keys@1, ui.navigate@2.
  • kernels/paint.ent — What a pixel of a screen is painted.
  • kernels/writing.ent — Text drawn.

tests/ holds scenes and their replays, run on every backend: navigation.replay. Every Kernel of the package is reached by one of them.

Used by the collapse, cube-puzzle, level, sound, spells, ui, voxel examples.

Kernel Mode Brief
ui.navigate@2 map The navigation after a frame through rows rows, round when wrap is 1, by hands (controls.read over ui.navigation_keys) and the pointer (controls.pointer). The list lies where its row list says, in the output’s pixels (its left, top, width, and the rows’ height), the rows gap apart, for the pointer: a scene’s layout works it out, the window’s size and scale known. active 0 holds it still, its row kept and nothing asked.
ui.navigation_keys@1 map The actions a list confirms and goes back by, for controls.read (domain = 2): Enter, Space or a pad’s south; Esc, Backspace or its east.
ui.navigation_start@1 map The navigation before any frame, row row lit.
Function Brief
rect_at(origin: Vec2, size: Vec2) -> Rect A rectangle from its top left and its size.
rect_size(r: Rect) -> Vec2
rect_middle(r: Rect) -> Vec2
contains(r: Rect, q: Vec2) -> Bool Whether the rectangle contains q: its low edges in, its high edges out.
near_rect(r: Rect, q: Vec2, by: Float) -> Bool Whether q is within by of it: a widget’s shadow or glow.
inset(r: Rect, by: Float) -> Rect Shrunk by by on every side; grown, by less than zero.
inset2(r: Rect, by: Vec2) -> Rect Shrunk by x across and y down, each side.
moved(r: Rect, by: Vec2) -> Rect Moved by by.
top_of(r: Rect, h: Float) -> Rect The top h of it, and the rest below; the left w, and the rest right of it; the bottom h, the right w.
below_top(r: Rect, h: Float) -> Rect
left_of(r: Rect, w: Float) -> Rect
right_of_left(r: Rect, w: Float) -> Rect
bottom_of(r: Rect, h: Float) -> Rect
right_of(r: Rect, w: Float) -> Rect
row_of(r: Rect, k: Int, n: Int, gap: Float) -> Rect Row k of n equal rows, gap between each.
column_of(r: Rect, k: Int, n: Int, gap: Float) -> Rect Column k of n equal columns, gap between each.
cell_of(r: Rect, c: IVec2, n: IVec2, gap: Float) -> Rect Cell c (column, row) of a grid of n (columns, rows), gap between each.
list_row(r: Rect, k: Int, h: Float, gap: Float) -> Rect Row k of rows h high from the top, gap between each: a list whose rows are a size, however many.
list_row_at(r: Rect, q: Vec2, h: Float, gap: Float, n: Int) -> Int Which of the list’s rows q falls in, h high and gap apart from the top; -1 outside them and in a gap.
span(r: Rect, from: Float, width: Float) -> Rect The part of r from from pixels from its left, width wide.
column_in(r: Rect, starts: Vec4, k: Int) -> Rect Column k (0 to 3) of a table’s row whose columns start starts pixels from its left: each up to where the next starts, the last (or one whose next starts no further right) up to the row’s right.
list_row_near(r: Rect, q: Vec2, h: Float, gap: Float, n: Int, lit: Int, by: Float) -> Int The row of a list (n rows h high, gap apart) a pixel is drawn by: the row it falls in, else the lit row (lit, -1 none) when q is within by of it, as a lit row’s band and mark reach past it; -1 none.
placed(r: Rect, size: Vec2, align: Vec2) -> Rect A thing size big placed in it: align 0 at its top or left, 0.5 in its middle, 1 at its bottom or right, each way; on whole pixels.
centered(middle: Vec2, size: Vec2) -> Rect A rectangle size big with its middle at middle, on whole pixels.
nav_confirm() -> Int The actions of ui.navigation_keys, by their place in its table.
nav_back() -> Int
row_state(nav: Nav, k: Int, enabled: Bool) -> Int What a widget in row k is with the navigation at nav: focused when lit, else idle; disabled when not enabled.
stepped(v: Int, by: Int, lo: Int, hi: Int) -> Int A count changed by by within lo to hi; round among n.
cycled(v: Int, by: Int, n: Int) -> Int
slid(v: Float, by: Int, step: Float) -> Float A level (0 to 1) changed by by steps of step.
clear() -> Vec4 Nothing: no color, no cover.
paint(c: Vec3, a: Float) -> Vec4 A color covering as much as a.
faded(p: Vec4, k: Float) -> Vec4 p with its cover times k.
over(under: Vec4, top: Vec4) -> Vec4 top over under, as a painter lays one coat on another.
onto(picture: Vec3, p: Vec4) -> Vec3 A painting laid over an opaque picture.
cover(d: Float) -> Float How much of a pixel a shape covers whose edge is d from its middle, less than zero inside.
rounded_distance(q: Vec2, r: Rect, radius: Float) -> Float The signed distance from q to a rectangle with corners rounded by radius: less than zero inside.
fill(r: Rect, radius: Float, color: Vec4, q: Vec2) -> Vec4 A rectangle filled, its corners rounded by radius.
outline(r: Rect, radius: Float, width: Float, color: Vec4, q: Vec2) -> Vec4 A rectangle’s edge, width wide inside it.
graded(r: Rect, radius: Float, from: Vec4, to: Vec4, q: Vec2) -> Vec4 A rectangle filled from at its top to to at its bottom.
shadow(r: Rect, radius: Float, by: Vec2, blur: Float, strength: Float, q: Vec2) -> Vec4 The soft shadow a rectangle casts by below and right, spread over blur pixels, strength at its darkest.
disc(middle: Vec2, radius: Float, color: Vec4, q: Vec2) -> Vec4 A disc, and a ring width wide inside its edge.
ring(middle: Vec2, radius: Float, width: Float, color: Vec4, q: Vec2) -> Vec4
segment(a: Vec2, b: Vec2, width: Float, color: Vec4, q: Vec2) -> Vec4 A line from a to b, width wide, its ends round.
arrow(middle: Vec2, size: Float, way: Int, color: Vec4, q: Vec2) -> Vec4 A triangle pointing one way from its middle, size across: 0 left, 1 right, 2 up, 3 down; on whole pixels, as pixel art draws one.
tick(origin: Vec2, size: Float, width: Float, color: Vec4, q: Vec2) -> Vec4 A tick in a box size across from origin.
line_reach() -> Float How far above and below its 8 texels a line’s letters may reach.
cell_cover(letters: Grid<Float>, cells: Rows<Int>, first: Int, col: Int, local: Vec2) -> Float The cover at local, in texels from the cell’s top left, of cell col of the row of letters from first: its letter, or its part of the wide letter it follows (one cell back, or two).
row_length(cells: Rows<Int>, row: Int, width: Int) -> Int How many cells of row row hold letters, its trailing spaces left off.
row_width(cells: Rows<Int>, row: Int, width: Int, scale: Float) -> Float How wide row row is drawn, in pixels at scale.
row_size(cells: Rows<Int>, row: Int, width: Int, scale: Float) -> Vec2 The size a row is drawn at, its 8 texels high.
row_cover(letters: Grid<Float>, cells: Rows<Int>, row: Int, width: Int, q: Vec2, origin: Vec2, scale: Float) -> Float The cover at q of row row drawn from origin, its top left.
written(letters: Grid<Float>, cells: Rows<Int>, row: Int, width: Int, q: Vec2, origin: Vec2, scale: Float, color: Vec4) -> Vec4 Row row in color, from origin.
shadowed(letters: Grid<Float>, cells: Rows<Int>, row: Int, width: Int, q: Vec2, origin: Vec2, scale: Float, color: Vec4, shade: Float) -> Vec4 Row row in color over its shadow, a texel down and right, of shade cover.
row_origin(cells: Rows<Int>, row: Int, width: Int, scale: Float, r: Rect, align: Vec2) -> Vec2 Where a row is drawn from to stand in r as align says (0 left or top, 0.5 middle, 1 right or bottom).
label(letters: Grid<Float>, cells: Rows<Int>, row: Int, width: Int, r: Rect, align: Vec2, scale: Float, color: Vec4, q: Vec2) -> Vec4 Row row in color aligned in r, with its shadow; cut at r‘s sides, and nothing above or below it but the letters’ reach.
figures(v: Int) -> Int How many characters v is written with: its digits, - first when it is below zero.
figure_code(v: Int, i: Int) -> Int The code of character i of v written out, most significant first.
number_size(v: Int, scale: Float) -> Vec2 The size v is drawn at.
number_cover(letters: Grid<Float>, v: Int, q: Vec2, origin: Vec2, scale: Float) -> Float The cover at q of v written from origin, its top left.
number(letters: Grid<Float>, v: Int, r: Rect, align: Vec2, scale: Float, color: Vec4, q: Vec2) -> Vec4 v in color aligned in r, with its shadow.
named_number(letters: Grid<Float>, cells: Rows<Int>, name: Int, width: Int, v: Int, r: Rect, scale: Float, name_ink: Vec4, value_ink: Vec4, q: Vec2) -> Vec4 A name and a number on one row: the name at its left in name_ink, the number at its right in value_ink; a stat, a price, a count.
letter_at(letters: Grid<Float>, code: Int, q: Vec2, origin: Vec2, scale: Float) -> Float One letter’s cover at q, its top left at origin.
Name Syntax
Rect struct Rect { lo: Vec2; hi: Vec2; }
WidgetState type WidgetState = enum { Idle, Focused, Pressed, Disabled };
Nav struct Nav { row: Int; by: Int; confirm: Bool; back: Bool; pointed: Int; along: Float; }

The navigation after a frame through rows rows, round when wrap is 1, by hands (controls.read over ui.navigation_keys) and the pointer (controls.pointer). The list lies where its row list says, in the output’s pixels (its left, top, width, and the rows’ height), the rows gap apart, for the pointer: a scene’s layout works it out, the window’s size and scale known. active 0 holds it still, its row kept and nothing asked.

Mode map
Requires field.read, field.write
Inputs previous: Rows<Nav>, list: Rows<Vec4>, hands: Rows<ActionControls>, pointer: Rows<PointerControls>
Params rows: Int = 1, wrap: Int = 1, active: Int = 1, gap: Float = 0.0
Outputs result: Rows<Nav>
Source packages/ui.entpkg/kernels/navigation.ent

The actions a list confirms and goes back by, for controls.read (domain = 2): Enter, Space or a pad’s south; Esc, Backspace or its east.

Mode map
Requires field.write
Inputs —
Params —
Outputs result: Rows<ActionBinding>
Source packages/ui.entpkg/kernels/navigation.ent

The navigation before any frame, row row lit.

Mode map
Requires field.write
Inputs —
Params row: Int = 0
Outputs result: Rows<Nav>
Source packages/ui.entpkg/kernels/navigation.ent

navigation.replay