Documentation
¶
Overview ¶
Package ui owns the immediate-mode frame tree, controls, editors, input routing and the Renderer behind the public nefergui facade.
Index ¶
- type ButtonEvent
- type ButtonOption
- type ChangeEvent
- type Clipboard
- type CommonOption
- type ContainerOption
- type Cursor
- type DisabledOption
- type EditEvent
- type EditOption
- type Format
- type Frame
- type HeadingOption
- type IME
- type Input
- type InputKind
- type Modifiers
- type Node
- func (n Node) Aside(options ...ContainerOption) Node
- func (n Node) Box(options ...ContainerOption) Node
- func (n Node) Button(label string, options ...ButtonOption) ButtonEvent
- func (n Node) Checkbox(label string, value *bool, options ...ButtonOption) ChangeEvent
- func (n Node) Column(options ...ContainerOption) Node
- func (n Node) Element(typ string, options ...ContainerOption) Node
- func (n Node) Footer(options ...ContainerOption) Node
- func (n Node) Header(options ...ContainerOption) Node
- func (n Node) Heading(text string, options ...HeadingOption)
- func (n Node) Icon(name string, options ...ContainerOption)
- func (n Node) Image(img image.Image, options ...ContainerOption)
- func (n Node) Input(label string, value *string, options ...EditOption) EditEvent
- func (n Node) Main(options ...ContainerOption) Node
- func (n Node) Masked(count int, options ...ContainerOption)
- func (n Node) Nav(options ...ContainerOption) Node
- func (n Node) Radio(label, option string, selected *string, options ...ButtonOption) ChangeEvent
- func (n Node) Rect(x, y, w, h float64) Node
- func (n Node) Row(options ...ContainerOption) Node
- func (n Node) Scroll(options ...ContainerOption) Node
- func (n Node) Section(options ...ContainerOption) Node
- func (n Node) Separator(options ...ContainerOption)
- func (n Node) Slider(label string, value *float64, min, max, step float64, options ...ValueOption) ChangeEvent
- func (n Node) Spacer(options ...ContainerOption)
- func (n Node) Stack(options ...ContainerOption) Node
- func (n Node) Text(text string, options ...ContainerOption)
- func (n Node) TextInt(prefix string, v int64, options ...ContainerOption)
- func (n Node) Textarea(label string, value *string, options ...EditOption) EditEvent
- type Output
- type Plane
- type Rect
- type Renderer
- func (r *Renderer) Close() error
- func (r *Renderer) Input(ev *Input) bool
- func (r *Renderer) Invalidate()
- func (r *Renderer) Measure[T any](model *T, view func(*Frame, *T), maxWidth float64) (width, height float64, err error)
- func (r *Renderer) Pending() bool
- func (r *Renderer) Released(buffer uint64) error
- func (r *Renderer) Render[T any](out *Output, model *T, view func(*Frame, *T)) (bool, error)
- func (r *Renderer) Resize(width, height int, scale float64)
- func (r *Renderer) Wake() <-chan struct{}
- type RendererConfig
- type Retired
- type Timeline
- type ValueOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ButtonEvent ¶
type ButtonEvent struct {
// contains filtered or unexported fields
}
Control event values are immutable snapshots; querying them never consumes events.
func (ButtonEvent) Activated ¶
func (e ButtonEvent) Activated() bool
type ButtonOption ¶
type ButtonOption interface {
// contains filtered or unexported methods
}
type ChangeEvent ¶
type ChangeEvent struct {
// contains filtered or unexported fields
}
func (ChangeEvent) Changed ¶
func (e ChangeEvent) Changed() bool
type Clipboard ¶ added in v0.5.0
type Clipboard = edit.AsyncClipboard
Clipboard is the optional asynchronous clipboard; IME the optional input method.
type CommonOption ¶
type CommonOption struct {
// contains filtered or unexported fields
}
CommonOption is the concrete type of Key, ID, Class and Inline; it belongs to every option family. It is exported only so the root facade can return it. It is plain data rather than a closure, so creating one never allocates.
func Class ¶
func Class(class string) CommonOption
func ID ¶
func ID(id string) CommonOption
func Inline ¶
func Inline(src string) CommonOption
func Key ¶
func Key(key string) CommonOption
type ContainerOption ¶
type ContainerOption interface {
// contains filtered or unexported methods
}
ContainerOption, ButtonOption and EditOption are separate option families.
type DisabledOption ¶
type DisabledOption struct {
// contains filtered or unexported fields
}
DisabledOption is the concrete type of Disabled. It applies to every interactive control (buttons, value controls and editors) but not to containers or headings. Exported only so the root facade can return it.
func Disabled ¶
func Disabled(v bool) DisabledOption
Disabled blocks focus and interaction on an interactive control.
type EditOption ¶
type EditOption interface {
// contains filtered or unexported methods
}
func Password ¶
func Password(v bool) EditOption
func Placeholder ¶
func Placeholder(v string) EditOption
type Frame ¶
type Frame struct {
// contains filtered or unexported fields
}
Frame is valid only during one call to the view function.
func (*Frame) Diagnostics ¶
Diagnostics returns a copy of frame diagnostics (populated with -tags nefergui_debug).
func (*Frame) Root ¶
func (f *Frame) Root(options ...ContainerOption) Node
func (*Frame) SetInputRects ¶ added in v0.2.0
SetInputRects stages the input region for the surface: pointer input outside the rectangles passes through. Renderer reports it in Output.InputRects when it changes. nil restores the whole surface, and a non-nil empty slice makes the surface click-through. Rects need positive size. The slice is copied, so callers may reuse it; an unchanged region costs nothing.
type HeadingOption ¶
type HeadingOption interface {
// contains filtered or unexported methods
}
HeadingOption accepts common CSS options and Level, but not control options.
func Level ¶
func Level(level int) HeadingOption
Level sets the accessibility heading level (1 through 6).
type IME ¶ added in v0.5.0
Clipboard is the optional asynchronous clipboard; IME the optional input method.
type Input ¶ added in v0.5.0
type Input struct {
Kind InputKind
X, Y, DX, DY float64 // logical pixels; DX, DY are scroll deltas
Button uint32 // evdev code
Pressed bool
Repeat bool
Keysym uint32 // xkb keysym
Text []byte
Modifiers Modifiers
}
Input is one platform input event. Text is read only during the call.
type Modifiers ¶ added in v0.2.0
type Modifiers uint8
Modifiers is a bit set of keyboard modifiers held during a key or pointer event. ModShift, ModCtrl, ModAlt and ModSuper report held keys; ModCapsLock and ModNumLock report the latched lock state. The Renderer reads only ModShift and ModCtrl, so lock bits never change shortcuts or text entry. The Renderer does not expose modifiers to views: an application that shows a lock indicator records the lock bits of Input.Modifiers in its own model.
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node is an ephemeral handle into the current frame. Do not retain it between frames.
func (Node) Aside ¶
func (n Node) Aside(options ...ContainerOption) Node
func (Node) Box ¶
func (n Node) Box(options ...ContainerOption) Node
func (Node) Button ¶
func (n Node) Button(label string, options ...ButtonOption) ButtonEvent
func (Node) Checkbox ¶
func (n Node) Checkbox(label string, value *bool, options ...ButtonOption) ChangeEvent
func (Node) Column ¶
func (n Node) Column(options ...ContainerOption) Node
func (Node) Footer ¶
func (n Node) Footer(options ...ContainerOption) Node
func (Node) Header ¶
func (n Node) Header(options ...ContainerOption) Node
func (Node) Heading ¶
func (n Node) Heading(text string, options ...HeadingOption)
func (Node) Icon ¶
func (n Node) Icon(name string, options ...ContainerOption)
func (Node) Image ¶
func (n Node) Image(img image.Image, options ...ContainerOption)
Image borrows a decoded Go image. Treat its pixels as immutable while passed to Image; pass a new image value to change pixels. Renderer cache identity requires a comparable image.Image value (for example, *image.RGBA).
func (Node) Input ¶
func (n Node) Input(label string, value *string, options ...EditOption) EditEvent
func (Node) Main ¶
func (n Node) Main(options ...ContainerOption) Node
func (Node) Masked ¶ added in v0.5.0
func (n Node) Masked(count int, options ...ContainerOption)
Masked shows count bullet glyphs and stores no value, for a secret held outside the view (a password field fed from an external buffer). A negative count shows nothing.
func (Node) Nav ¶
func (n Node) Nav(options ...ContainerOption) Node
func (Node) Radio ¶
func (n Node) Radio(label, option string, selected *string, options ...ButtonOption) ChangeEvent
func (Node) Rect ¶ added in v0.2.0
Rect positions the node at x, y with size w, h in logical pixels, relative to the content box of its Stack parent, without CSS parsing or per-frame strings or style copies. The geometry is border-box and overrides authored width, height and margin. Rect is valid only on a direct child of Stack; elsewhere it is ignored, keeping normal flex and block layout, and debug builds (-tags nefergui_debug) report it through Frame.Diagnostics.
func (Node) Row ¶
func (n Node) Row(options ...ContainerOption) Node
func (Node) Scroll ¶
func (n Node) Scroll(options ...ContainerOption) Node
func (Node) Section ¶
func (n Node) Section(options ...ContainerOption) Node
func (Node) Separator ¶
func (n Node) Separator(options ...ContainerOption)
func (Node) Slider ¶
func (n Node) Slider(label string, value *float64, min, max, step float64, options ...ValueOption) ChangeEvent
func (Node) Spacer ¶
func (n Node) Spacer(options ...ContainerOption)
func (Node) Stack ¶
func (n Node) Stack(options ...ContainerOption) Node
func (Node) Text ¶
func (n Node) Text(text string, options ...ContainerOption)
func (Node) TextInt ¶ added in v0.5.0
func (n Node) TextInt(prefix string, v int64, options ...ContainerOption)
TextInt shows prefix followed by v in decimal without fmt boxing. A prefix up to 76 bytes is built in a stack buffer, so the only allocation is the final string; a longer prefix costs one more.
type Output ¶ added in v0.5.0
type Output struct {
Buffer uint64
NewBuffer bool
Retired []Retired
Width, Height int32
FourCC uint32
Modifier uint64
Planes [4]Plane
PlaneCount int
Acquire, Release Timeline
NewTimelines bool
AcquirePoint uint64
ReleasePoint uint64
ReleaseFD int
Damage []Rect
Cursor Cursor
InputRects []Rect
InputRectsChanged bool
}
Output describes one frame to present, in physical pixels. Every file descriptor stays owned by the Renderer. Slices are reused and valid until the next Render.
type Rect ¶ added in v0.2.0
type Rect struct{ X, Y, Width, Height int32 }
Rect is an integer logical-pixel rectangle in surface coordinates.
type Renderer ¶ added in v0.5.0
type Renderer struct {
// contains filtered or unexported fields
}
Renderer renders views into DMA-BUF buffers for a transport it does not know. It owns no Wayland object and starts no goroutine. All methods except Wake run on one owner goroutine.
func NewRenderer ¶ added in v0.5.0
func NewRenderer(cfg RendererConfig) (*Renderer, error)
NewRenderer opens the GPU for cfg.MainDevice and loads fonts and styles. It allocates no images.
func (*Renderer) Close ¶ added in v0.5.0
Close cancels pending pastes and frees the GPU resources. The Renderer is unusable afterwards.
func (*Renderer) Input ¶ added in v0.5.0
Input routes one event and reports whether a redraw is needed.
func (*Renderer) Invalidate ¶ added in v0.5.0
func (r *Renderer) Invalidate()
Invalidate requests a rebuild at the next Render.
func (*Renderer) Measure ¶ added in v0.7.0
func (r *Renderer) Measure[T any](model *T, view func(*Frame, *T), maxWidth float64) (width, height float64, err error)
Measure returns the logical size, in pixels rounded up, that view needs for model: its natural width, at most maxWidth, and the height the content takes at that width (text wraps at maxWidth). Use it to size a surface before creating it. The size includes the root's margins.
The view is built in a temporary runtime that shares only this Renderer's styles and text engine. Those caches only grow during Measure: it does not age their entries, so a later Render finds its own entries intact. Hover, focus, scroll offsets, editor state, queued input, the Wake channel and the target are neither read nor changed, nothing is drawn, and the view sees no events.
There is no surface yet, so the height is indefinite: inside the view Frame.Size reports an unbounded height (1<<20), and percentage height, min-height and max-height of the root are treated as auto, as for nested boxes, instead of resolving against that value. Lengths in pixels apply.
Call it from the owner goroutine, before or after Resize, never from inside a view callback. It allocates and shapes text: use it when opening a surface, not on every frame. It returns an error when the Renderer is closed, model or view is nil, maxWidth is not a finite number above zero, or the view cannot be laid out (the layout error is wrapped). A view that declares no root measures 0 by 0.
func (*Renderer) Pending ¶ added in v0.5.0
Pending reports that a built frame is waiting for the GPU (a buffer still being drawn, or a release wait not yet installed) rather than for the compositor. No event announces this: arm a short timer (for example 2 ms) and call Render again. It is false while every buffer belongs to the compositor; Released is the wake-up for that case.
func (*Renderer) Released ¶ added in v0.5.0
Released must be called when the release eventfd of an Output buffer is readable. It lets the buffer be reused.
func (*Renderer) Render ¶ added in v0.5.0
Render builds the view and, when something changed and a buffer is free, draws it. It returns false without touching the GPU when nothing changed, no buffer is available yet (call it again after Released) or before the first Resize. When it returns true, out describes the frame to present.
type RendererConfig ¶ added in v0.5.0
type RendererConfig struct {
MainDevice uint64 // dev_t from linux-dmabuf feedback main_device
Formats []Format // compositor preference order, tranches flattened
Transparent bool // ARGB8888 instead of XRGB8888
Styles string // optional CSS file path
Clipboard Clipboard
IME IME
}
RendererConfig configures a Wayland-free Renderer.
type Retired ¶ added in v0.5.0
Plane, Timeline and Retired are the transport-facing parts of Output.
type Timeline ¶ added in v0.5.0
Plane, Timeline and Retired are the transport-facing parts of Output.
type ValueOption ¶
type ValueOption interface {
// contains filtered or unexported methods
}
ValueOption accepts CSS options and Disabled for pointer-backed controls.