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 ¶
- Variables
- type About
- type Clicked
- type Element
- func Blank() *Element
- func BottomLeft(e *Element) *Element
- func BottomMiddle(e *Element) *Element
- func BottomRight(e *Element) *Element
- func Button(label string, cmds ...command.Command) *Element
- func ButtonOf(t Text, cmds ...command.Command) *Element
- func Center(e *Element) *Element
- func Checkbox(label string, get func() bool, set func(on bool) command.Command) *Element
- func Columns(parts ...Part) *Element
- func Drawer(r render.Renderer) *Element
- func Dropdown(options []string, get func() int, set func(i int) command.Command) *Element
- func Heading(text string) *Element
- func HeadingOf(t Text) *Element
- func Image(src render.Surface) *Element
- func Label(text string) *Element
- func LabelOf(t Text) *Element
- func Layers(elements ...*Element) *Element
- func MiddleLeft(e *Element) *Element
- func MiddleRight(e *Element) *Element
- func Panel(e *Element) *Element
- func Rows(parts ...Part) *Element
- func Scroll(e *Element) *Element
- func Slider(min, max, step float64, get func() float64, ...) *Element
- func Subheading(text string) *Element
- func Title(text string) *Element
- func TopLeft(e *Element) *Element
- func TopMiddle(e *Element) *Element
- func TopRight(e *Element) *Element
- func Window(title string, elements ...*Element) *Element
- func WindowOf(title Text, elements ...*Element) *Element
- func (e *Element) Above() *Element
- func (e *Element) Below() *Element
- func (e *Element) Beside() *Element
- func (e *Element) Border(c color.RGBA, width float32) *Element
- func (e *Element) Box() geom.AABB
- func (e *Element) Fill(c color.RGBA) *Element
- func (e *Element) Fraction(w, h float32) *Element
- func (e *Element) Hidden() *Element
- func (e *Element) Hide()
- func (e *Element) Hits(p geom.Vec) bool
- func (e *Element) Input(in Input) *Element
- func (e *Element) Live(on func() bool) *Element
- func (e *Element) Margin(px float32) *Element
- func (e *Element) Masked(m Mask) *Element
- func (e *Element) Modal() *Element
- func (e *Element) Named(name string) *Element
- func (e *Element) OffScreen(how OffScreen) *Element
- func (e *Element) Offset(dx, dy float32) *Element
- func (e *Element) On(whom ceremony.Whom) *Element
- func (e *Element) Padding(px float32) *Element
- func (e *Element) Passing() *Element
- func (e *Element) Show()
- func (e *Element) Size(w, h float32) *Element
- func (e *Element) Steady() *Element
- func (e *Element) Under(ef effect.Effect) *Element
- func (e *Element) Where(p Pin) *Element
- type Hide
- type Hovered
- type Input
- type Looker
- type Mask
- type OffScreen
- type Owner
- type Part
- type Pin
- type Scene
- func (s *Scene) Drawers() []render.Renderer
- func (s *Scene) Element(name string) *Element
- func (s *Scene) Focusable() bool
- func (s *Scene) HandleEvents(events *control.InputEvents, runtime game.Runtime, ...)
- func (s *Scene) Hide(name string)
- func (s *Scene) Input(fn func(*control.InputEvents, game.Runtime, game.Composition)) *Scene
- func (s *Scene) Issue(fn func(cmd command.Command) error) *Scene
- func (s *Scene) Keys(bindings ...control.Binding) *Scene
- func (s *Scene) Laid() geom.AABB
- func (s *Scene) Lay(screen geom.AABB)
- func (s *Scene) Name() string
- func (s *Scene) Persisted() []any
- func (s *Scene) Replace(screen *Element)
- func (s *Scene) Restore()
- func (s *Scene) Show(name string)
- func (s *Scene) Shown(name string) bool
- func (s *Scene) Theme(t Theme) *Scene
- func (s *Scene) Toggle(name string)
- func (s *Scene) Unfolded() bool
- type Show
- type Text
- type Theme
- type Toggle
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
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 BottomMiddle ¶
func BottomRight ¶
func Button ¶
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 Checkbox ¶
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 Drawer ¶
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 ¶
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 Image ¶
Image shows src filling the element's box, the box's size given to it: a feed of the world, a picture.
func LabelOf ¶
LabelOf is a Label whose words t says, every frame: a pinned element's for its entity.
func Layers ¶
Layers lays every element over the whole box, from the bottom up: each covers those before it.
func MiddleLeft ¶
func MiddleRight ¶
func Scroll ¶
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 ¶
Subheading is a Label in the theme's Accent colour: a section's part.
func TopLeft ¶
TopLeft and the anchors below place their element at their point of the box, kept Margin pixels from the edges.
func Window ¶
Window is a panel with a title over its elements, one under another, each as large as it needs.
func WindowOf ¶
WindowOf is a Window whose title t says, every frame; with no title it is left out, elements and all.
func (*Element) Fraction ¶
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 ¶
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 ¶
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 ¶
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
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 ¶
Margin keeps the element px pixels inside the box its parent gives it, on every side.
func (*Element) Masked ¶
Masked cuts the element to m: its background, its picture and what hits it.
func (*Element) Modal ¶
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 ¶
Named calls the element name, for showing and hiding it (Scene.Show, Scene.Hide).
func (*Element) OffScreen ¶
OffScreen says what the pinned element does while its entity is out of sight: PointAtIt unless said.
func (*Element) Offset ¶
Offset moves the pinned element dx, dy pixels from where it stands by its entity.
func (*Element) Padding ¶
Padding keeps the element's children px pixels inside its own box, on every side.
func (*Element) Passing ¶ added in v0.6.0
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) Steady ¶
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.
type Hovered ¶
Hovered is an Input told before each pass of input whether the cursor lies on its picture, no element over it there.
type Input ¶
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 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.
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 ¶
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.
type Pin ¶
type Pin interface {
// contains filtered or unexported methods
}
Pin is the entities an element is shown for: Tagged.
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 ¶
NewScene is the scene name, its screen the element screen, made once the world is there.
func (*Scene) Drawers ¶
Drawers is the one drawer drawing the screen, which publishes what it reads off the game once a frame (plugin.Publisher).
func (*Scene) Element ¶
Element is the first element called name, laid where the last frame laid it; nil for none.
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) 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 ¶
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 ¶
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 ¶
Laid is the screen the scene was last laid over: a zero box before the first frame.
func (*Scene) Persisted ¶
Persisted is the names of the elements shown: a game saved with a window open loads with it open.
func (*Scene) Replace ¶
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.
type Text ¶
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.
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.