layout

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package layout provides a default layout scheme that can, but need not, be used with the ui framework.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Anchor

func Anchor() ui.Layout

Anchor returns a layout that positions elements relative to key positions of the receiver element:

  • left padding border
  • right padding border
  • top padding border
  • bottom padding border
  • horizontal center
  • vertical center

The exact positioning of a child is determined by its layout data. Individual children are positioned independently, hence two child elements could overlap.

func Fill

func Fill() ui.Layout

Fill returns a layout that positions elements within the whole bounds of the receiver element.

If the receiver element has multiple children then each one is positioned independently to take up the whole space.

func Frame

func Frame(settings ...FrameSettings) ui.Layout

Frame returns a layout that positions elements around a frame (like a picture frame). The five main sections are top,left,center,right,bottom and are distributed as follows.

 _____________
|______T______|
|   |     |   |
| L |  C  | R |
|___|_____|___|
|______B______|

func Horizontal

func Horizontal(settings ...HorizontalSettings) ui.Layout

Horizontal returns a layout that positions elements horizontally, in a sequence.

func Vertical

func Vertical(settings ...VerticalSettings) ui.Layout

Vertical returns a layout that positions elements vertically, in a sequence.

Types

type Data

type Data struct {

	// Left indicates the positioning relative to the parent's left border.
	Left opt.T[int]

	// Right indicates the positioning relative to the parent's right border.
	Right opt.T[int]

	// Top indicates the positioning relative to the parent's top border.
	Top opt.T[int]

	// Bottom indicates the positioning relative to the parent's bottom border.
	Bottom opt.T[int]

	// HorizontalCenter indicates the positioning relative to the parent's
	// horizontal center.
	HorizontalCenter opt.T[int]

	// VerticalCenter indicates the positioning relative to the parent's
	// vertical center.
	VerticalCenter opt.T[int]

	// Width specifies the desired width of the component.
	Width opt.T[int]

	// Height specifies the desired height of the component.
	Height opt.T[int]

	// GrowHorizontally indicates whether the component should occupy as much
	// space horizontally as possible.
	GrowHorizontally bool

	// GrowVertically indicates whether the component should occupy as much
	// space vertically as possible.
	GrowVertically bool

	// HorizontalAlignment indicates how a component should be aligned
	// horizontally if this cannot be determined by any other parameters.
	HorizontalAlignment HorizontalAlignment

	// VerticalAlignment indicates how a component should be aligned
	// vertically if this cannot be determined by any other parameters.
	VerticalAlignment VerticalAlignment
}

Data represents a layout configuration for a component that is added to a layout container.

func ElementData

func ElementData(element *ui.Element) Data

ElementData returns the layout data associated with the specified element. If one has not been assigned to the element or if it is of a different type then a default one is returned.

type FrameSettings added in v0.12.0

type FrameSettings struct {
	ContentSpacing ui.Spacing
}

FrameSettings contains configurations for the Frame layout.

type HorizontalAlignment

type HorizontalAlignment int8

HorizontalAlignment determines the horizontal relative positioning of child elements within a Layout or text within a component.

const (
	// HorizontalAlignmentDefault indicates that the receiver should use its
	// preferred alignment model.
	HorizontalAlignmentDefault HorizontalAlignment = iota

	// HorizontalAlignmentCenter indicates that the receiver should try and center
	// the content horizontally.
	HorizontalAlignmentCenter

	// HorizontalAlignmentLeft indicates that the receiver should try and position
	// the content to the left.
	HorizontalAlignmentLeft

	// HorizontalAlignmentRight indicates that the receiver should try and
	// position the content to the right.
	HorizontalAlignmentRight
)

type HorizontalSettings

type HorizontalSettings struct {
	ContentAlignment VerticalAlignment
	ContentSpacing   int
}

HorizontalSettings contains configurations for the Horizontal layout.

type VerticalAlignment

type VerticalAlignment int8

VerticalAlignment determines the vertical relative positioning of child elements within a Layout or text within a component.

const (
	// VerticalAlignmentDefault indicates that the receiver should use its
	// preferred alignment model.
	VerticalAlignmentDefault VerticalAlignment = iota

	// VerticalAlignmentCenter indicates that the receiver should try and center
	// the content vertically.
	VerticalAlignmentCenter

	// VerticalAlignmentTop indicates that the receiver should try and position
	// the content to the top.
	VerticalAlignmentTop

	// VerticalAlignmentBottom indicates that the receiver should try and position
	// the content to the bottom.
	VerticalAlignmentBottom
)

type VerticalSettings

type VerticalSettings struct {
	ContentAlignment HorizontalAlignment
	ContentSpacing   int
}

VerticalSettings contains configurations for the Vertical layout.

Jump to

Keyboard shortcuts

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