~eliasnaur/gio

0d49eb3f4b31b9a91b23526bd0c2b0e67ea709b4 — Elias Naur 1 year, 4 months ago 5c3398f
ui/layout: drop CrossAxisAlignment value Stretch

It doesn't carry its own weight; client can just as easily adjust
the Constraints themselves.

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

M ui/layout/flex.go
M ui/layout/list.go
M ui/layout/flex.go => ui/layout/flex.go +2 -14
@@ 43,7 43,6 @@ const (
	SpaceEvenly

	Baseline CrossAxisAlignment = iota
	Stretch
)

const (


@@ 85,7 84,7 @@ func (f *Flex) Rigid() Constraints {
	if mainc.Max != ui.Inf {
		mainMax -= f.size
	}
	return axisConstraints(f.Axis, Constraint{Max: mainMax}, f.crossConstraintChild(f.cs))
	return axisConstraints(f.Axis, Constraint{Max: mainMax}, axisCrossConstraint(f.Axis, f.cs))
}

func (f *Flex) Flexible(weight float32) Constraints {


@@ 101,7 100,7 @@ func (f *Flex) Flexible(weight float32) Constraints {
		}
	}
	submainc := Constraint{Max: flexSize}
	return axisConstraints(f.Axis, submainc, f.crossConstraintChild(f.cs))
	return axisConstraints(f.Axis, submainc, axisCrossConstraint(f.Axis, f.cs))
}

func (f *Flex) End(dims Dimens) FlexChild {


@@ 235,17 234,6 @@ func axisCrossConstraint(a Axis, cs Constraints) Constraint {
	}
}

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

func axisConstraints(a Axis, mainc, crossc Constraint) Constraints {
	if a == Horizontal {
		return Constraints{mainc, crossc}

M ui/layout/list.go => ui/layout/list.go +1 -9
@@ 113,7 113,7 @@ func (l *List) Index() int {

// Constraints is the constraints for the current element.
func (l *List) Constraints() Constraints {
	return axisConstraints(l.Axis, Constraint{Max: ui.Inf}, l.crossConstraintChild(l.cs))
	return axisConstraints(l.Axis, Constraint{Max: ui.Inf}, axisCrossConstraint(l.Axis, l.cs))
}

func (l *List) More() bool {


@@ 243,11 243,3 @@ func (l *List) Layout() Dimens {
	block.Add(ops)
	return Dimens{Size: dims}
}

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