Skip to content

layout ​

分层

只有 api/stable/ui_layout.txt 列出的符号受兼容性承诺约束。标有「实验性」的符号,以及类型下「实验性成员」列出的字段,任何 0.x 版本都可能有不兼容变化(docs/release.md「API 稳定性」)。

go
import "github.com/tangoui/tango/ui/layout"

本页由 site/tools/apigen 从源码注释生成(按 darwin 构建标签选文件),请勿手改。

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.

变量 ​

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

类型 ​

Align ​

go
type Align uint8

Align positions items on the cross axis.

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

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

Direction ​

go
type Direction uint8

Direction is the main axis of a container.

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

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

Justify ​

go
type Justify uint8

Justify distributes free space on the main axis.

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

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

Option ​

go
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 ​

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

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

func AlignItems ​

go
func AlignItems(a Align) Option

Align sets cross-axis alignment of children.

func Basis ​

go
func Basis(v float32) Option

Basis sets an explicit flex basis.

func Between ​

go
func Between() Option

Between spreads children with space-between.

func Center ​

go
func Center() Option

Center centers children on both axes.

func Dir ​

go
func Dir(d Direction) Option

Dir sets the container direction.

func End ​

go
func End() Option

End packs children at the end of the main axis.

func Fill ​

go
func Fill() Option

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

func Gap ​

go
func Gap(v float32) Option

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

func GapXY ​

go
func GapXY(main, lines float32) Option

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

func Grow ​

go
func Grow(g float32) Option

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

func H ​

go
func H(v float32) Option

H fixes the height.

func JustifyContent ​

go
func JustifyContent(j Justify) Option

JustifyContent sets main-axis distribution.

func Margin ​

go
func Margin(in geom.Insets) Option

Margin sets per-edge margin.

func MaxH ​

go
func MaxH(v float32) Option

func MaxW ​

go
func MaxW(v float32) Option

func Middle ​

go
func Middle() Option

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

func MinH ​

go
func MinH(v float32) Option

func MinW ​

go
func MinW(v float32) Option

MinW / MaxW / MinH / MaxH clamp the size.

func NoStretch 实验性 ​

go
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 ​

go
func Pad(v float32) Option

Pad sets equal padding.

func PadSE ​

go
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 ​

go
func PadVH(v, h float32) Option

PadVH sets CSS two-value padding.

func Padding ​

go
func Padding(in geom.Insets) Option

Padding sets per-edge padding.

func Physical ​

go
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 实验性 ​

go
func ScrollX() Option

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

func ScrollY 实验性 ​

go
func ScrollY() Option

ScrollY lets the content exceed the box vertically.

func Self ​

go
func Self(a Align) Option

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

func Shrink ​

go
func Shrink(v float32) Option

Shrink sets the flex shrink factor.

func Size ​

go
func Size(w, h float32) Option

Size fixes both dimensions.

func Stretch 实验性 ​

go
func Stretch() Option

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

func W ​

go
func W(v float32) Option

W fixes the width.

func WrapItems ​

go
func WrapItems() Option

WrapItems enables wrapping.

以 MIT 许可发布