Skip to content

Style properties ​

A scene.Style describes one element. Every field is optional, and an absent field uses GPUI's default. Because each snapshot is complete, a property you leave out of the next snapshot returns to its default.

go
style := &scene.Style{
	Width:          scene.Percent(100),
	Padding:        scene.Padding(16),
	Gap:            scene.Pixels(8),
	FlexDirection:  scene.FlexRow.Enum(),
	AlignItems:     scene.AlignCenter.Enum(),
	JustifyContent: scene.JustifySpaceBetween.Enum(),
	Background:     scene.RGB(0x0f172a),
	FontSize:       scene.Ptr[float32](15),
}

Value helpers ​

HelperProduces
scene.Pixels(v)A length in logical pixels
scene.Percent(v)A percentage from 0 to 100
scene.Rems(v)A length relative to the root font size
scene.Auto()An automatic length
scene.Padding(v)The same pixel length on all four edges
scene.RGB(0xRRGGBB)An opaque color
scene.Ptr[T](v)An optional scalar. An explicit zero or false stays present
.Enum()An optional enum field, as in scene.FlexColumn.Enum()

For a translucent color, build the value directly, with each channel from 0 to 1:

go
overlay := &scene.Color{Red: 0, Green: 0, Blue: 0, Alpha: 0.5}

For different edges, build a scene.Edges. Omitted edges stay unset:

go
edges := &scene.Edges{Top: scene.Pixels(8), Left: scene.Rems(1)}

Pixel and rem lengths must be finite, with a magnitude of at most 1,000,000.

Size ​

FieldTypeAccepts
Width, Height*scene.LengthPixels, percent, rems, auto. Not negative
MinWidth, MinHeight*scene.LengthSame
MaxWidth, MaxHeight*scene.LengthSame

Boxes with a fixed width, a 100 percent width, and a capped width with a minimum height

Spacing ​

FieldTypeAccepts
Padding*scene.EdgesPixels, percent, rems. Not auto or negative
Margin*scene.EdgesPixels, percent, rems, including negative. Not auto
Gap*scene.LengthPixels or rems only, not negative. Applies to rows and columns

Boxes demonstrating padding, top and left margin, and gap

Layout ​

FieldTypeValues
Display*scene.DisplayDisplayFlex, DisplayGrid, DisplayNone
FlexDirection*scene.FlexDirectionFlexRow, FlexColumn
FlexWrap*boolTrue wraps children onto new lines
FlexGrow, FlexShrink*float320 or greater
AlignItems*scene.AlignmentAlignStart, AlignCenter, AlignEnd, AlignStretch
JustifyContent*scene.JustificationJustifyStart, JustifyCenter, JustifyEnd, JustifySpaceBetween
GridColumns*uint321 to 1024 equal columns

Three boxes in a flex row and in a flex column

Boxes of different heights aligned to start, center, end and stretched

Three boxes justified to start, center, end and with space between

Items that overflow without wrapping, and the same items wrapping onto a second line

Three boxes in a row with flex grow values 0, 1 and 3

Grids of two and four equal columns

FlexDirection overrides Display

Setting FlexDirection forces flex display, even when the same style sets Display to DisplayGrid or DisplayNone. To hide or grid a container, leave FlexDirection unset in that style.

Positioning ​

FieldTypeValues
Position*scene.PositionPositionRelative, PositionAbsolute
Inset*scene.EdgesOffsets from each edge. Pixels, percent, rems or auto, including negative

A badge positioned absolutely in the top right corner of a panel

Overflow ​

FieldTypeValues
OverflowX, OverflowY*scene.OverflowOverflowVisible, OverflowHidden, OverflowScroll

A tall box overflowing its parent, clipped, and scrollable

Color and borders ​

FieldTypeValues
Background*scene.ColorBackground color
Opacity*float320 to 1
BorderWidth*float32Applied to all four sides, 0 or greater
BorderColor*scene.ColorBorder color
CornerRadius*float32Applied to all four corners, 0 or greater
Shadows[]*scene.ShadowAt most 8

Tiles showing a background, a border, a corner radius and all three combined

Four tiles at opacity 1, 0.75, 0.5 and 0.25

scene.Shadow has a Color, a required Offset point, a Blur of 0 or greater and a Spread. Inset shadows are not available.

go
style := &scene.Style{
	Shadows: []*scene.Shadow{{
		Color:  &scene.Color{Alpha: 0.3},
		Offset: &scene.Point{Y: 4},
		Blur:   12,
	}},
}

Tiles with a blurred shadow, an offset shadow and a colored spread shadow

Text ​

These are inherited by descendants.

FieldTypeValues
TextColor*scene.ColorText color
FontSize*float32Logical pixels, 0 or greater
FontWeight*uint32100 to 900
FontFamily*stringNonempty, at most 256 bytes
Italic*boolTrue for italic
TextAlign*scene.TextAlignmentTextAlignLeft, TextAlignCenter, TextAlignRight

Left, center and right aligned text, and text properties inherited from a parent

Pointer ​

FieldTypeValues
Cursor*scene.CursorCursorArrow, CursorPointer

Released under the Apache License 2.0. The optional Zed editor component is GPL-3.0-or-later.