Documentation
¶
Overview ¶
Package antui builds desktop apps the simple way, with no dependency to download and nothing to link against beyond what the system already has.
Windows → Win32 (user32 + gdi32), through syscall macOS → Cocoa through the Objective-C runtime Linux/BSD → the X11 protocol spoken straight over the socket
Everything is drawn in software into a Canvas, which is a plain slice of pixels — so drawing works with no window at all, and can be tested in a terminal.
Index ¶
- Constants
- Variables
- func LabelHeight(pad int) int
- func LabelWidth(text string, pad int) int
- func LabelsWidth(labels []string, pad, gap int) int
- func Now() float64
- func SetSystemFace(points, scale float64) bool
- func Sleep(seconds float64)
- func SystemFace(pixels float64) (*canvas.Face, error)
- func SystemFont() (path string, data []byte, err error)
- func UIFace(points, scale float64) (*canvas.Face, error)
- func WindowsMachines() []string
- func WrapLabels(labels []string, pad, gap, most int) []int
- func WriteICO(w io.Writer, images ...*canvas.Canvas) error
- func WriteWindowsResource(w io.Writer, images ...*canvas.Canvas) error
- func WriteWindowsResourceFor(w io.Writer, arch string, images ...*canvas.Canvas) error
- type Audio
- type Event
- type EventType
- type Gestures
- type Key
- type Limits
- type Mod
- type MouseButton
- type Options
- type Theme
- type Tool
- type Touch
- type Window
- func (win *Window) Background()
- func (win *Window) Begin() bool
- func (win *Window) Blit(x, y int, src *canvas.Canvas)
- func (win *Window) BlitScaled(x, y, width, height int, src *canvas.Canvas)
- func (win *Window) Bounds() Limits
- func (win *Window) Button(x, y, w, h int, label string) bool
- func (win *Window) Canvas() *canvas.Canvas
- func (win *Window) Checkbox(x, y int, label string, value *bool) bool
- func (win *Window) Circle(cx, cy, radius int, c canvas.Color)
- func (win *Window) Clear(c canvas.Color)
- func (win *Window) Clicked(x, y, w, h int) bool
- func (win *Window) ClickedID(name string, x, y, w, h int) bool
- func (win *Window) ClipboardFiles() []string
- func (win *Window) ClipboardText() string
- func (win *Window) Close()
- func (win *Window) ContentScale() float64
- func (win *Window) Delta() float64
- func (win *Window) DisplayRefresh() int
- func (win *Window) DisplaySize() (width, height int, ok bool)
- func (win *Window) DroppedFiles() []string
- func (win *Window) End()
- func (win *Window) Events(yield func(Event) bool)
- func (win *Window) FillCircle(cx, cy, radius int, c canvas.Color)
- func (win *Window) FillRect(x, y, w, h int, c canvas.Color)
- func (win *Window) FillRoundRect(x, y, w, h, r int, c canvas.Color)
- func (win *Window) FillTriangle(x0, y0, x1, y1, x2, y2 int, c canvas.Color)
- func (win *Window) Fullscreen() bool
- func (win *Window) Gestures() Gestures
- func (win *Window) Height() int
- func (win *Window) Hovered(x, y, w, h int) bool
- func (win *Window) Input(x, y, w, h int, text *string) bool
- func (win *Window) KeyDown(k Key) bool
- func (win *Window) KeyPressed(k Key) bool
- func (win *Window) KeyReleased(k Key) bool
- func (win *Window) Keys() iter.Seq[Key]
- func (win *Window) Label(x, y int, text string)
- func (win *Window) Limits() Limits
- func (win *Window) Line(x0, y0, x1, y1 int, c canvas.Color)
- func (win *Window) Mods() Mod
- func (win *Window) MouseDown(b MouseButton) bool
- func (win *Window) MousePressed(b MouseButton) bool
- func (win *Window) MouseReleased(b MouseButton) bool
- func (win *Window) MouseX() int
- func (win *Window) MouseY() int
- func (win *Window) NextEvent() (Event, bool)
- func (win *Window) Opacity() uint8
- func (win *Window) Pixel(x, y int, c canvas.Color)
- func (win *Window) Progress(x, y, w, h int, progress float32)
- func (win *Window) Push(ev Event)
- func (win *Window) PushSimple(t EventType)
- func (win *Window) Quit()
- func (win *Window) Radio(x, y int, label string, value *int, option int) bool
- func (win *Window) Rect(x, y, w, h int, c canvas.Color)
- func (win *Window) ResetClip()
- func (win *Window) Resizable() bool
- func (win *Window) ResizeCanvas(width, height int) bool
- func (win *Window) RoundRect(x, y, w, h, r int, c canvas.Color)
- func (win *Window) Running() bool
- func (win *Window) SafeArea() canvas.Area
- func (win *Window) SetClip(x, y, w, h int)
- func (win *Window) SetClipboardText(text string) bool
- func (win *Window) SetFPS(fps int)
- func (win *Window) SetFixedSize(width, height int)
- func (win *Window) SetFullscreen(on bool) bool
- func (win *Window) SetIcon(images ...*canvas.Canvas) bool
- func (win *Window) SetLimits(limits Limits)
- func (win *Window) SetMouse(x, y int)
- func (win *Window) SetOpacity(alpha uint8) bool
- func (win *Window) SetSafeArea(a canvas.Area)
- func (win *Window) SetShouldClose()
- func (win *Window) SetSize(width, height int) bool
- func (win *Window) SetTheme(theme Theme)
- func (win *Window) SetTitle(title string)
- func (win *Window) SetTouchFirst()
- func (win *Window) SizeInPoints() (width, height int)
- func (win *Window) Slider(x, y, w, h int, value *float32, minValue, maxValue float32) bool
- func (win *Window) Text(x, y int, text string, c canvas.Color) int
- func (win *Window) TextInput() string
- func (win *Window) TextScaled(x, y int, text string, c canvas.Color, scale int) int
- func (win *Window) Theme() *Theme
- func (win *Window) TouchByID(id int) (Touch, bool)
- func (win *Window) TouchCount() int
- func (win *Window) TouchScreen() bool
- func (win *Window) Touches() []Touch
- func (win *Window) Triangle(x0, y0, x1, y1, x2, y2 int, c canvas.Color)
- func (win *Window) Wheel() int
- func (win *Window) WidgetActive() uint32
- func (win *Window) WidgetCaret() bool
- func (win *Window) WidgetClick(id uint32, hovered bool) bool
- func (win *Window) WidgetCursor() int
- func (win *Window) WidgetCursorSet(c int)
- func (win *Window) WidgetEdit(text *string) bool
- func (win *Window) WidgetEndPress(id uint32)
- func (win *Window) WidgetFocus() uint32
- func (win *Window) WidgetFocusClear(id uint32)
- func (win *Window) WidgetFocusSet(id uint32)
- func (win *Window) WidgetHot(id uint32)
- func (win *Window) WidgetID(kind string, x, y, w, h int, label string) uint32
- func (win *Window) WidgetKeyActivate(id uint32) bool
- func (win *Window) WidgetStartPress(id uint32)
- func (win *Window) WidgetTabStop(id uint32)
- func (win *Window) Width() int
Constants ¶
const ( EventNone = backend.EventNone EventClose = backend.EventClose EventResize = backend.EventResize EventKeyDown = backend.EventKeyDown EventKeyUp = backend.EventKeyUp EventText = backend.EventText EventMouseDown = backend.EventMouseDown EventMouseUp = backend.EventMouseUp EventMouseMove = backend.EventMouseMove EventMouseWheel = backend.EventMouseWheel EventFocus = backend.EventFocus EventExpose = backend.EventExpose EventDropFiles = backend.EventDropFiles EventTouchDown = backend.EventTouchDown EventTouchMove = backend.EventTouchMove EventTouchUp = backend.EventTouchUp EventTouchCancel = backend.EventTouchCancel )
The event kinds. The comment on each names the fields it fills in.
const ( // TapSlop is how far a finger may wander and still be a tap rather than // a drag. TapSlop = 8.0 // LongPressTime is how long a finger must stay put to be a long press. LongPressTime = 0.5 // DoubleTapTime and DoubleTapSlop bound the gap between two taps for // them to count as one double tap. DoubleTapTime = 0.3 DoubleTapSlop = 32.0 // FlingSpeed is the slowest lift that still counts as a throw, in points // a second. FlingSpeed = 50.0 )
The thresholds a gesture is recognised against, in points rather than pixels so that they mean the same thing on a dense screen as on a coarse one. They are the platform's own numbers: a gesture that behaves differently from every other app on the device is a gesture the user gets wrong, however well it is implemented.
const ( KeyUnknown = backend.KeyUnknown KeySpace = backend.KeySpace KeyApostrophe = backend.KeyApostrophe KeyComma = backend.KeyComma KeyMinus = backend.KeyMinus KeyPeriod = backend.KeyPeriod KeySlash = backend.KeySlash Key0 = backend.Key0 Key1 = backend.Key1 Key2 = backend.Key2 Key3 = backend.Key3 Key4 = backend.Key4 Key5 = backend.Key5 Key6 = backend.Key6 Key7 = backend.Key7 Key8 = backend.Key8 Key9 = backend.Key9 KeySemicolon = backend.KeySemicolon KeyEqual = backend.KeyEqual KeyA = backend.KeyA KeyB = backend.KeyB KeyC = backend.KeyC KeyD = backend.KeyD KeyE = backend.KeyE KeyF = backend.KeyF KeyG = backend.KeyG KeyH = backend.KeyH KeyI = backend.KeyI KeyJ = backend.KeyJ KeyK = backend.KeyK KeyL = backend.KeyL KeyM = backend.KeyM KeyN = backend.KeyN KeyO = backend.KeyO KeyP = backend.KeyP KeyQ = backend.KeyQ KeyR = backend.KeyR KeyS = backend.KeyS KeyT = backend.KeyT KeyU = backend.KeyU KeyV = backend.KeyV KeyW = backend.KeyW KeyX = backend.KeyX KeyY = backend.KeyY KeyZ = backend.KeyZ KeyLeftBracket = backend.KeyLeftBracket KeyBackslash = backend.KeyBackslash KeyRightBracket = backend.KeyRightBracket KeyGrave = backend.KeyGrave )
Printable keys.
const ( KeyEscape = backend.KeyEscape KeyEnter = backend.KeyEnter KeyTab = backend.KeyTab KeyBackspace = backend.KeyBackspace KeyInsert = backend.KeyInsert KeyDelete = backend.KeyDelete KeyRight = backend.KeyRight KeyLeft = backend.KeyLeft KeyDown = backend.KeyDown KeyUp = backend.KeyUp KeyPageUp = backend.KeyPageUp KeyPageDown = backend.KeyPageDown KeyHome = backend.KeyHome KeyEnd = backend.KeyEnd KeyCapsLock = backend.KeyCapsLock KeyF1 = backend.KeyF1 KeyF2 = backend.KeyF2 KeyF3 = backend.KeyF3 KeyF4 = backend.KeyF4 KeyF5 = backend.KeyF5 KeyF6 = backend.KeyF6 KeyF7 = backend.KeyF7 KeyF8 = backend.KeyF8 KeyF9 = backend.KeyF9 KeyF10 = backend.KeyF10 KeyF11 = backend.KeyF11 KeyF12 = backend.KeyF12 KeyLeftShift = backend.KeyLeftShift KeyLeftControl = backend.KeyLeftControl KeyLeftAlt = backend.KeyLeftAlt KeyLeftSuper = backend.KeyLeftSuper KeyRightShift = backend.KeyRightShift KeyRightControl = backend.KeyRightControl KeyRightAlt = backend.KeyRightAlt KeyRightSuper = backend.KeyRightSuper KeyBack = backend.KeyBack KeyMenu = backend.KeyMenu KeySearch = backend.KeySearch KeyVolumeUp = backend.KeyVolumeUp KeyVolumeDown = backend.KeyVolumeDown KeyPadA = backend.KeyPadA KeyPadB = backend.KeyPadB KeyPadX = backend.KeyPadX KeyPadY = backend.KeyPadY KeyPadL1 = backend.KeyPadL1 KeyPadR1 = backend.KeyPadR1 KeyPadL2 = backend.KeyPadL2 KeyPadR2 = backend.KeyPadR2 KeyPadStart = backend.KeyPadStart KeyPadSelect = backend.KeyPadSelect KeyPadThumbL = backend.KeyPadThumbL KeyPadThumbR = backend.KeyPadThumbR KeyPadMode = backend.KeyPadMode )
Special keys.
const ( ModShift = backend.ModShift ModControl = backend.ModControl ModAlt = backend.ModAlt ModSuper = backend.ModSuper )
The modifiers, combined with |.
const ( MouseLeft = backend.MouseLeft MouseRight = backend.MouseRight MouseMiddle = backend.MouseMiddle )
The mouse buttons.
const ( ToolUnknown = backend.ToolUnknown ToolFinger = backend.ToolFinger ToolStylus = backend.ToolStylus ToolMouse = backend.ToolMouse ToolEraser = backend.ToolEraser // the far end of a stylus, used to rub out )
The tools. A device that does not say reports ToolUnknown rather than guessing at a finger.
Variables ¶
var ErrNoAudio = errors.New("antui: no audio device")
ErrNoAudio is what opening gives back where there is no sound at all: a machine with no card, a session with no server, a platform nothing is written for yet. It is worth telling apart from a broken device, because a game carries on perfectly well in silence and should not stop for it.
var ErrNoSystemFont = errors.New("antui: no system font found")
ErrNoSystemFont is what SystemFace gives back when the system has no answer and nothing on the fallback list is there.
It is worth telling apart from a broken font file, because the response is the same either way — carry on with the built-in — and a program should not stop for it.
Functions ¶
func LabelHeight ¶
LabelHeight is how tall one is with pad above and below.
func LabelWidth ¶
LabelWidth is how wide a piece of text is with pad either side of it.
func LabelsWidth ¶
LabelsWidth is how wide a row of labels is: each with pad either side, and gap between one and the next.
func Now ¶
func Now() float64
Now is the seconds since the library was first asked the time, on a monotonic clock that no change to the system clock can move.
func SetSystemFace ¶
SetSystemFace makes the program draw in the platform's own font, and says whether it managed.
It is the whole of what most programs want:
antui.SetSystemFace(0, win.ContentScale())
and it is deliberately not done automatically. The built-in font is exact and identical on every machine, which is what a test card, a screenshot comparison and a game with a fixed layout all depend on; changing that underneath every program that already exists would break them for a nicety.
func SystemFace ¶
SystemFace is the platform's own interface font at a size in pixels.
face, err := antui.SystemFace(15)
if err == nil {
canvas.SetDefaultFace(face)
}
A program that wants to look like the machine it is on asks for this and carries on with the built-in when it is not there, which is what the two lines above do. Refusing to start because a font is missing would be a strange thing for a window library to do.
func SystemFont ¶
SystemFont is the file this platform writes its interface in, and the bytes of it.
The path is there so a program can say which font it chose — a settings screen showing "Noto Sans" is a great deal more use than one showing nothing — and so that a bug report can name it.
func UIFace ¶
UIFace is SystemFace at the size the platform draws its own interface at, scaled for the display.
Points, not pixels: the size an interface is specified in is a physical one, and the number of pixels it comes to depends on the screen. A program with a window passes win.ContentScale(); zero points means the platform's own default, which differs by platform and is why it is not a constant here.
func WindowsMachines ¶
func WindowsMachines() []string
WindowsMachines is the architectures a resource can be written for: the three Go builds Windows programs for.
func WrapLabels ¶
WrapLabels breaks a row of labels into rows none of which is wider than most, keeping the order they were given in. It gives back how many labels are on each row.
A label too wide for a row of its own still gets one: making it share would only push something else out of the box as well, and a row that is too wide is a thing the caller can see and shorten. There is always at least one row when there is at least one label, so a caller can lay them out without checking for nothing.
func WriteICO ¶
WriteICO writes the pictures as a Windows .ico file, largest first.
It is worth having on its own — an .ico is what a file browser or an installer wants — and it is half of what the resource below is made of.
func WriteWindowsResource ¶
WriteWindowsResource writes a .syso: an object file the Go linker puts into the program, holding the icon the file browser shows.
Put what it writes in the main package as `icon_windows.syso` — the name ends in `_windows` so that the toolchain leaves it out of every other platform's build, which is what makes a checked-in resource harmless everywhere else.
Types ¶
type Audio ¶
type Audio struct {
// contains filtered or unexported fields
}
An Audio is one stream of sound going out to the speakers.
func OpenAudio ¶
OpenAudio starts sending sound, and calls fill whenever the device wants more of it.
fill is given interleaved stereo — left, right, left, right — at the rate asked for, and must overwrite all of it: what is in the slice is the last block, not silence. It is called from the device's own goroutine, so whatever it touches has to be safe to touch from there.
The rate is what the game wants and not necessarily what it gets. Ask the device with Rate before making anything that depends on it.
func (*Audio) Err ¶
Err is what went wrong after the device was opened — a card unplugged, a server that went away — or nil.
A device that dies does not take the game with it. Everything goes on being mixed and nothing is heard, which is what happens on a machine with the speakers turned off anyway.
type Event ¶
Event is one thing the window system reported. Reading events is optional: Begin has already folded them into the input state that Window.KeyDown and friends report, and most programs only need that.
type EventType ¶
EventType says which kind of thing happened. The fields of Event that carry meaning depend on it; the rest are zero.
type Gestures ¶
type Gestures struct {
// X and Y are where the gesture is: the finger, or the point between two
// of them for a pinch.
X, Y int
// Tap is a finger that landed and lifted without wandering. Count is 1
// for a single tap, 2 for a double, and keeps going for as long as the
// taps keep coming quickly enough — so a triple tap is Count 3, not
// three separate taps.
Tap bool
Count int
// LongPress fires once, while the finger is still down, as soon as it
// has been still for long enough. It does not wait for the lift, because
// by then the user has been waiting for half a second with no answer.
LongPress bool
// Drag is a finger that has moved past the slop. DX and DY are this
// frame's movement.
Drag bool
DX, DY int
// Fling is a drag that was let go while still moving. VX and VY are how
// fast, in pixels a second.
Fling bool
VX, VY float64
// Pinch and Rotate need two fingers. Scale is the change this frame —
// above 1 for fingers moving apart — and Angle is the change in radians,
// positive clockwise.
Pinch bool
Scale float64
Rotate bool
Angle float64
}
Gestures is what the fingers did this frame. Every field is about this frame alone: a Tap is true on the frame the finger lifted and false on the next one, the same way MousePressed is.
It is touch only. A mouse has no gestures — it has buttons and a wheel, which are reported as themselves — so on a desktop this is always empty.
type Key ¶
Key identifies a physical key, independent of the text it produces. Printable keys carry their own uppercase ASCII code, so KeyA is 'A' and Key1 is '1'; everything else is numbered from 256 up.
type Limits ¶
Limits are what a window may be resized to. The zero value is a window with no bounds at all, which is what a window is without them — so Limits{MinWidth: 640, MinHeight: 480} says only what it looks like it says and leaves everything else alone.
type Options ¶
Options is everything a window can be opened with. The zero value plus a size is exactly what Open gives: a resizable window with no bounds.
type Theme ¶
type Theme struct {
Background canvas.Color
Surface canvas.Color
SurfaceHover canvas.Color
SurfaceActive canvas.Color
Border canvas.Color
Accent canvas.Color
AccentHover canvas.Color
Text canvas.Color
TextMuted canvas.Color
TextOnAccent canvas.Color
Radius int // radius of the rounded corners
Padding int // inner spacing
}
Theme is the set of colours and metrics the ready-made widgets draw with. Every field is public and may be changed at will — Window.Theme returns a pointer to the live one.
func DarkTheme ¶
func DarkTheme() Theme
DarkTheme is the same set of roles in reverse: light text on a dark background, with the accent lifted so it still reads against it.
func LightTheme ¶
func LightTheme() Theme
LightTheme is the default: dark text on a light background.
type Touch ¶
type Touch struct {
// ID stays with this finger for as long as it is down, and may be reused
// by a later one. It is not an index: a finger's position in
// [Window.Touches] changes as others come and go.
ID int
// X and Y are where it is now, in canvas pixels.
X, Y int
// DX and DY are how far it moved this frame.
DX, DY int
// StartX and StartY are where it landed, which is what a swipe is
// measured from.
StartX, StartY int
// Pressure is 0 to 1 on hardware that measures it. On hardware that does
// not it is 1 the whole time the finger is down, so it cannot be used to
// find out whether the device reports pressure at all.
Pressure float32
// Size is how much of the screen the touch covers, 0 to 1. It is how a
// thumb is told from a fingertip.
Size float32
// Tool is what is doing the touching.
Tool Tool
// Began is set for the one frame the finger landed on, and Ended for the
// one frame it lifted on. A touch is still in [Window.Touches] on the
// frame it ended, so nothing has to be caught between frames.
Began bool
Ended bool
// Cancelled says the system took the touch away rather than the user
// lifting it — a notification pulled down over the app, a gesture the
// system claimed. A tap must not be counted from a cancelled touch.
Cancelled bool
}
Touch is one finger on the screen, from the moment it lands to the moment it lifts.
It is not a mouse and is not reported as one. A mouse has one position and a set of buttons; fingers arrive several at a time, each with its own history, and a program that wants to pinch or to let two people play on one screen needs to tell them apart. For everything simpler, the first finger down is also reported as the left mouse button, so a program written for a desktop works on a phone without knowing.
type Window ¶
type Window struct {
// contains filtered or unexported fields
}
Window is an open window and everything drawn into it. It is not safe for concurrent use: like every immediate-mode UI, one goroutine owns the frame loop and everything else talks to it through channels.
func Offscreen ¶ added in v0.0.2
Offscreen makes a Window that draws into a canvas and shows nothing: no window is opened, nothing is presented, and events never come from a display. It is for tests, and for rendering a UI onto a texture to be pasted somewhere else. `win.Canvas()` is where everything lands.
Its input still works — Window.Push folds events into the same input state a real window keeps — so a widget can be clicked and typed at from a test exactly as from a screen. Window.End does nothing without a display, and the frame is free to be looked at after Window.Begin.
func OpenWith ¶
OpenWith creates and shows a window with everything Options says. Open is this with the defaults, and is what most games want.
func (*Window) Background ¶
func (win *Window) Background()
Background paints the window in the theme's background colour.
func (*Window) Begin ¶
Begin starts a frame: it processes system events and refreshes the input state. It returns false once the window has been closed.
for win.Begin() {
win.Clear(canvas.White)
win.End()
}
func (*Window) BlitScaled ¶
BlitScaled draws another canvas fitted into a rectangle.
func (*Window) Bounds ¶
bounds resolves the limits against the size the window is now: a fixed window's smallest and largest size are both the size it has. Keeping Fixed as a flag rather than writing the numbers in is what lets a window locked at no particular size follow a display change instead of being frozen at whatever it happened to be when the game asked.
func (*Window) Checkbox ¶
Checkbox draws a labelled checkbox, flips value when clicked, and reports whether it changed this frame.
func (*Window) Clicked ¶
Clicked reports whether a rectangle was clicked or tapped this frame, drawing nothing at all.
func (*Window) ClickedID ¶
ClickedID is Window.Clicked for a control that moves: the name decides what "the same control" means, rather than where it happens to be.
func (*Window) ClipboardFiles ¶
ClipboardFiles is the files the clipboard names. Empty when it holds none.
func (*Window) ClipboardText ¶
ClipboardText is what the system clipboard holds as text, or "" when it holds nothing this window can read.
func (*Window) Close ¶
func (win *Window) Close()
Close destroys the window and gives back everything it held.
func (*Window) ContentScale ¶
ContentScale is how many pixels the window draws for each point the system lays it out in: 1 on an ordinary display, 2 on a Mac retina or a Windows laptop at 200 per cent, 1.5 at 150.
It is what makes "fixed size" mean the same thing on every machine. A system that does not say answers 1 rather than 0, so arithmetic on it is always safe.
func (*Window) DisplayRefresh ¶
DisplayRefresh is how many times a second the display refreshes, or 0 when it could not be told.
func (*Window) DisplaySize ¶
DisplaySize is the display's size in pixels, and whether it could be told.
func (*Window) DroppedFiles ¶
DroppedFiles is what was dragged onto the window this frame.
func (*Window) End ¶
func (win *Window) End()
End finishes the frame: it sends the pixels to the screen and applies the frame-rate cap.
func (*Window) FillCircle ¶
FillCircle fills a disc.
func (*Window) FillRoundRect ¶
FillRoundRect fills a rounded rectangle.
func (*Window) FillTriangle ¶
FillTriangle fills a triangle.
func (*Window) Fullscreen ¶
Fullscreen reports what was last asked for, not what a window manager did about it.
func (*Window) Input ¶
Input draws a single-line text field and reports whether the text changed this frame.
func (*Window) KeyPressed ¶
KeyPressed reports whether a key went down during this frame.
func (*Window) KeyReleased ¶
KeyReleased reports whether a key came up during this frame.
func (*Window) MouseDown ¶
func (win *Window) MouseDown(b MouseButton) bool
MouseDown reports whether a button is held.
func (*Window) MousePressed ¶
func (win *Window) MousePressed(b MouseButton) bool
MousePressed reports whether a button went down during this frame.
func (*Window) MouseReleased ¶
func (win *Window) MouseReleased(b MouseButton) bool
MouseReleased reports whether a button came up during this frame.
func (*Window) NextEvent ¶
NextEvent pops the next event off this frame's queue, reporting false when it is empty.
func (*Window) Opacity ¶ added in v0.0.2
Opacity is what was last asked for with SetOpacity, 255 by default.
func (*Window) PushSimple ¶
pushSimple queues an event that carries nothing but its kind.
func (*Window) Quit ¶
func (win *Window) Quit()
Quit marks the window for closing, so the next Begin returns false.
func (*Window) Radio ¶
Radio draws one option of a group. Clicking it sets value to option and reports true; clicking the already-selected option changes nothing.
func (*Window) ResetClip ¶
func (win *Window) ResetClip()
ResetClip opens drawing back up to the whole window.
func (*Window) Resizable ¶
Resizable reports whether the window may be resized. It says what was asked for, not what the window manager will do about it.
func (*Window) ResizeCanvas ¶
resizeCanvas grows or shrinks the drawable surface. Backends call it when the window system reports a new size.
func (*Window) SafeArea ¶
SafeArea is the part of the canvas that nothing else is drawn over.
On a desktop it is the whole canvas and always has been. On a phone it is not: an app gets a surface the size of the screen and the system paints its status bar, its navigation bar and the notch around the camera **over** it — so the app owns every pixel and a strip at each end of them is behind something. Anything the user has to be able to read or press belongs inside this rectangle; a background belongs outside it, filling the screen.
It is in canvas pixels, and it moves: a rotation changes it, and so does the on-screen keyboard coming up.
func (*Window) SetClipboardText ¶
SetClipboardText puts text on the system clipboard — what a Copy button does — and reports whether the system took it.
func (*Window) SetFixedSize ¶
SetFixedSize locks the window to one size: both the smallest and the largest it may be, with the maximise button gone.
func (*Window) SetFullscreen ¶
SetFullscreen asks the system to put the window full screen, or to take it back out. It reports whether the request could be made, not whether it was granted.
func (*Window) SetIcon ¶
SetIcon gives the window an icon, at whatever sizes are handed to it.
It reports whether the window system took it. Pass a square picture of any size and the window system scales it, or pass several sizes and let it pick — canvas.IconSet makes a whole set from one picture.
func (*Window) SetLimits ¶
SetLimits changes what the window may be resized to, and takes effect at once: a window already outside the new bounds is asked to come back inside them.
func (*Window) SetMouse ¶
SetMouse is where a backend with no cursor position of its own records the pointer.
func (*Window) SetOpacity ¶ added in v0.0.2
SetOpacity fades the whole window — decorations and all — so that what sits behind the program shows through; 255 is fully opaque and 0 is invisible. It reports whether the request could be made: there is no window to fade on an offscreen canvas, so that reports false while still remembering the value. The window itself is never returned to — this is a whole-window opacity, not a fade of the pixels drawn into it, so what is drawn keeps its contrast and only its overall brightness changes.
func (*Window) SetSafeArea ¶
setSafeArea is how a backend reports it. A zero rectangle means "the whole canvas", which is what every backend that does not know says by saying nothing.
func (*Window) SetShouldClose ¶
func (win *Window) SetShouldClose()
SetShouldClose asks the window to begin closing.
func (*Window) SetSize ¶
SetSize asks for a new drawable size, reduced to the limits and to what the display can show. It reports whether the request could be made at all, not whether the window manager honoured it.
The canvas is not resized here. It is resized when the size actually arrives, which is what keeps everything drawn following the framebuffer rather than following a request that may have been ignored.
func (*Window) SetTouchFirst ¶
func (win *Window) SetTouchFirst()
setTouchFirst is how a backend says there is no other kind of input on this platform, so that the first frame already knows rather than waiting for a finger.
func (*Window) SizeInPoints ¶
SizeInPoints is the size the window appears to be, as against the pixels it draws — the two are the same number until the display is scaled.
func (*Window) Slider ¶
Slider draws a horizontal slider and reports whether the value changed this frame.
func (*Window) TextInput ¶
TextInput is the text typed this frame, in UTF-8, empty when nothing was.
func (*Window) TextScaled ¶
TextScaled draws a string with the font blown up, returning the width of the widest line drawn.
func (*Window) TouchCount ¶
TouchCount is how many fingers are on the screen.
func (*Window) TouchScreen ¶
TouchScreen reports whether this window is being driven by a touchscreen, which is what decides whether a game has to put controls on the screen.
It is not a question about the hardware, it is a question about the player: a laptop with a touchscreen nobody uses should be given a keyboard game, and a tablet with a keyboard attached still has a screen to press. So the answer is "a finger has touched this window", which is false until one does — and on a platform where there is nothing else, true from the start.
A game that wants to decide for itself should ignore this and set its own flag; this is the default, not the rule.
func (*Window) Touches ¶
Touches is every finger on the screen this frame, in the order they landed. The slice is the window's own and is rewritten every frame, so anything kept has to be copied.
func (*Window) WidgetActive ¶ added in v0.0.2
WidgetActive is the widget that is in the middle of being pressed, or 0.
func (*Window) WidgetCaret ¶ added in v0.0.2
WidgetCaret reports whether the text cursor is lit right now. It blinks on the same clock the built-in text field blinks on.
func (*Window) WidgetClick ¶ added in v0.0.2
WidgetClick drives the press-and-release logic every clickable widget shares and reports whether it was clicked this frame. See Window.Clicked.
func (*Window) WidgetCursor ¶ added in v0.0.2
WidgetCursor is where the cursor sits in the focused text field.
func (*Window) WidgetCursorSet ¶ added in v0.0.2
WidgetCursorSet moves the cursor in the focused text field.
func (*Window) WidgetEdit ¶ added in v0.0.2
WidgetEdit applies this frame's keys and typing to the focused field, exactly as the built-in Input does.
func (*Window) WidgetEndPress ¶ added in v0.0.2
WidgetEndPress ends the press on the widget, whatever it was.
func (*Window) WidgetFocus ¶ added in v0.0.2
WidgetFocus is the widget the keyboard is going to, or 0.
func (*Window) WidgetFocusClear ¶ added in v0.0.2
WidgetFocusClear takes the keyboard away again.
func (*Window) WidgetFocusSet ¶ added in v0.0.2
WidgetFocusSet hands the keyboard to the widget.
func (*Window) WidgetHot ¶ added in v0.0.2
WidgetHot marks the widget as the one under the pointer, which is how a widget that is not drawn under the cursor still keeps others from acting on presses meant for it.
func (*Window) WidgetID ¶ added in v0.0.2
WidgetID is the identity a widget's state is kept under. Two calls with the same kind, place and label are the same widget; changing any of them makes a new one. The built-in widgets use it, and a template's widgets should too, so that a template widget and a built-in one never mistake each other for the same thing.
func (*Window) WidgetKeyActivate ¶ added in v0.0.2
WidgetKeyActivate reports whether Enter or Space was pressed this frame while the widget held the keyboard. A focused button, checkbox or radio is "clicked" by Enter or Space, the way the web does it.
func (*Window) WidgetStartPress ¶ added in v0.0.2
WidgetStartPress begins a press on the widget. It takes the keyboard away from any text field, the same way the built-in widgets do when pressed.
func (*Window) WidgetTabStop ¶ added in v0.0.2
WidgetTabStop says the widget takes the keyboard, at its place in the frame's focus order. Widgets register themselves, in the order they draw, and Tab walks that order.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package backend carries everything a platform backend and the library agree on, without either of them importing the other.
|
Package backend carries everything a platform backend and the library agree on, without either of them importing the other. |
|
android
Package android is AntUI on a phone: the platform underneath an Android app, and the tools that turn a Go program into one the Play Store takes.
|
Package android is AntUI on a phone: the platform underneath an Android app, and the tools that turn a Go program into one the Play Store takes. |
|
android/apk
Package apk builds an Android package out of a Go program.
|
Package apk builds an Android package out of a Go program. |
|
android/app
Package app is the shape of an Android app: the activity Android created, the surface it draws on, and the lifecycle it is dragged through.
|
Package app is the shape of an Android app: the activity Android created, the surface it draws on, and the lifecycle it is dragged through. |
|
android/assets
Package assets reads the files packed into the APK, as an io/fs.FS.
|
Package assets reads the files packed into the APK, as an io/fs.FS. |
|
android/audio
Package audio is the part of sound that is Android's rather than AntUI's: asking the system for the right to be heard, noticing the headphones coming out, and listening through the microphone.
|
Package audio is the part of sound that is Android's rather than AntUI's: asking the system for the right to be heard, noticing the headphones coming out, and listening through the microphone. |
|
android/biometric
Package biometric asks the user to prove who they are with a fingerprint or a face.
|
Package biometric asks the user to prove who they are with a fingerprint or a face. |
|
android/camera
Package camera opens the device's cameras and hands each frame over as a [canvas.Canvas].
|
Package camera opens the device's cameras and hands each frame over as a [canvas.Canvas]. |
|
android/clipboard
Package clipboard is the system clipboard: text in and text out.
|
Package clipboard is the system clipboard: text in and text out. |
|
android/device
Package device is what the machine says about itself: what it is called, what version of Android it runs, where in the world it is set to, and an identifier for this app on it.
|
Package device is what the machine says about itself: what it is called, what version of Android it runs, where in the world it is set to, and an identifier for this app on it. |
|
android/dialog
Package dialog puts the platform's own dialog on screen.
|
Package dialog puts the platform's own dialog on screen. |
|
android/display
Package display is the screen: how big it is, how dense, how fast, and whether there is more than one.
|
Package display is the screen: how big it is, how dense, how fast, and whether there is more than one. |
|
android/gallery
Package gallery puts pictures, videos and sounds into the device's own library, where the gallery and every other app can see them.
|
Package gallery puts pictures, videos and sounds into the device's own library, where the gallery and every other app can see them. |
|
android/intent
Package intent is how an app asks the rest of the device to do something: open a link, share some text, view a file — and how it reads what another app asked of it.
|
Package intent is how an app asks the rest of the device to do something: open a link, share some text, view a file — and how it reads what another app asked of it. |
|
android/jni
Package jni calls Java from Go.
|
Package jni calls Java from Go. |
|
android/location
Package location says where the device is.
|
Package location says where the device is. |
|
android/media
Package media plays a video file into a [canvas.Canvas], and decodes its sound into samples.
|
Package media plays a video file into a [canvas.Canvas], and decodes its sound into samples. |
|
android/ndk
Package ndk is the thin part: the C APIs Android exposes to native code, bound one to one and nothing more.
|
Package ndk is the thin part: the C APIs Android exposes to native code, bound one to one and nothing more. |
|
android/network
Package network says what the device is connected to and whether the connection costs money.
|
Package network says what the device is connected to and whether the connection costs money. |
|
android/notify
Package notify posts notifications.
|
Package notify posts notifications. |
|
android/permission
Package permission asks the user for the things Android will not give an app for the asking: the camera, the microphone, where the device is.
|
Package permission asks the user for the things Android will not give an app for the asking: the camera, the microphone, where the device is. |
|
android/picker
Package picker asks the user to choose a file.
|
Package picker asks the user to choose a file. |
|
android/power
Package power is the battery and the states the system puts a device into to protect it.
|
Package power is the battery and the states the system puts a device into to protect it. |
|
android/prefs
Package prefs is Android's SharedPreferences: a small named store of settings that survives the app being closed.
|
Package prefs is Android's SharedPreferences: a small named store of settings that survives the app being closed. |
|
android/sdk
Package sdk finds the Android SDK, the NDK and a JDK on the machine doing the building, and says where each tool inside them is.
|
Package sdk finds the Android SDK, the NDK and a JDK on the machine doing the building, and says where each tool inside them is. |
|
android/sensor
Package sensor reads the device's sensors.
|
Package sensor reads the device's sensors. |
|
android/share
Package share hands a file to another app.
|
Package share hands a file to another app. |
|
android/shim
Package shim holds the only Java in this library, and the compiled form of it that ships inside an APK.
|
Package shim holds the only Java in this library, and the compiled form of it that ships inside an APK. |
|
android/speech
Package speech turns text into sound and sound into text.
|
Package speech turns text into sound and sound into text. |
|
android/sqlite
Package sqlite is the SQLite every Android device already has.
|
Package sqlite is the SQLite every Android device already has. |
|
linux
Package linux drives windows over the X11 protocol, spoken straight over the socket with nothing to link against.
|
Package linux drives windows over the X11 protocol, spoken straight over the socket with nothing to link against. |
|
macos
Package macos drives windows on Cocoa (AppKit) through the Objective-C runtime.
|
Package macos drives windows on Cocoa (AppKit) through the Objective-C runtime. |
|
windows
Package windows drives windows on Win32 (user32 + gdi32), driven through syscall.
|
Package windows drives windows on Win32 (user32 + gdi32), driven through syscall. |
|
Package blendasm is the assembly half of row blending, and it is a package of its own for one reason: a package that uses cgo may not hold Go assembly.
|
Package blendasm is the assembly half of row blending, and it is a package of its own for one reason: a package that uses cgo may not hold Go assembly. |
|
Package template is how a whole screen of AntUI is made without drawing a single control from scratch.
|
Package template is how a whole screen of AntUI is made without drawing a single control from scratch. |
|
audio
Package audio is the hearable half of a template: a set of short sounds, one per interactive component, that plays through [antui.OpenAudio] when the component is used.
|
Package audio is the hearable half of a template: a set of short sounds, one per interactive component, that plays through [antui.OpenAudio] when the component is used. |
|
event
Package event is what the templates agree on: the components that exist, the things they can do, and the sound bank that hears about them.
|
Package event is what the templates agree on: the components that exist, the things they can do, and the sound bank that hears about them. |