constraint

– import “gomatcha.io/matcha/layout/constraint”

Package constraint implements a constraint-based layout system. See http://gomatcha.io/guide/layout/ for more details.

type Anchor

type Anchor struct {
}

Anchor represents a float64 value that is materialized during the layout phase.

func Const

func Const(f float64) *Anchor

Const returns a new Anchor with a constant value f.

func Notifier

func Notifier(n comm.Float64Notifier) *Anchor

Notifier returns a new Anchor whose value is equal to n.Value().

func (*Anchor) Add

func (a *Anchor) Add(v float64) *Anchor

Add returns a new Anchor that is offset by v.

func (*Anchor) Mul

func (a *Anchor) Mul(v float64) *Anchor

Mul returns a new anchor that is multiplied by v.

type Guide

type Guide struct {
}

Guide represents a layout.Guide that is materialized during the layout phase.

func (*Guide) Bottom

func (g *Guide) Bottom() *Anchor

Bottom returns the maximum Y coordinate as an Anchor.

func (*Guide) CenterX

func (g *Guide) CenterX() *Anchor

CenterX returns the center of g along the X axis as an Anchor.

func (*Guide) CenterY

func (g *Guide) CenterY() *Anchor

CenterY returns the center of g along the Y axis as an Anchor.

func (*Guide) Height

func (g *Guide) Height() *Anchor

Height returns the height of g as an Anchor.

func (*Guide) Left

func (g *Guide) Left() *Anchor

Left returns the minimum X coordinate as an Anchor.

func (*Guide) Right

func (g *Guide) Right() *Anchor

Right returns the maximum X coordinate as an Anchor.

func (*Guide) Solve

func (g *Guide) Solve(solveFunc func(*Solver))

Solve immediately calls solveFunc to update the constraints for g.

func (*Guide) Top

func (g *Guide) Top() *Anchor

Top returns the minimum Y coordinate as an Anchor.

func (*Guide) Width

func (g *Guide) Width() *Anchor

Width returns the width of g as an Anchor.

type Layouter

type Layouter struct {
	// Guide represents the size of the view that the layouter is attached to. By default, Guide is the same size as MinGuide.
	Guide
}

func (*Layouter) Add

func (l *Layouter) Add(v view.View, solveFunc func(*Solver)) *Guide

Add immediately calls solveFunc to generate the constraints for v. These constraints are solved by l during the layout phase. A corresponding guide is returned, which can be used to position other views or reposition v. If the view is not fully constrained it will try to match the MinGuide in dimension and center. If the child view is not fully constrained it will try to match the parent in center.

func (*Layouter) DebugStrings

func (l *Layouter) DebugStrings() (string, []string)

DebugStrings must be called after Layout()…

func (*Layouter) Layout

func (l *Layouter) Layout(ctx layout.Context) (layout.Guide, []layout.Guide)

Layout evaluates the constraints and returns the calculated guide and child guides.

func (*Layouter) MaxGuide

func (l *Layouter) MaxGuide() *Guide

MaxGuide returns a guide representing the largest allowed size for the view.

func (*Layouter) MinGuide

func (l *Layouter) MinGuide() *Guide

MinGuide returns a guide representing the smallest allowed size for the view.

func (*Layouter) Notify

func (l *Layouter) Notify(f func()) comm.Id

Notify calls f anytime a Notifier anchor changes. Other updates to the layouter, such as adding guides will not trigger the notification.

func (*Layouter) Solve

func (l *Layouter) Solve(solveFunc func(*Solver))

func (*Layouter) Unnotify

func (l *Layouter) Unnotify(id comm.Id)

Unnotify stops notifications for id.

func (*Layouter) Views

func (l *Layouter) Views() []view.View

View returns a list of all views added to l.

type Solver

type Solver struct {
}

Solver is a list of constraints to be applied to a view.

func (*Solver) Bottom

func (s *Solver) Bottom(v float64)

func (*Solver) BottomEqual

func (s *Solver) BottomEqual(a *Anchor)

func (*Solver) BottomGreater

func (s *Solver) BottomGreater(a *Anchor)

func (*Solver) BottomLess

func (s *Solver) BottomLess(a *Anchor)

func (*Solver) CenterX

func (s *Solver) CenterX(v float64)

func (*Solver) CenterXEqual

func (s *Solver) CenterXEqual(a *Anchor)

func (*Solver) CenterXGreater

func (s *Solver) CenterXGreater(a *Anchor)

func (*Solver) CenterXLess

func (s *Solver) CenterXLess(a *Anchor)

func (*Solver) CenterY

func (s *Solver) CenterY(v float64)

func (*Solver) CenterYEqual

func (s *Solver) CenterYEqual(a *Anchor)

func (*Solver) CenterYGreater

func (s *Solver) CenterYGreater(a *Anchor)

func (*Solver) CenterYLess

func (s *Solver) CenterYLess(a *Anchor)

func (*Solver) Debug

func (s *Solver) Debug()

Debug adds debug logging for the solver.

func (*Solver) Height

func (s *Solver) Height(v float64)

func (*Solver) HeightEqual

func (s *Solver) HeightEqual(a *Anchor)

func (*Solver) HeightGreater

func (s *Solver) HeightGreater(a *Anchor)

func (*Solver) HeightLess

func (s *Solver) HeightLess(a *Anchor)

func (*Solver) Left

func (s *Solver) Left(v float64)

func (*Solver) LeftEqual

func (s *Solver) LeftEqual(a *Anchor)

func (*Solver) LeftGreater

func (s *Solver) LeftGreater(a *Anchor)

func (*Solver) LeftLess

func (s *Solver) LeftLess(a *Anchor)

func (*Solver) Right

func (s *Solver) Right(v float64)

func (*Solver) RightEqual

func (s *Solver) RightEqual(a *Anchor)

func (*Solver) RightGreater

func (s *Solver) RightGreater(a *Anchor)

func (*Solver) RightLess

func (s *Solver) RightLess(a *Anchor)

func (*Solver) String

func (s *Solver) String() string

func (*Solver) Top

func (s *Solver) Top(v float64)

func (*Solver) TopEqual

func (s *Solver) TopEqual(a *Anchor)

func (*Solver) TopGreater

func (s *Solver) TopGreater(a *Anchor)

func (*Solver) TopLess

func (s *Solver) TopLess(a *Anchor)

func (*Solver) Width

func (s *Solver) Width(v float64)

func (*Solver) WidthEqual

func (s *Solver) WidthEqual(a *Anchor)

func (*Solver) WidthGreater

func (s *Solver) WidthGreater(a *Anchor)

func (*Solver) WidthLess

func (s *Solver) WidthLess(a *Anchor)