styles

package
v1.0.31-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 2 Imported by: 1 module, 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Styles

type Styles struct {
	// FlexDirection is the main axis of a flex container: "row" or
	// "column".
	FlexDirection properties.FlexDirection
	// Align positions children on the flex cross axis.
	Align properties.Align
	// Justify distributes children on the flex main axis.
	Justify properties.Justify
	// Wrap controls whether children continue onto a new line when
	// they overflow the main axis. Unset defaults to wrapping on Row
	// containers and not wrapping on Stack (column) containers.
	Wrap properties.Wrap
	// Gap is the spacing between flex children, and between wrapped
	// lines.
	Gap properties.Gap
	// RowGap is the spacing between a grid's rows; Gap when 0.
	RowGap properties.Gap
	// GridColumns and GridRows size a grid's tracks (Display:
	// DisplayGrid), as CSS's grid-template-columns: "200 1fr 2fr",
	// "repeat(auto-fill, minmax(220, 1fr))". Rows past GridRows are
	// auto.
	GridColumns properties.GridTracks
	GridRows    properties.GridTracks
	// GridColumn and GridRow place a grid's child: Span(n), or
	// Cell(start, span) from a 1-based track.
	GridColumn properties.GridSpan
	GridRow    properties.GridSpan
	// FlexGrow is the share of spare space a flex child takes.
	FlexGrow properties.FlexGrow
	// Width and Height size the element: 0 hugs content, -1 expands,
	// >0 is fixed.
	Width  properties.Width
	Height properties.Height
	// WidthPct and HeightPct size the element as a percentage of the
	// available space and take precedence over Width and Height.
	WidthPct  properties.WidthPct
	HeightPct properties.HeightPct
	// Padding is the space between the edge and the content.
	Padding properties.Padding
	// Margin is the space outside the painted area.
	Margin properties.Margin
	// Background is the fill color behind the content.
	Background properties.Background
	// BackgroundImage is an image behind the content, scaled with
	// BackgroundFit.
	BackgroundImage properties.BackgroundImage
	BackgroundFit   properties.BackgroundFit
	// BorderWidth and BorderColor draw a border around the element.
	BorderWidth properties.BorderWidth
	BorderColor properties.BorderColor
	// BorderRadius rounds the background corners.
	BorderRadius properties.BorderRadius
	// BorderRadii rounds each corner separately and takes precedence
	// over BorderRadius when any corner is set.
	BorderRadii properties.Corners
	// BackgroundGradient paints a linear gradient above Background
	// (see properties.Linear).
	BackgroundGradient properties.BackgroundGradient
	// Opacity is the element transparency in the range 0-1.
	Opacity properties.Opacity
	// Color is the text color.
	Color properties.Color
	// FontSize is the text size in sp.
	FontSize properties.FontSize
	// FontWeight is the text weight.
	FontWeight properties.FontWeight
	// TextAlign aligns text within its box.
	TextAlign properties.TextAlign
	// LineHeight is the distance between text baselines.
	LineHeight properties.LineHeight
	// MaxLines truncates text after the given number of lines.
	MaxLines properties.MaxLines
	// TabWidth is the distance between tab stops in text, in columns
	// (default 4).
	TabWidth properties.TabWidth
	// Cursor is the cursor shown while hovering.
	Cursor properties.Cursor
	// Fit controls how images scale into their box.
	Fit properties.Fit
	// Position selects static, relative or absolute placement.
	Position properties.Position
	// Top, Right, Bottom and Left offset absolutely positioned
	// elements from their parent box edges.
	Top    properties.Top
	Right  properties.Right
	Bottom properties.Bottom
	Left   properties.Left
	// ZIndex orders siblings: higher values paint above.
	ZIndex properties.ZIndex
	// MinWidth, MaxWidth, MinHeight and MaxHeight clamp the resolved
	// size.
	MinWidth  properties.MinWidth
	MaxWidth  properties.MaxWidth
	MinHeight properties.MinHeight
	MaxHeight properties.MaxHeight
	// BoxShadow paints a drop shadow behind the element.
	BoxShadow properties.BoxShadow
	// ScrollBar customizes the scrollbar a Scroll container draws.
	ScrollBar properties.ScrollBar
	// AspectRatio derives the unresized axis from the resized one.
	AspectRatio properties.AspectRatio
	// Overflow clips content to the box when set to hidden.
	Overflow properties.Overflow
	// TextDecoration decorates text.
	TextDecoration properties.TextDecoration
	// FontStyle selects normal or italic text.
	FontStyle properties.FontStyle
	// FontFamily selects the text typeface.
	FontFamily properties.FontFamily
	// TextTransform changes the capitalization of text.
	TextTransform properties.TextTransform
	// TextOverflow selects how text cut off by MaxLines ends.
	TextOverflow properties.TextOverflow
	// Transform rotates, scales or translates the painted element
	// without affecting layout.
	Transform properties.Transform
	// Display removes the element from layout when set to none.
	Display properties.Display
	// Visibility hides the element while keeping its space.
	Visibility properties.Visibility
	// Transition animates color and opacity changes between base and
	// hover styles.
	Transition properties.Transition
}

Styles is the set of CSS-like properties applied to an element. Zero values mean "unset"; elements fall back to their defaults.

Lengths (sizes, paddings, margins, gaps, radii, border widths, offsets, shadows) are in device-independent pixels (dp): they are scaled by the display's density when laid out, so a UI keeps its physical size on HiDPI screens, matching font sizes, which are in sp. Use Px to resolve a Styles value to physical pixels in custom elements.

func Merge

func Merge(base Styles, overs ...Styles) Styles

Merge overlays the non-zero values of each of overs on top of base, in order, and returns the result. It is used by components to apply defaults before user styles. Colors count as set when non-empty, so an explicit "transparent" overrides an inherited color.

func (Styles) Corners

func (s Styles) Corners() properties.Corners

Corners returns the resolved per-corner radii: BorderRadii when set, otherwise BorderRadius on every corner.

func (Styles) Px

func (s Styles) Px(m unit.Metric) Styles

Px returns s with every length resolved from dp to physical pixels through m. Sentinel values (Width/Height -1, meaning "expand") are kept. Elements call it once at the start of Layout; custom elements reading lengths from Styles should do the same:

st := e.st.Px(gtx.Metric)
size := int(st.Width)

func (Styles) With

func (s Styles) With(over ...Styles) Styles

With returns s with the non-zero values of each of over applied on top, in order - the method form of Merge:

card := base.With(styles.Styles{Background: "theme.surface"})

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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