layout

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package layout provides spacing helpers, a FocusGroup, and flex/grid wrappers for Gio applications. It forms part of the Prism component foundation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Col

func Col(gtx gio.Context, children ...gio.Widget) gio.Dimensions

Col lays out widgets as Rigid children in a vertical Flex column, top-to-bottom. For mixed Rigid/Flexed children use gioui.org/layout.Flex directly.

func HSpacer

func HSpacer(dp float32) gio.Widget

HSpacer returns a Widget that occupies dp device-independent pixels horizontally and no vertical space. Use as a gap between children inside a Row.

func Inset

func Inset(dp float32) gio.Inset

Inset returns a uniform inset with dp device-independent pixels on all sides.

func InsetXY

func InsetXY(h, v float32) gio.Inset

InsetXY returns an inset with h horizontal (left+right) and v vertical (top+bottom) device-independent padding.

func Pill

func Pill(ops *op.Ops, rect image.Rectangle, rad int) clip.Op

Pill returns a rounded-rect clip op whose corner radius is clamped to min(w,h)/2. clip.RRect does not clamp corner radii to the rect, so a token.Radius.Full sentinel (9999 dp) passed directly to clip.RRect sprays paint across the entire canvas. Pill centralises the clamp so callers cannot reintroduce that bug.

func Row

func Row(gtx gio.Context, children ...gio.Widget) gio.Dimensions

Row lays out widgets as Rigid children in a horizontal Flex row, left-to-right. For mixed Rigid/Flexed children use gioui.org/layout.Flex directly.

func VSpacer

func VSpacer(dp float32) gio.Widget

VSpacer returns a Widget that occupies dp device-independent pixels vertically and no horizontal space. Use as a gap between children inside a Col.

Types

type FocusGroup

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

FocusGroup tracks keyboard focus among a fixed set of interactive items. Allocate once per logical group; call Update every frame before registering items via their tags.

Usage pattern:

var g layout.FocusGroup
g.Grow(3)

// each frame:
g.Update(gtx)
for i := 0; i < g.Len(); i++ {
    // inside a clip area: event.Op(gtx.Ops, g.Tag(i))
}
focused := g.Focused() // -1 if none

func (*FocusGroup) Focused

func (g *FocusGroup) Focused() int

Focused returns the index of the currently focused item, or -1 if no item in the group currently has focus.

func (*FocusGroup) Grow

func (g *FocusGroup) Grow(n int)

Grow ensures the group has at least n items. Items already present are left untouched.

func (*FocusGroup) Len

func (g *FocusGroup) Len() int

Len returns the number of items in the group.

func (*FocusGroup) Tag

func (g *FocusGroup) Tag(i int) event.Tag

Tag returns the event.Tag for item i. Pass it to event.Op inside a clip area during layout so the item participates in focus traversal. i must be in [0, Len()).

func (*FocusGroup) Update

func (g *FocusGroup) Update(gtx gio.Context)

Update refreshes focus state from the current router state. Call once per frame before the layout pass that registers item tags via event.Op.

Each item's FocusFilter is registered so the router retains focus when assigned to an item. gtx.Focused is used to query focus rather than draining FocusEvents, because focus commands applied between frames take effect immediately in the router's state.

Jump to

Keyboard shortcuts

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