~whereswaldon/gio-x

fd429bc740d454fef684d54a7ba2b60c42a6c2e8 — Chris Waldon 1 year, 8 months ago 47aed33 grid
component: fix first frame in grid

This commit fixes a bug that would layout out the grid with zero
max constraints on the first frame, resulting in an empty grid.

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

M component/grid.go
M component/grid.go => component/grid.go +14 -14
@@ 70,34 70,33 @@ func (t TableStyle) Layout(gtx layout.Context, rows, cols int, dimensioner outla

// Layout will draw a grid, using fixed column widths and row height.
func (g GridStyle) Layout(gtx layout.Context, rows, cols int, dimensioner outlay.Dimensioner, cellFunc outlay.Cell) layout.Dimensions {

	// Determine how much space the scrollbars occupy when present.
	hBarWidth := gtx.Px(g.HScrollbarStyle.Width(gtx.Metric))
	vBarWidth := gtx.Px(g.VScrollbarStyle.Width(gtx.Metric))

	// Calculate column widths in pixels. Width is sum of widths.
	totalWidth := g.State.Horizontal.Length
	totalHeight := g.State.Vertical.Length
	rowHeight := dimensioner(layout.Vertical, 0, gtx.Constraints.Max.Y)

	displayWidth := totalWidth
	// Reserve space for the scrollbars using the gtx constraints.
	if g.AnchorStrategy == material.Occupy {
		gtx.Constraints.Max.X -= vBarWidth
		gtx.Constraints.Max.Y -= hBarWidth
	}

	// Make the scroll bar stick to the grid.
	if gtx.Constraints.Max.X > displayWidth {
		gtx.Constraints.Max.X = displayWidth
	}
	gtx.Constraints.Min = gtx.Constraints.Max

	defer pointer.PassOp{}.Push(gtx.Ops).Pop()

	// Draw grid.
	dim := g.State.Grid.Layout(gtx, rows, cols, dimensioner, cellFunc)

	// Calculate column widths in pixels. Width is sum of widths.
	totalWidth := g.State.Horizontal.Length
	totalHeight := g.State.Vertical.Length
	rowHeight := dimensioner(layout.Vertical, 0, gtx.Constraints.Max.Y)

	// Make the scroll bar stick to the grid.
	if gtx.Constraints.Max.X > dim.Size.X {
		gtx.Constraints.Max.X = dim.Size.X
		if g.AnchorStrategy == material.Occupy {
			gtx.Constraints.Max.X += vBarWidth
		}
	}

	// Get horizontal scroll info.
	delta := g.HScrollbarStyle.Scrollbar.ScrollDistance()
	if delta != 0 {


@@ 148,5 147,6 @@ func (g GridStyle) Layout(gtx layout.Context, rows, cols int, dimensioner outlay
		dim.Size.Y += hBarWidth
	}
	dim.Size.Y += rowHeight

	return dim
}