Instead of
type Contraints struct {
Width, Height Constraint
}
use
type Constraints struct {
Min, Max image.Point
}
which leads to simpler use. For example, the Min method is trivally replaced by
the field, and the RigidConstraints constructor is no longer a net win.
API Change. Rewrites:
gofmt -r 'gtx.Constraints.Min() -> gtx.Constraints.Min'
gofmt -r 'gtx.Constraints.Width.Min -> gtx.Constraints.Min.X'
gofmt -r 'gtx.Constraints.Height.Min -> gtx.Constraints.Min.Y'
gofmt -r 'gtx.Constraints.Height.Max -> gtx.Constraints.Max.Y'
gofmt -r 'gtx.Constraints.Width.Max -> gtx.Constraints.Max.X'
Signed-off-by: Elias Naur <mail@eliasnaur.com>
With the simplification of MacroOp, it is now possible to simplify
the Flex API to just a single Layout method, similar to List:
layout.Flex{}.Layout(gtx,
layout.Rigid(func() { ... }),
layout.Flexed(0.5, func() { ... }),
)
Signed-off-by: Elias Naur <mail@eliasnaur.com>
The ability to invoke other operation lists belongs in the new CallOp.
While we're here, make MacroOp.Add use a pointer receiver to match the
other methods.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
Overlapping layouts such as
outer := layout.Flex{}
inner := layout.Stack{}
child := inner.Rigid(gtx, ...)
outerChild := outer.Rigid(gtx, func() {
inner.Layout(gtx, child)
})
outer.Layout(gtx, outerChild)
runs but result in a wrong layout.
This change use empty StackOps to ensure that the Stack and Flex
child layout methods are called in the same scope as their Layout
methods:
outer := layout.Flex{}
inner := layout.Stack{}
outerChild := outer.Rigid(gtx, func() {
child := inner.Rigid(gtx, ...)
inner.Layout(gtx, child)
})
outer.Layout(gtx, outerChild)
Signed-off-by: Elias Naur <mail@eliasnaur.com>
With Context containing all the necessary information, separate
Init methods no longer makes much sense. Delete them and thereby
remove a source of runtime panics.
Signed-off-by: Elias Naur <mail@eliasnaur.com>