ui

package
v0.23.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 19, 2026 License: MIT Imports: 18 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package ui composes a scene's screen out of elements: panels, labels, windows, buttons and pictures of the world, laid out in a tree. It knows no cameras: the world seen through a camera is a render.Feed, which ui shows as any other picture.

Scene

A Scene is a game.Scene whose screen is a tree of elements, made by NewScene once the world is there. Scene.Input hands its input to the players' bindings; Scene.Show, Scene.Hide and Scene.Toggle show and hide elements by name (Element.Named). Its drawer is a plugin.Publisher: once a frame, after the ticks, it reads off the game where its pinned elements' entities stand, every Text's words, every control's value and what is hidden, and the frame is laid, drawn and clicked as that says; an element put in since reads them as it is laid. It is laid on the frame's barrier, where nothing ticks or draws (game.Laying), and drawing only paints it.

Layout

An Element is given a box by its parent. Layers lays its elements over the whole box, each covering those before it; Columns and Rows split it, each element taking its Part: a Share of what is left, Fixed pixels, or what it needs (Fit). An anchor (TopLeft, Center, BottomRight and the rest) places its element at its point of the box, at the Element.Size asked for or the Element.Fraction of the box, Element.Margin pixels off the edges.

Elements

Panel is a background and a border round an element; Label a line of text (Heading, Subheading and Title its weights); Image a render.Surface filling its box, whose source may draw on the glass over it (a render.Feed with a render.Glass source), last of all, over whatever lies over the picture; Window a panel with a title over its elements, which Element.Modal makes hold the input while shown; Element.Passing lets the pointer through an element and all in it to what lies under, a button or a control inside aside; Blank a gap; Drawer a screen renderer; Scroll an element taller than its box, scrolled by its bar or the wheel. Any element takes Element.Fill, Element.Border and Element.Padding. LabelOf, ButtonOf and WindowOf (HeadingOf too) read their words off a Text every frame, for the entity a pinned element is shown for; Of is a Text read off a component of that entity, While one saying its words while a function says so. A Text saying nothing leaves its element out.

Controls

A control shows a value read through a function every frame and gives, as it is used, the command a second function builds for the new value, the way a Button gives its commands: a Checkbox on or off, a Slider dragged along its track or stepped by the wheel over it, a Dropdown opening its options over everything, the one clicked chosen. A control reads no entity: pinned, every instance shows the same. The settings screen (players) is made of them. An element given Element.Live is live while its function says so, else drawn dimmed and passed by the pointer, with everything in it: a slider beside a checkbox that is off.

Theme

A Theme is how a scene's elements look where they say nothing of their own, its Accent the controls' marks. Scene.Theme sets it; an element's own Fill or Border wins.

Input

A click goes to the topmost element it hits. A Button gives its commands: the scene's own (Show, Hide, Toggle) or any other through Scene.Issue, else as nobody through the Runtime. A picture with an Input (Element.Input) lets the click through to Scene.Input, unless its Input is Clicked and takes the press itself (a minimap); any other element keeps it; a shown modal element holds every click and the wheel outside it. A slider pressed holds the cursor till the button is let go, wherever that is; a dropdown's open options take every click, one outside them closing them, as Esc does (Scene.Unfolded). A Hovered Input hears whether the cursor lies on its picture uncovered. Scene.Keys are the scene's own keys; Element.Show and Element.Hide show and hide an element from code.

Pinned to entities

An element Element.Under an effect is shown once for every entity the effect is on, pinned to it; Element.On pins it to the entities a name or a group calls, Element.Where to those a Pin holds (Tagged). It stands Element.Above, Element.Below or Element.Beside its entity, moved by Element.Offset, in every picture that has it in sight and shows it (Owner). Out of sight everywhere it does what Element.OffScreen says (PointAtIt, ShowIt, GoToIt), moving the camera through the picture's Looker. A pinned element's button gives a command for It, or an About, for the entity it is shown for.

Shapes

Element.Masked cuts an element to a Mask, Circle or a convex Polygon: its background, its picture and what hits it alike.

Index

Constants

This section is empty.

Variables

View Source
var It ceremony.Target = it{}

It is whom a command is for in an element pinned to an entity: the entity the element is shown for. A ceremony.Command for It is defined in the register as any other.

Functions

This section is empty.

Types

type About

type About interface {
	command.Command
	About(of uid.UID64) command.Command
}

About is a plugin's own command that is for the entity the element giving it is pinned to, as a ceremony.Command for It is.

type Clicked

type Clicked interface {
	Input
	Click(at geom.Vec)
}

Clicked is an Input that takes a press on its picture itself: Click hears where, in the picture's pixels from its top-left corner, and neither the press nor the wheel over the picture goes further.

type Element

type Element struct {
	// contains filtered or unexported fields
}

Element is a part of a scene's screen: given a box by its parent, it places its children in it, draws itself and says whether a point of the screen hits it.

func Blank

func Blank() *Element

Blank is an element showing nothing of its own: a gap, or with a Fill a divider, a plate.

func BottomLeft

func BottomLeft(e *Element) *Element

func BottomMiddle

func BottomMiddle(e *Element) *Element

func BottomRight

func BottomRight(e *Element) *Element

func Button

func Button(label string, cmds ...command.Command) *Element

Button is a label that gives its commands when clicked, in order: the scene's own (Show, Hide, Toggle), or any other the way a key gives it (Scene.Issue).

func ButtonOf

func ButtonOf(t Text, cmds ...command.Command) *Element

ButtonOf is a Button whose label t says, every frame; with no label it is left out.

func Center

func Center(e *Element) *Element

func Checkbox

func Checkbox(label string, get func() bool, set func(on bool) command.Command) *Element

Checkbox is a box with label beside it, ticked while get says so, read every frame; a click gives the command set builds for the other state. It reads no entity: pinned, every instance shows the same.

func Columns

func Columns(parts ...Part) *Element

Columns splits the box into columns, left to right, one a part; none covers another.

func Drawer

func Drawer(r render.Renderer) *Element

Drawer is an element drawn by r, a screen renderer drawing in the screen's pixels: the telemetry line. An r that is a plugin.Publisher is published and swapped with the scene.

func Dropdown(options []string, get func() int, set func(i int) command.Command) *Element

Dropdown is a field showing the option get chooses, read every frame; clicked, it opens the options over everything, and the one clicked gives the command set builds for its index. It reads no entity.

func Heading

func Heading(text string) *Element

Heading is a Label in the theme's bold font: a section's title.

func HeadingOf

func HeadingOf(t Text) *Element

HeadingOf is a Heading whose words t says, every frame, as LabelOf.

func Image

func Image(src render.Surface) *Element

Image shows src filling the element's box, the box's size given to it: a feed of the world, a picture.

func Label

func Label(text string) *Element

Label is a line of text, or lines of it, one under another.

func LabelOf

func LabelOf(t Text) *Element

LabelOf is a Label whose words t says, every frame: a pinned element's for its entity.

func Layers

func Layers(elements ...*Element) *Element

Layers lays every element over the whole box, from the bottom up: each covers those before it.

func MiddleLeft

func MiddleLeft(e *Element) *Element

func MiddleRight

func MiddleRight(e *Element) *Element

func Panel

func Panel(e *Element) *Element

Panel is a background and a border round its element, padded.

func Rows

func Rows(parts ...Part) *Element

Rows splits the box into rows, top to bottom, one a part; none covers another.

func Scroll

func Scroll(e *Element) *Element

Scroll shows e, as wide and as tall as it needs, through the box it is given: what lies past the box's bottom comes into it scrolled, by the bar at the box's right edge dragged or by the wheel over any of it; an e that fits shows whole, the bar not drawn.

func Slider

func Slider(min, max, step float64, get func() float64,
	set func(v float64) command.Command) *Element

Slider is a knob on a track, at the number get says between min and max; dragged, or stepped by the wheel over it, it gives the command set builds for each new number, a step apart. Size sets its length; it reads no entity.

func Subheading

func Subheading(text string) *Element

Subheading is a Label in the theme's Accent colour: a section's part.

func Title

func Title(text string) *Element

Title is a Label in the theme's large font: a screen's title.

func TopLeft

func TopLeft(e *Element) *Element

TopLeft and the anchors below place their element at their point of the box, kept Margin pixels from the edges.

func TopMiddle

func TopMiddle(e *Element) *Element

func TopRight

func TopRight(e *Element) *Element

func Window

func Window(title string, elements ...*Element) *Element

Window is a panel with a title over its elements, one under another, each as large as it needs.

func WindowOf

func WindowOf(title Text, elements ...*Element) *Element

WindowOf is a Window whose title t says, every frame; with no title it is left out, elements and all.

func (*Element) Above

func (e *Element) Above() *Element

Above stands the pinned element above its entity: the default.

func (*Element) Below

func (e *Element) Below() *Element

Below stands the pinned element below its entity.

func (*Element) Beside

func (e *Element) Beside() *Element

Beside stands the pinned element to the right of its entity.

func (*Element) Border

func (e *Element) Border(c color.RGBA, width float32) *Element

Border outlines the element in c, width pixels wide.

func (*Element) Box

func (e *Element) Box() geom.AABB

Box is where the element was last laid, in the screen's pixels.

func (*Element) Fill

func (e *Element) Fill(c color.RGBA) *Element

Fill paints the element's background c.

func (*Element) Fraction

func (e *Element) Fraction(w, h float32) *Element

Fraction asks for w and h of the box its parent gives it, so the element keeps its share as the window changes. An axis asked for as 0 follows the proportions of the picture it shows, else its own size.

func (*Element) Hidden

func (e *Element) Hidden() *Element

Hidden has the element start hidden: not drawn, hit by nothing, until shown.

func (*Element) Hide

func (e *Element) Hide()

Hide has the element neither drawn nor hit, as Hidden has it start.

func (*Element) Hits

func (e *Element) Hits(p geom.Vec) bool

Hits reports whether the screen point p hits the element: a container where one of its children is hit, any other inside its box, and its mask if it has one; a Passing one where a button or a control in it is hit.

func (*Element) Input

func (e *Element) Input(in Input) *Element

Input hands the input over the picture to in: a click on it reaches in, nothing of ui keeps it.

func (*Element) Live added in v0.6.0

func (e *Element) Live(on func() bool) *Element

Live has the element, and everything in it, live while on says so, read every frame: else it is drawn dimmed and the pointer passes it by, a slider beside a checkbox that is off.

func (*Element) Margin

func (e *Element) Margin(px float32) *Element

Margin keeps the element px pixels inside the box its parent gives it, on every side.

func (*Element) Masked

func (e *Element) Masked(m Mask) *Element

Masked cuts the element to m: its background, its picture and what hits it.

func (*Element) Modal

func (e *Element) Modal() *Element

Modal has the element — a window, or an anchor round one — hold the input while it is shown: nothing under it or beside it is clicked.

func (*Element) Named

func (e *Element) Named(name string) *Element

Named calls the element name, for showing and hiding it (Scene.Show, Scene.Hide).

func (*Element) OffScreen

func (e *Element) OffScreen(how OffScreen) *Element

OffScreen says what the pinned element does while its entity is out of sight: PointAtIt unless said.

func (*Element) Offset

func (e *Element) Offset(dx, dy float32) *Element

Offset moves the pinned element dx, dy pixels from where it stands by its entity.

func (*Element) On

func (e *Element) On(whom ceremony.Whom) *Element

On shows the element for every entity whom names, pinned to it as Under does.

func (*Element) Padding

func (e *Element) Padding(px float32) *Element

Padding keeps the element's children px pixels inside its own box, on every side.

func (*Element) Passing added in v0.6.0

func (e *Element) Passing() *Element

Passing lets the pointer through the element and all in it to whatever lies under, as a decoration or a panel of words laid over a picture should (never a Modal). A button or a control inside still takes its press.

func (*Element) Show

func (e *Element) Show()

Show has the element drawn and hit again.

func (*Element) Size

func (e *Element) Size(w, h float32) *Element

Size asks for w by h pixels: what an anchor places, what Fit takes.

func (*Element) Steady

func (e *Element) Steady() *Element

Steady keeps the element from shrinking: it needs the widest and the tallest it has needed so far, so a box round words that change does not flicker.

func (*Element) Under

func (e *Element) Under(ef effect.Effect) *Element

Under shows the element for every entity ef is on, pinned to it. One with no place in the world has it where its parent lays it.

func (*Element) Where

func (e *Element) Where(p Pin) *Element

Where shows the element for every entity p holds, pinned to it as Under does.

type Hide

type Hide struct{ Name string }

Hide hides the scene's elements called Name.

func (Hide) Command

func (Hide) Command()

type Hovered

type Hovered interface {
	Input
	Hover(on bool)
}

Hovered is an Input told before each pass of input whether the cursor lies on its picture, no element over it there.

type Input

type Input interface {
	Over(area geom.AABB, shown render.Surface)
}

Input is whoever takes the input over a picture of the world, told before each pass of input where the picture lies on the screen and what it shows.

type Looker

type Looker interface{ LookAt(entity uid.UID64) }

Looker is an Input that can move its camera onto an entity.

type Mask

type Mask interface {
	// contains filtered or unexported methods
}

Mask is a shape an element is cut to inside its box: drawn and hit only within it.

var Circle Mask = ellipse{}

Circle is the ellipse filling the box: a circle in a square one.

func Polygon

func Polygon(corners ...geom.Vec) Mask

Polygon is the convex polygon of corners given in the box's own terms: (0, 0) its top-left, (1, 1) its bottom-right — a hexagon, a diamond.

type OffScreen

type OffScreen int

OffScreen is what an element pinned to an entity does while the entity is out of every picture of the world on the screen.

const (
	// PointAtIt stands at the edge of the picture on the entity's side, an arrow towards it.
	PointAtIt OffScreen = iota
	// ShowIt stands in the middle of the picture with a button moving the camera onto the entity.
	ShowIt
	// GoToIt moves the camera onto the entity as it appears, and stands by it.
	GoToIt
)

type Owner

type Owner interface{ Shows(entity uid.UID64) bool }

Owner is an Input that says which entities its picture shows elements pinned to. A picture without one shows them all.

type Part

type Part struct {
	// contains filtered or unexported fields
}

Part is an element's part of a split: a share of what is left, fixed pixels, or what it needs.

func Fit

func Fit(e *Element) Part

Fit is what the element needs: its Size, else its content's.

func Fixed

func Fixed(px float32, e *Element) Part

Fixed is px pixels.

func Share

func Share(n float32, e *Element) Part

Share is n parts of what the fixed and fitted leave: two Share(1, …) are halves, Share(2, …) beside Share(1, …) two thirds.

type Pin

type Pin interface {
	// contains filtered or unexported methods
}

Pin is the entities an element is shown for: Tagged.

func Tagged

func Tagged[F any](t tag.Tag[F]) Pin

Tagged is the entities carrying t, a tag of any family.

type Scene

type Scene struct {
	// contains filtered or unexported fields
}

Scene is a game.Scene whose screen is a tree of elements laid over the screen every frame.

func NewScene

func NewScene(name string, screen *Element) *Scene

NewScene is the scene name, its screen the element screen, made once the world is there.

func (*Scene) Drawers

func (s *Scene) Drawers() []render.Renderer

Drawers is the one drawer drawing the screen, which publishes what it reads off the game once a frame (plugin.Publisher).

func (*Scene) Element

func (s *Scene) Element(name string) *Element

Element is the first element called name, laid where the last frame laid it; nil for none.

func (*Scene) Focusable

func (s *Scene) Focusable() bool

func (*Scene) HandleEvents

func (s *Scene) HandleEvents(
	events *control.InputEvents,
	runtime game.Runtime,
	composition game.Composition,
)

HandleEvents routes this tick's input: a click to the topmost element it hits, the scene's keys to their commands, what is left to Input.

func (*Scene) Hide

func (s *Scene) Hide(name string)

Hide hides every element called name.

func (*Scene) Input

func (s *Scene) Input(fn func(*control.InputEvents, game.Runtime, game.Composition)) *Scene

Input hands the scene's input, while it is active, to fn: the players' bindings, as a rule.

func (*Scene) Issue

func (s *Scene) Issue(fn func(cmd command.Command) error) *Scene

Issue is how the scene gives a command that is not its own, a button's or a key's: the players' Issue, as a rule. Without one the scene gives it as nobody through the Runtime.

func (*Scene) Keys

func (s *Scene) Keys(bindings ...control.Binding) *Scene

Keys are the scene's own keys: each gives its command when its key is pressed with the modifiers it asks for — one of the scene's own (Show, Hide, Toggle), or any other through Issue.

func (*Scene) Laid

func (s *Scene) Laid() geom.AABB

Laid is the screen the scene was last laid over: a zero box before the first frame.

func (*Scene) Lay

func (s *Scene) Lay(screen geom.AABB)

Lay lays the scene's elements over screen, as every frame does before drawing.

func (*Scene) Name

func (s *Scene) Name() string

func (*Scene) Persisted

func (s *Scene) Persisted() []any

Persisted is the names of the elements shown: a game saved with a window open loads with it open.

func (*Scene) Replace

func (s *Scene) Replace(screen *Element)

Replace puts screen in place of the scene's tree, for one built afresh each time it is shown (a listing): dressed in the theme at once, drawn from the next frame, published by the barrier at the latest. What Drawers binds once — pictures, screen renderers, pinned elements, texts read off components — must not be in it.

func (*Scene) Restore

func (s *Scene) Restore()

Restore lays the names loaded on the elements, now or once they are made.

func (*Scene) Show

func (s *Scene) Show(name string)

Show shows every element called name.

func (*Scene) Shown

func (s *Scene) Shown(name string) bool

Shown reports whether an element called name is shown.

func (*Scene) Theme

func (s *Scene) Theme(t Theme) *Scene

Theme draws the scene's elements in t where they say nothing of their own.

func (*Scene) Toggle

func (s *Scene) Toggle(name string)

Toggle shows the elements called name where any is hidden, else hides them.

func (*Scene) Unfolded

func (s *Scene) Unfolded() bool

Unfolded reports whether a dropdown's options lie open: Esc closes them before anything else.

type Show

type Show struct{ Name string }

Show shows the scene's elements called Name.

func (Show) Command

func (Show) Command()

type Text

type Text interface {
	Text(of uid.UID64, pinned bool) (string, bool)
}

Text is what an element reads its words off once a frame, as its scene is published, for the entity it is pinned to. False leaves the element out: it takes no room and nothing hits it.

func Of

func Of[T any](fn func(v *T) (string, bool)) Text

Of is a Text read off the component T of the entity an element is pinned to: fn says the words. An entity without T, or an element pinned to none, says nothing.

func While

func While(on func() bool, text string) Text

While is a Text saying text while on says so, and nothing else: an element left out till then.

type Theme

type Theme struct {
	Font   *render.Font
	Bold   *render.Font // a Heading's; nil, the Font
	Large  *render.Font // a Title's; nil, the Bold
	Text   color.RGBA
	Shadow color.RGBA // a pixel under and right of the text; zero for none
	Panel  color.RGBA // a panel's and a window's background
	Border color.RGBA // a panel's, a window's and a button's border
	Title  color.RGBA // a window's title's background
	Button color.RGBA // a button's background
	Accent color.RGBA // a checkbox's tick, a slider's knob and the track behind it
	// contains filtered or unexported fields
}

Theme is how a scene's elements look where they say nothing of their own: the font and the colour of their text, and the colours of panels, windows' titles, buttons and the widgets' marks.

func DefaultTheme

func DefaultTheme() Theme

DefaultTheme is light text in Go Regular over dark panels.

type Toggle

type Toggle struct{ Name string }

Toggle shows the scene's elements called Name where any is hidden, else hides them.

func (Toggle) Command

func (Toggle) Command()

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL