layout

package
v0.0.0-...-abd1f79 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2017 License: BSD-3-Clause Imports: 1 Imported by: 1

Documentation

Overview

Package layout provides helpers for laying out hierarchies of rectangular elements in two dimensional space.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Element

type Element interface {
	// SizeHint returns this Element's desired size and whether it
	// can expand from that size in either direction.
	SizeHint() (w, h float64, flexw, flexh bool)

	// SetLayout sets this Element's layout relative to its parent
	// and, if this Element is a container, recursively lays out
	// this Element's children.
	//
	// w and h may be smaller than SizeHint() if the space is
	// constrained. They may also be larger, even if the element
	// isn't flexible, in which case the Element will position
	// itself within the assigned size using some gravity.
	//
	// TODO: Or should the parent be responsible for gravity if it
	// allocates too much space to a fixed element?
	//
	// TODO: Since an Element doesn't know its parent, it's
	// difficult to turn local coordinates into absolute
	// coordinates. These should either be absolute coordinates,
	// or Element should have a parent and it should be easy to
	// get absolute coordinates.
	SetLayout(x, y, w, h float64)

	// Layout returns this Element's layout.
	Layout() (x, y, w, h float64)
}

An Element is a rectangular feature in a layout.

type Grid

type Grid struct {
	// contains filtered or unexported fields
}

Grid lays out elements in a two dimensional table. Each child is assigned to a cell in the table and may optionally span multiple rows and/or columns.

func (*Grid) Add

func (g *Grid) Add(e Element, x, y, colSpan, rowSpan int)

Add adds Element e to Grid g, spanning cells (x,y) up to but not including (x+colSpan, y+colSpan).

func (*Grid) Children

func (g *Grid) Children() []Element

func (*Grid) Layout

func (g *Grid) Layout() (x, y, w, h float64)

func (*Grid) SetLayout

func (g *Grid) SetLayout(x, y, w, h float64)

func (*Grid) SizeHint

func (g *Grid) SizeHint() (w, h float64, flexw, flexh bool)

type Group

type Group interface {
	Element

	// Children returns the child Elements laid out by this Group.
	Children() []Element
}

A Group is an Element that manages the layout of child Elements.

type Leaf

type Leaf struct {
	// contains filtered or unexported fields
}

Leaf is a leaf in a layout hierarchy. It is meant for embedding: it partially implements Element, leaving SizeHint to the embedding type.

func (*Leaf) Layout

func (l *Leaf) Layout() (x, y, w, h float64)

func (*Leaf) SetLayout

func (l *Leaf) SetLayout(x, y, w, h float64)

Jump to

Keyboard shortcuts

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