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 ¶
- func Col(gtx gio.Context, children ...gio.Widget) gio.Dimensions
- func HSpacer(dp float32) gio.Widget
- func Inset(dp float32) gio.Inset
- func InsetXY(h, v float32) gio.Inset
- func Pill(ops *op.Ops, rect image.Rectangle, rad int) clip.Op
- func Row(gtx gio.Context, children ...gio.Widget) gio.Dimensions
- func VSpacer(dp float32) gio.Widget
- type FocusGroup
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Col ¶
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 ¶
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 InsetXY ¶
InsetXY returns an inset with h horizontal (left+right) and v vertical (top+bottom) device-independent padding.
func Pill ¶
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.
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.