~eliasnaur/gio

896f5a77dd20d42f4bd6ec1044473d2fbadcbd1e — Elias Naur 1 year, 4 months ago dbe15b2
ui/layout: don't stretch Align child

Let the caller decide whether the constraints should be stretched.

Also unexport Constraint (not Constraints) methods, they weren't
pulling their weight.

Finally, don't force cross axis constraint minimum to 0 in List.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2 files changed, 13 insertions(+), 16 deletions(-)

M ui/layout/layout.go
M ui/layout/list.go
M ui/layout/layout.go => ui/layout/layout.go +12 -12
@@ 43,15 43,19 @@ func (c Constraints) Constrain(p image.Point) image.Point {
}

func (c Constraints) Expand() Constraints {
	return Constraints{Width: c.Width.Expand(), Height: c.Height.Expand()}
	return Constraints{Width: c.Width.expand(), Height: c.Height.expand()}
}

func (c Constraint) Expand() Constraint {
func (c Constraints) Loose() Constraints {
	return Constraints{Width: c.Width.loose(), Height: c.Height.loose()}
}

func (c Constraint) expand() Constraint {
	return Constraint{Min: c.Max, Max: c.Max}
}

func (c Constraints) Loose() Constraints {
	return Constraints{Width: c.Width.Loose(), Height: c.Height.Loose()}
func (c Constraint) loose() Constraint {
	return Constraint{Max: c.Max}
}

func (c Constraints) Exact(width, height int) Constraints {


@@ 74,10 78,6 @@ func (c Constraints) Exact(width, height int) Constraints {
	return c
}

func (c Constraint) Loose() Constraint {
	return Constraint{Max: c.Max}
}

// ExactConstraints returns the rigid constraints that represents the
// given dimensions.
func ExactConstraints(size image.Point) Constraints {


@@ 177,11 177,11 @@ func (a *Align) End(dims Dimens) Dimens {
	ops := a.ops
	block := ops.End()
	sz := dims.Size
	if a.cs.Width.Max != ui.Inf {
		sz.X = a.cs.Width.Max
	if sz.X < a.cs.Width.Min {
		sz.X = a.cs.Width.Min
	}
	if a.cs.Height.Max != ui.Inf {
		sz.Y = a.cs.Height.Max
	if sz.Y < a.cs.Height.Min {
		sz.Y = a.cs.Height.Min
	}
	var p image.Point
	switch a.Alignment {

M ui/layout/list.go => ui/layout/list.go +1 -4
@@ 217,11 217,8 @@ func (l *List) Layout() Dimens {

func (l *List) crossConstraintChild(cs Constraints) Constraint {
	c := axisCrossConstraint(l.Axis, cs)
	switch l.CrossAxisAlignment {
	case Stretch:
	if l.CrossAxisAlignment == Stretch {
		c.Min = c.Max
	default:
		c.Min = 0
	}
	return c
}