layout
分层
只有 api/stable/ui_layout.txt 列出的符号受兼容性承诺约束。标有「实验性」的符号,以及类型下「实验性成员」列出的字段,任何 0.x 版本都可能有不兼容变化(docs/release.md「API 稳定性」)。
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.
变量
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
type Align uint8Align 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
)Direction
type Direction uint8Direction 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
)Justify
type Justify uint8Justify 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
)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) OptionAbs positions the node absolutely; pass Unset for unused edges.
func AlignItems
func AlignItems(a Align) OptionAlign sets cross-axis alignment of children.
func Basis
func Basis(v float32) OptionBasis sets an explicit flex basis.
func Between
func Between() OptionBetween spreads children with space-between.
func Center
func Center() OptionCenter centers children on both axes.
func Dir
func Dir(d Direction) OptionDir sets the container direction.
func End
func End() OptionEnd packs children at the end of the main axis.
func Fill
func Fill() OptionFill makes the node grow on the main axis and stretch on the cross axis.
func Gap
func Gap(v float32) OptionGap sets the main-axis gap between children (and the wrap line gap).
func GapXY
func GapXY(main, lines float32) OptionGapXY sets main-axis gap and wrapped-line gap separately.
func Grow
func Grow(g float32) OptionGrow sets the flex grow factor (basis defaults to 0).
func H
func H(v float32) OptionH fixes the height.
func JustifyContent
func JustifyContent(j Justify) OptionJustifyContent sets main-axis distribution.
func Margin
func Margin(in geom.Insets) OptionMargin sets per-edge margin.
func MaxH
func MaxH(v float32) Optionfunc MaxW
func MaxW(v float32) Optionfunc Middle
func Middle() OptionMiddle centers children on the cross axis (vertical centering in rows).
func MinH
func MinH(v float32) Optionfunc MinW
func MinW(v float32) OptionMinW / MaxW / MinH / MaxH clamp the size.
func NoStretch 实验性
func NoStretch() OptionNoStretch 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) OptionPad sets equal padding.
func PadSE
func PadSE(v, start, end float32) OptionPadSE 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) OptionPadVH sets CSS two-value padding.
func Padding
func Padding(in geom.Insets) OptionPadding sets per-edge padding.
func Physical
func Physical() OptionPhysical 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() OptionScrollX lets the content exceed the box horizontally; the container scrolls or clips it.
func ScrollY 实验性
func ScrollY() OptionScrollY lets the content exceed the box vertically.
func Self
func Self(a Align) OptionSelf sets this node's own cross-axis alignment.
func Shrink
func Shrink(v float32) OptionShrink sets the flex shrink factor.
func Size
func Size(w, h float32) OptionSize fixes both dimensions.
func Stretch 实验性
func Stretch() OptionStretch makes the node fill the cross axis, undoing NoStretch.
func W
func W(v float32) OptionW fixes the width.
func WrapItems
func WrapItems() OptionWrapItems enables wrapping.