layout

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 3 Imported by: ? modules, 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 layout holds the layout options of the Tango self-drawn UI: Row/Column/Stack containers take Options built here (Grow, W, H, Pad, Gap, Align, Justify, Abs ...), and Box.Style applies more. The layout solver itself (flexbox-style: Grow/Shrink/Basis, Gap, Padding, Margin, Align, Justify, Wrap, Stack and absolute positioning) is internal.

API tiers: only the symbols listed in api/stable/ui_layout.txt are covered by the compatibility promise of docs/release.md ("API 稳定性"); every other exported symbol is Experimental and may change in any 0.x release. The API reference on the documentation site marks the experimental symbols.

Index

Constants

This section is empty.

Variables

View Source
var Unset = float32(math.NaN())

Unset marks an unused edge of Abs. It is a variable only because Go has no NaN constant: treat it as a constant and never assign to it.

Functions

This section is empty.

Types

type Align

type Align uint8

Align positions items on the cross axis.

Append-only: never reorder or insert; the zero value stays AlignAuto.

const (
	AlignAuto    Align = iota // AlignSelf: inherit; Align: same as Stretch
	AlignStretch              // fill the cross axis
	AlignStart
	AlignCenter
	AlignEnd
)

type Direction

type Direction uint8

Direction is the main axis of a container.

Append-only: never reorder or insert; the zero value stays Column.

const (
	Column Direction = iota // children top to bottom (default)
	Row                     // children left to right
	Stack                   // children overlap, aligned in both axes
)

type Justify

type Justify uint8

Justify distributes free space on the main axis.

Append-only: never reorder or insert; the zero value stays JustifyStart.

const (
	JustifyStart Justify = iota
	JustifyCenter
	JustifyEnd
	JustifySpaceBetween
	JustifySpaceAround
	JustifySpaceEvenly
)

type Option

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

Option sets one aspect of a node's layout. It is opaque: build it with the functions of this package and pass it to containers (ui.Row, ui.Column, ui.Div ...) or Box.Style. The zero Option does nothing.

func Abs

func Abs(left, top, right, bottom float32) Option

Abs positions the node absolutely; pass Unset for unused edges.

func AlignItems

func AlignItems(a Align) Option

Align sets cross-axis alignment of children.

func Basis

func Basis(v float32) Option

Basis sets an explicit flex basis.

func Between

func Between() Option

Between spreads children with space-between.

func Center

func Center() Option

Center centers children on both axes.

func Dir

func Dir(d Direction) Option

Dir sets the container direction.

func End

func End() Option

End packs children at the end of the main axis.

func Fill

func Fill() Option

Fill makes the node grow on the main axis and stretch on the cross axis.

func Gap

func Gap(v float32) Option

Gap sets the main-axis gap between children (and the wrap line gap).

func GapXY

func GapXY(main, lines float32) Option

GapXY sets main-axis gap and wrapped-line gap separately.

func Grow

func Grow(g float32) Option

Grow sets the flex grow factor (basis defaults to 0).

func H

func H(v float32) Option

H fixes the height.

func JustifyContent

func JustifyContent(j Justify) Option

JustifyContent sets main-axis distribution.

func Margin

func Margin(in geom.Insets) Option

Margin sets per-edge margin.

func MaxH

func MaxH(v float32) Option

func MaxW

func MaxW(v float32) Option

func Middle

func Middle() Option

Middle centers children on the cross axis (vertical centering in rows).

func MinH

func MinH(v float32) Option

func MinW

func MinW(v float32) Option

MinW / MaxW / MinH / MaxH clamp the size.

func NoStretch

func NoStretch() Option

NoStretch keeps the node's own cross size where the alignment would stretch it; it is then placed at the start of the cross axis.

func Pad

func Pad(v float32) Option

Pad sets equal padding.

func PadSE

func PadSE(v, start, end float32) Option

PadSE sets vertical padding v and inline start/end padding. Left/Right of geom.Insets are the start/end sides (they swap physically in RTL boxes).

func PadVH

func PadVH(v, h float32) Option

PadVH sets CSS two-value padding.

func Padding

func Padding(in geom.Insets) Option

Padding sets per-edge padding.

func Physical

func Physical() Option

Physical keeps the node at its physical (LTR) position inside an RTL parent: its x is not mirrored. Use it for things pinned to a physical edge regardless of reading direction. It does not affect the node's own children; those follow the node's RTL flag.

func ScrollX

func ScrollX() Option

ScrollX lets the content exceed the box horizontally; the container scrolls or clips it.

func ScrollY

func ScrollY() Option

ScrollY lets the content exceed the box vertically.

func Self

func Self(a Align) Option

Self sets this node's own cross-axis alignment.

func Shrink

func Shrink(v float32) Option

Shrink sets the flex shrink factor.

func Size

func Size(w, h float32) Option

Size fixes both dimensions.

func Stretch

func Stretch() Option

Stretch makes the node fill the cross axis, undoing NoStretch.

func W

func W(v float32) Option

W fixes the width.

func WrapItems

func WrapItems() Option

WrapItems enables wrapping.

Jump to

Keyboard shortcuts

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