antui

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2026 License: Apache-2.0 Imports: 20 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 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

View Source
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.

View Source
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.

View Source
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.

View Source
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.

View Source
const (
	ModShift   = backend.ModShift
	ModControl = backend.ModControl
	ModAlt     = backend.ModAlt
	ModSuper   = backend.ModSuper
)

The modifiers, combined with |.

View Source
const (
	MouseLeft   = backend.MouseLeft
	MouseRight  = backend.MouseRight
	MouseMiddle = backend.MouseMiddle
)

The mouse buttons.

View Source
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

View Source
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.

View Source
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

func LabelHeight(pad int) int

LabelHeight is how tall one is with pad above and below.

func LabelWidth

func LabelWidth(text string, pad int) int

LabelWidth is how wide a piece of text is with pad either side of it.

func LabelsWidth

func LabelsWidth(labels []string, pad, gap int) int

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

func SetSystemFace(points, scale float64) bool

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 Sleep

func Sleep(seconds float64)

Sleep pauses for a number of seconds.

func SystemFace

func SystemFace(pixels float64) (*canvas.Face, error)

SystemFace is the platform's own interface font at a size in pixels.

face, err := antui.SystemFace(15)
if err == nil {
    antui.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

func SystemFont() (path string, data []byte, err error)

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

func UIFace(points, scale float64) (*canvas.Face, error)

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

func WrapLabels(labels []string, pad, gap, most int) []int

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

func WriteICO(w io.Writer, images ...*canvas.Canvas) error

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

func WriteWindowsResource(w io.Writer, images ...*canvas.Canvas) error

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.

func WriteWindowsResourceFor

func WriteWindowsResourceFor(w io.Writer, arch string, images ...*canvas.Canvas) error

WriteWindowsResourceFor is WriteWindowsResource for an architecture other than the usual one.

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

func OpenAudio(name string, rate int, fill func([]float32)) (*Audio, error)

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) Channels

func (a *Audio) Channels() int

Channels is how many there are in a frame. Two, everywhere, for now.

func (*Audio) Close

func (a *Audio) Close() error

Close stops the sound. It is safe to call twice.

func (*Audio) Err

func (a *Audio) Err() error

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.

func (*Audio) Latency

func (a *Audio) Latency() time.Duration

Latency is roughly how long it is between a sample being written and being heard. It is what the device was talked into rather than a measurement.

func (*Audio) Rate

func (a *Audio) Rate() int

Rate is how many frames a second the device is really running at.

type Event

type Event = backend.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

type EventType = backend.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

type Key = backend.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

type Limits = backend.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 Mod

type Mod = backend.Mod

Mod is a set of held modifier keys.

type MouseButton

type MouseButton = backend.MouseButton

MouseButton identifies a mouse button.

type Options

type Options = backend.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 Tool

type Tool = backend.Tool

Tool is what is touching the screen.

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 Open

func Open(title string, width, height int) (*Window, error)

Open creates and shows a window: resizable, unbounded, its size in pixels.

func OpenWith

func OpenWith(opt Options) (*Window, error)

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

func (win *Window) Begin() bool

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) Blit

func (win *Window) Blit(x, y int, src *canvas.Canvas)

Blit composites another canvas over the window.

func (*Window) BlitScaled

func (win *Window) BlitScaled(x, y, width, height int, src *canvas.Canvas)

BlitScaled draws another canvas fitted into a rectangle.

func (*Window) Bounds

func (win *Window) Bounds() Limits

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) Button

func (win *Window) Button(x, y, w, h int, label string) bool

Button draws a button and reports whether it was clicked this frame.

func (*Window) Canvas

func (win *Window) Canvas() *canvas.Canvas

Canvas is the window's pixel surface: direct access, if you need it.

func (*Window) Checkbox

func (win *Window) Checkbox(x, y int, label string, value *bool) bool

Checkbox draws a labelled checkbox, flips value when clicked, and reports whether it changed this frame.

func (*Window) Circle

func (win *Window) Circle(cx, cy, radius int, c canvas.Color)

Circle draws a circle outline.

func (*Window) Clear

func (win *Window) Clear(c canvas.Color)

Clear paints the whole window in one colour.

func (*Window) Clicked

func (win *Window) Clicked(x, y, w, h int) bool

Clicked reports whether a rectangle was clicked or tapped this frame, drawing nothing at all.

func (*Window) ClickedID

func (win *Window) ClickedID(name string, x, y, w, h int) bool

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

func (win *Window) ClipboardFiles() []string

ClipboardFiles is the files the clipboard names. Empty when it holds none.

func (*Window) ClipboardText

func (win *Window) ClipboardText() string

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

func (win *Window) ContentScale() float64

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) Delta

func (win *Window) Delta() float64

Delta is how long the last frame took, in seconds.

func (*Window) DisplayRefresh

func (win *Window) DisplayRefresh() int

DisplayRefresh is how many times a second the display refreshes, or 0 when it could not be told.

func (*Window) DisplaySize

func (win *Window) DisplaySize() (width, height int, ok bool)

DisplaySize is the display's size in pixels, and whether it could be told.

func (*Window) DroppedFiles

func (win *Window) DroppedFiles() []string

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) Events

func (win *Window) Events(yield func(Event) bool)

Events iterates this frame's queue, draining it as it goes.

func (*Window) FillCircle

func (win *Window) FillCircle(cx, cy, radius int, c canvas.Color)

FillCircle fills a disc.

func (*Window) FillRect

func (win *Window) FillRect(x, y, w, h int, c canvas.Color)

FillRect fills a rectangle.

func (*Window) FillRoundRect

func (win *Window) FillRoundRect(x, y, w, h, r int, c canvas.Color)

FillRoundRect fills a rounded rectangle.

func (*Window) FillTriangle

func (win *Window) FillTriangle(x0, y0, x1, y1, x2, y2 int, c canvas.Color)

FillTriangle fills a triangle.

func (*Window) Fullscreen

func (win *Window) Fullscreen() bool

Fullscreen reports what was last asked for, not what a window manager did about it.

func (*Window) Gestures

func (win *Window) Gestures() Gestures

Gestures is what the fingers did this frame.

func (*Window) Height

func (win *Window) Height() int

Height is the drawable height in pixels.

func (*Window) Hovered

func (win *Window) Hovered(x, y, w, h int) bool

Hovered reports whether the pointer is inside a rectangle.

func (*Window) Input

func (win *Window) Input(x, y, w, h int, text *string) bool

Input draws a single-line text field and reports whether the text changed this frame.

func (*Window) KeyDown

func (win *Window) KeyDown(k Key) bool

KeyDown reports whether a key is held.

func (*Window) KeyPressed

func (win *Window) KeyPressed(k Key) bool

KeyPressed reports whether a key went down during this frame.

func (*Window) KeyReleased

func (win *Window) KeyReleased(k Key) bool

KeyReleased reports whether a key came up during this frame.

func (*Window) Keys

func (win *Window) Keys() iter.Seq[Key]

Keys walks every key that is held or that went down or up this frame.

func (*Window) Label

func (win *Window) Label(x, y int, text string)

Label draws plain text in the theme's text colour.

func (*Window) Limits

func (win *Window) Limits() Limits

Limits returns the constraints the window was given.

func (*Window) Line

func (win *Window) Line(x0, y0, x1, y1 int, c canvas.Color)

Line draws a line.

func (*Window) Mods

func (win *Window) Mods() Mod

Mods is the set of modifier keys held.

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) MouseX

func (win *Window) MouseX() int

MouseX is the pointer's horizontal position, in window pixels.

func (*Window) MouseY

func (win *Window) MouseY() int

MouseY is the pointer's vertical position, in window pixels.

func (*Window) NextEvent

func (win *Window) NextEvent() (Event, bool)

NextEvent pops the next event off this frame's queue, reporting false when it is empty.

func (*Window) Pixel

func (win *Window) Pixel(x, y int, c canvas.Color)

Pixel blends one pixel.

func (*Window) Progress

func (win *Window) Progress(x, y, w, h int, progress float32)

Progress draws a progress bar, with progress running from 0 to 1.

func (*Window) Push

func (win *Window) Push(ev Event)

push folds an event into the input state and queues it for NextEvent.

func (*Window) PushSimple

func (win *Window) PushSimple(t EventType)

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

func (win *Window) Radio(x, y int, label string, value *int, option int) bool

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) Rect

func (win *Window) Rect(x, y, w, h int, c canvas.Color)

Rect draws a one-pixel outline.

func (*Window) ResetClip

func (win *Window) ResetClip()

ResetClip opens drawing back up to the whole window.

func (*Window) Resizable

func (win *Window) Resizable() bool

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

func (win *Window) ResizeCanvas(width, height int) bool

resizeCanvas grows or shrinks the drawable surface. Backends call it when the window system reports a new size.

func (*Window) RoundRect

func (win *Window) RoundRect(x, y, w, h, r int, c canvas.Color)

RoundRect draws a rounded outline.

func (*Window) Running

func (win *Window) Running() bool

Running reports whether the window is still open.

func (*Window) SafeArea

func (win *Window) SafeArea() canvas.Area

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) SetClip

func (win *Window) SetClip(x, y, w, h int)

SetClip narrows drawing to a rectangle.

func (*Window) SetClipboardText

func (win *Window) SetClipboardText(text string) bool

SetClipboardText puts text on the system clipboard — what a Copy button does — and reports whether the system took it.

func (*Window) SetFPS

func (win *Window) SetFPS(fps int)

SetFPS caps the frame rate in End. Zero turns the cap off.

func (*Window) SetFixedSize

func (win *Window) SetFixedSize(width, height int)

SetFixedSize locks the window to one size: both the smallest and the largest it may be, with the maximise button gone.

func (*Window) SetFullscreen

func (win *Window) SetFullscreen(on bool) bool

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

func (win *Window) SetIcon(images ...*canvas.Canvas) bool

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

func (win *Window) SetLimits(limits Limits)

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

func (win *Window) SetMouse(x, y int)

SetMouse is where a backend with no cursor position of its own records the pointer.

func (*Window) SetSafeArea

func (win *Window) SetSafeArea(a canvas.Area)

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

func (win *Window) SetSize(width, height int) bool

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) SetTheme

func (win *Window) SetTheme(theme Theme)

SetTheme replaces the whole theme at once.

func (*Window) SetTitle

func (win *Window) SetTitle(title string)

SetTitle changes the title bar.

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

func (win *Window) SizeInPoints() (width, height int)

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

func (win *Window) Slider(x, y, w, h int, value *float32, minValue, maxValue float32) bool

Slider draws a horizontal slider and reports whether the value changed this frame.

func (*Window) Text

func (win *Window) Text(x, y int, text string, c canvas.Color) int

Text draws a string and returns the width of the widest line drawn.

func (*Window) TextInput

func (win *Window) TextInput() string

TextInput is the text typed this frame, in UTF-8, empty when nothing was.

func (*Window) TextScaled

func (win *Window) TextScaled(x, y int, text string, c canvas.Color, scale int) int

TextScaled draws a string with the font blown up, returning the width of the widest line drawn.

func (*Window) Theme

func (win *Window) Theme() *Theme

Theme returns the live theme. Change its fields to restyle the widgets.

func (*Window) TouchByID

func (win *Window) TouchByID(id int) (Touch, bool)

TouchByID finds a touch by the identifier that stays with it.

func (*Window) TouchCount

func (win *Window) TouchCount() int

TouchCount is how many fingers are on the screen.

func (*Window) TouchScreen

func (win *Window) TouchScreen() bool

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

func (win *Window) Touches() []Touch

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) Triangle

func (win *Window) Triangle(x0, y0, x1, y1, x2, y2 int, c canvas.Color)

Triangle draws the edges of a triangle.

func (*Window) Wheel

func (win *Window) Wheel() int

Wheel is the wheel movement this frame, positive upwards.

func (*Window) Width

func (win *Window) Width() int

Width is the drawable width in pixels.

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.
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.

Jump to

Keyboard shortcuts

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