[GIO] How make all widgets in list same size?

I have some widgets in list and I want that all of them has equal size. How to do it in Gio?

MCVE(buttons in the list):

package main

import (
	"log"

	"gioui.org/app"
	"gioui.org/font/gofont"
	"gioui.org/io/system"
	"gioui.org/layout"
	"gioui.org/op"
	"gioui.org/unit"
	"gioui.org/widget"
	"gioui.org/widget/material"
)

func main() {
	go func() {
		w := app.NewWindow(app.Title("MCVE"),
			app.Size(unit.Dp(400), unit.Dp(400)))
		if err := loop(w); err != nil {
			log.Fatal(err)
		}
	}()
	app.Main()
}

func loop(w *app.Window) error {
	th := material.NewTheme(gofont.Collection())
	labels := []string{"B1", "Button2"}
	buttons := make([]widget.Clickable, len(labels))
	widgets := make([]layout.Widget, len(labels))
	var ops op.Ops
	for {
		e := <-w.Events()
		switch e := e.(type) {
		case system.DestroyEvent:
			return e.Err
		case system.FrameEvent:
			gtx := layout.NewContext(&ops, e)
			layout.Flex{Axis: layout.Vertical, Spacing: layout.SpaceAround}.Layout(gtx,
				layout.Rigid(func(gtx layout.Context) layout.Dimensions {
					return layout.Center.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
						list := &layout.List{
							Axis:      layout.Vertical,
							Alignment: layout.Middle,
						}
						for i, label := range labels {
							widgets[i] = material.Button(th, &buttons[i], label).Layout
						}
						return list.Layout(gtx, len(widgets), func(gtx layout.Context, i int) layout.Dimensions {
							return layout.UniformInset(unit.Dp(0)).Layout(gtx, widgets[i])
						})
					})
				}),
				layout.Rigid(func(gtx layout.Context) layout.Dimensions {
					return layout.Center.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
						return material.H6(th, "Info").Layout(gtx)
					})
				}),
			)
			e.Frame(gtx.Ops)
		}
	}
	return nil
}

You mean the documentation isn’t clear enough? :joy: … joking

1 Like

I was making a joke about the documentation … not you btw. I find the docs a bit frustrating

I understand jokes :stuck_out_tongue:

Well they try to provide at least something - https://gioui.org/doc/architecture

I just feel like it leaves a lot to be desired. I’m going to really dive into the library one of these days.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.