~whereswaldon/gio-x

1b330a12ccbeff8c4a09eb1c235eb7a66224d722 — Chris Waldon 1 year, 10 months ago 1978dde
outlay: make gridwrap return correct baseline

The GridWrap type previously returned a zero baseline unconditionally,
which made it impossible to align content outside of the grid to
the first line of text within the grid. Now the baseline is set
to the baseline of the first widget laid out within the grid.

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
1 files changed, 5 insertions(+), 2 deletions(-)

M outlay/grid.go
M outlay/grid.go => outlay/grid.go +5 -2
@@ 38,7 38,7 @@ type wrapData struct {
func (g GridWrap) Layout(gtx layout.Context, num int, el GridElement) layout.Dimensions {
	defer op.Offset(f32.Point{}).Push(gtx.Ops).Pop()
	csMax := gtx.Constraints.Max
	var mainSize, crossSize, mainPos, crossPos, base int
	var mainSize, crossSize, mainPos, crossPos, base, firstBase int
	gtx.Constraints.Min = image.Point{}
	mainCs := axisMain(g.Axis, csMax)
	crossCs := axisCross(g.Axis, gtx.Constraints.Max)


@@ 47,6 47,9 @@ func (g GridWrap) Layout(gtx layout.Context, num int, el GridElement) layout.Dim
	for i := 0; i < num; i++ {
		macro := op.Record(gtx.Ops)
		dims, okMain, okCross := g.place(gtx, i, el)
		if i == 0 {
			firstBase = dims.Size.Y - dims.Baseline
		}
		call := macro.Stop()
		if !okMain && !okCross {
			break


@@ 79,7 82,7 @@ func (g GridWrap) Layout(gtx layout.Context, num int, el GridElement) layout.Dim
	crossSize += crossPos
	g.placeAll(gtx.Ops, els, crossPos, base)
	sz := axisPoint(g.Axis, mainSize, crossSize)
	return layout.Dimensions{Size: sz}
	return layout.Dimensions{Size: sz, Baseline: sz.Y - firstBase}
}

func (g GridWrap) place(gtx layout.Context, i int, el GridElement) (dims layout.Dimensions, okMain, okCross bool) {