layout

package
v0.0.0-...-8d183ef Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2019 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package layout provides a Layout system for faiface/gui.

The core of the package is the Layout interface, everything else is just implementation.

The Layouts represent a Layout, and the Mux makes them usable. The Mux basically acts as a sort of driver.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EvenSplit

func EvenSplit(elements int, width int) []int

EvenSplit is a SplitFunc used to split a space (almost) evenly among the elements. It is almost evenly because width may not be divisible by elements.

Types

type Grid

type Grid struct {
	// Rows represents the number of childs of each row.
	Rows []int
	// Background represents the background of the grid as a uniform color.
	Background color.Color
	// Gap represents the grid gap, equal on all sides.
	Gap int
	// Split represents the way the space is divided among the columns in each row.
	Split SplitFunc
	// SplitRows represents the way the space is divided among the rows.
	SplitRows SplitFunc

	Margin      int
	Border      int
	BorderColor color.Color

	// Flip represents the orientation of the grid.
	// When false, rows are spread in the Y axis and columns in the X axis.
	// When true, rows are spread in the X axis and columns in the Y axis.
	Flip bool
}

Grid represents a grid with rows and columns in each row. Each row can be a different length.

func (Grid) Intercept

func (g Grid) Intercept(env gui.Env) gui.Env

func (Grid) Lay

func (g Grid) Lay(bounds image.Rectangle) []image.Rectangle

type Intercepter

type Intercepter interface {
	Intercept(gui.Env) gui.Env
}

Intercepter represents an element that can interact with Envs. An Intercepter can modify Events, stop them or emit arbitrary ones. It can also put itself in the draw pipeline, for throttling very expensive draw calls for example.

type Layout

type Layout interface {
	Lay(image.Rectangle) []image.Rectangle
	Intercepter
}

Layout represents any graphical layout

Lay represents the way to divide space among your childs. It takes a parameter of how much space is available, and returns where exactly to put its childs.

Intercept transforms an Env channel to another. This way the Layout can emit its own Events, re-emit previous ones, or even stop an event from propagating, think win.MoScroll. It can be a no-op.

type Mux

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

Mux can be used to multiplex an Env, let's call it a root Env. Mux implements a way to create multiple virtual Envs that all interact with the root Env. They receive the same events apart from gui.Resize, and their draw functions get redirected to the root Env.

All gui.Resize events are instead modified according to the underlying Layout. The master Env gets the original gui.Resize events.

func NewMux

func NewMux(ev gui.Env, envs []*gui.Env, l Layout) (mux *Mux, master gui.Env)

NewMux should only be used internally by Layouts. It has mostly the same behaviour as gui.Mux, except for its use of an underlying Layout for modifying the gui.Resize events sent to the childs.

func (*Mux) Layout

func (mux *Mux) Layout() Layout

Layout returns the underlying Layout of the Mux.

type RedrawIntercepter

type RedrawIntercepter struct {
	Redraw func(draw.Image, image.Rectangle)
}

RedrawIntercepter is a basic Intercepter, it is meant for use in simple Layouts that only need to redraw themselves.

func (RedrawIntercepter) Intercept

func (ri RedrawIntercepter) Intercept(env gui.Env) gui.Env

Intercept implements Intercepter

type Scroller

type Scroller struct {
	Background  color.Color
	Length      int
	ChildHeight int
	Offset      int
	Gap         int
	Vertical    bool
}

func (*Scroller) Intercept

func (s *Scroller) Intercept(env gui.Env) gui.Env

func (Scroller) Lay

func (s Scroller) Lay(bounds image.Rectangle) []image.Rectangle

type SplitFunc

type SplitFunc func(elements int, space int) []int

SplitFunc represents a way to split a space among a number of elements. The length of the returned slice must be equal to the number of elements. The sum of all elements of the returned slice must be eqal to the space.

Jump to

Keyboard shortcuts

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