Grid

Grid layout puts all child containers in an even grid, wrapping each row based on the number of columns.

preview

 1package main
 2
 3import (
 4	"image/color"
 5	"github.com/ebitenui/ebitenui"
 6	"github.com/ebitenui/ebitenui/image"
 7	"github.com/ebitenui/ebitenui/widget"
 8	"github.com/hajimehoshi/ebiten/v2"
 9	"golang.org/x/image/colornames"
10	"golang.org/x/image/colornames"
11)
12
13type Game struct {
14	ui *ebitenui.UI
15}
16
17func NewGame() *Game {
18	root := widget.NewContainer(
19		widget.ContainerOpts.BackgroundImage(
20			image.NewNineSliceColor(colornames.Gainsboro),
21		),
22		widget.ContainerOpts.Layout(widget.NewGridLayout(
23			widget.GridLayoutOpts.Columns(5),
24			widget.GridLayoutOpts.DefaultStretch(true, true),
25			widget.GridLayoutOpts.Padding(widget.NewInsetsSimple(25)),
26			widget.GridLayoutOpts.Spacing(5, 5),
27		)),
28	)
29	colors := []color.Color{
30		colornames.Indianred,
31		colornames.Goldenrod,
32		colornames.Steelblue,
33		colornames.Mediumseagreen,
34		colornames.Darkslategray,
35	}
36	for y := 0; y < 5; y++ {
37		for x := 0; x < 5; x++ {
38			child := widget.NewContainer(
39				widget.ContainerOpts.BackgroundImage(
40					image.NewNineSliceColor(colors[(x+y)%len(colors)]),
41				),
42				widget.ContainerOpts.WidgetOpts(
43					widget.WidgetOpts.LayoutData(widget.GridLayoutData{}),
44					widget.WidgetOpts.MinSize(16, 16),
45				),
46				widget.ContainerOpts.Layout(widget.NewAnchorLayout()),
47			)
48			root.AddChild(child)
49		}
50	}
51
52	return &Game{
53		ui: &ebitenui.UI{Container: root},
54	}
55}
56
57func (g *Game) Update() error {
58	g.ui.Update()
59	return nil
60}
61
62func (g *Game) Draw(screen *ebiten.Image) {
63	g.ui.Draw(screen)
64}
65
66func (g *Game) Layout(w, h int) (int, int) {
67	return w, h
68}
69
70func main() {
71	ebiten.SetWindowSize(480, 320)
72	ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
73	if err := ebiten.RunGame(NewGame()); err != nil {
74		panic(err)
75	}
76}

Layout options

Columns

Responsible for wrapping cells beyond a given number.

Stretch:
1root := widget.NewContainer(
2	widget.ContainerOpts.BackgroundImage(
3		image.NewNineSliceColor(colornames.Gainsboro),
4	),
5	widget.ContainerOpts.Layout(widget.NewGridLayout(
6		widget.GridLayoutOpts.Columns(1),
7	)),
8)

all

 1package main
 2
 3import (
 4	"image/color"
 5	"github.com/ebitenui/ebitenui"
 6	"github.com/ebitenui/ebitenui/image"
 7	"github.com/ebitenui/ebitenui/widget"
 8	"github.com/hajimehoshi/ebiten/v2"
 9	"golang.org/x/image/colornames"
10)
11
12type Game struct {
13	ui *ebitenui.UI
14}
15
16func NewGame() *Game {
17	root := widget.NewContainer(
18		widget.ContainerOpts.BackgroundImage(
19			image.NewNineSliceColor(colornames.Gainsboro),
20		),
21		widget.ContainerOpts.Layout(widget.NewGridLayout(
22			widget.GridLayoutOpts.Columns(1),
23		)),
24	)
25	colors := []color.Color{
26		colornames.Indianred,
27		colornames.Goldenrod,
28		colornames.Steelblue,
29		colornames.Mediumseagreen,
30		colornames.Darkslategray,
31	}
32	for i := 0; i < 5; i++ {
33		child := widget.NewContainer(
34			widget.ContainerOpts.BackgroundImage(
35				image.NewNineSliceColor(colors[i%len(colors)]),
36			),
37			widget.ContainerOpts.WidgetOpts(
38				widget.WidgetOpts.LayoutData(widget.GridLayoutData{}),
39				widget.WidgetOpts.MinSize(64, 64),
40			),
41			widget.ContainerOpts.Layout(widget.NewAnchorLayout()),
42		)
43		root.AddChild(child)
44	}
45
46	return &Game{
47		ui: &ebitenui.UI{Container: root},
48	}
49}
50
51func (g *Game) Update() error {
52	g.ui.Update()
53	return nil
54}
55
56func (g *Game) Draw(screen *ebiten.Image) {
57	g.ui.Draw(screen)
58}
59
60func (g *Game) Layout(w, h int) (int, int) {
61	return w, h
62}
63
64func main() {
65	ebiten.SetWindowSize(480, 320)
66	ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
67	if err := ebiten.RunGame(NewGame()); err != nil {
68		panic(err)
69	}
70}
1root := widget.NewContainer(
2	widget.ContainerOpts.BackgroundImage(
3		image.NewNineSliceColor(colornames.Gainsboro),
4	),
5	widget.ContainerOpts.Layout(widget.NewGridLayout(
6		widget.GridLayoutOpts.Columns(2),
7	)),
8)

all

 1package main
 2
 3import (
 4	"image/color"
 5	"github.com/ebitenui/ebitenui"
 6	"github.com/ebitenui/ebitenui/image"
 7	"github.com/ebitenui/ebitenui/widget"
 8	"github.com/hajimehoshi/ebiten/v2"
 9	"golang.org/x/image/colornames"
10)
11
12type Game struct {
13	ui *ebitenui.UI
14}
15
16func NewGame() *Game {
17	root := widget.NewContainer(
18		widget.ContainerOpts.BackgroundImage(
19			image.NewNineSliceColor(colornames.Gainsboro),
20		),
21		widget.ContainerOpts.Layout(widget.NewGridLayout(
22			widget.GridLayoutOpts.Columns(2),
23		)),
24	)
25	colors := []color.Color{
26		colornames.Indianred,
27		colornames.Goldenrod,
28		colornames.Steelblue,
29		colornames.Mediumseagreen,
30		colornames.Darkslategray,
31	}
32	for i := 0; i < 5; i++ {
33		child := widget.NewContainer(
34			widget.ContainerOpts.BackgroundImage(
35				image.NewNineSliceColor(colors[i%len(colors)]),
36			),
37			widget.ContainerOpts.WidgetOpts(
38				widget.WidgetOpts.LayoutData(widget.GridLayoutData{}),
39				widget.WidgetOpts.MinSize(64, 64),
40			),
41			widget.ContainerOpts.Layout(widget.NewAnchorLayout()),
42		)
43		root.AddChild(child)
44	}
45
46	return &Game{
47		ui: &ebitenui.UI{Container: root},
48	}
49}
50
51func (g *Game) Update() error {
52	g.ui.Update()
53	return nil
54}
55
56func (g *Game) Draw(screen *ebiten.Image) {
57	g.ui.Draw(screen)
58}
59
60func (g *Game) Layout(w, h int) (int, int) {
61	return w, h
62}
63
64func main() {
65	ebiten.SetWindowSize(480, 320)
66	ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
67	if err := ebiten.RunGame(NewGame()); err != nil {
68		panic(err)
69	}
70}
1root := widget.NewContainer(
2	widget.ContainerOpts.BackgroundImage(
3		image.NewNineSliceColor(colornames.Gainsboro),
4	),
5	widget.ContainerOpts.Layout(widget.NewGridLayout(
6		widget.GridLayoutOpts.Columns(3),
7	)),
8)

all

 1package main
 2
 3import (
 4	"image/color"
 5	"github.com/ebitenui/ebitenui"
 6	"github.com/ebitenui/ebitenui/image"
 7	"github.com/ebitenui/ebitenui/widget"
 8	"github.com/hajimehoshi/ebiten/v2"
 9	"golang.org/x/image/colornames"
10)
11
12type Game struct {
13	ui *ebitenui.UI
14}
15
16func NewGame() *Game {
17	root := widget.NewContainer(
18		widget.ContainerOpts.BackgroundImage(
19			image.NewNineSliceColor(colornames.Gainsboro),
20		),
21		widget.ContainerOpts.Layout(widget.NewGridLayout(
22			widget.GridLayoutOpts.Columns(3),
23		)),
24	)
25	colors := []color.Color{
26		colornames.Indianred,
27		colornames.Goldenrod,
28		colornames.Steelblue,
29		colornames.Mediumseagreen,
30		colornames.Darkslategray,
31	}
32	for i := 0; i < 5; i++ {
33		child := widget.NewContainer(
34			widget.ContainerOpts.BackgroundImage(
35				image.NewNineSliceColor(colors[i%len(colors)]),
36			),
37			widget.ContainerOpts.WidgetOpts(
38				widget.WidgetOpts.LayoutData(widget.GridLayoutData{}),
39				widget.WidgetOpts.MinSize(64, 64),
40			),
41			widget.ContainerOpts.Layout(widget.NewAnchorLayout()),
42		)
43		root.AddChild(child)
44	}
45
46	return &Game{
47		ui: &ebitenui.UI{Container: root},
48	}
49}
50
51func (g *Game) Update() error {
52	g.ui.Update()
53	return nil
54}
55
56func (g *Game) Draw(screen *ebiten.Image) {
57	g.ui.Draw(screen)
58}
59
60func (g *Game) Layout(w, h int) (int, int) {
61	return w, h
62}
63
64func main() {
65	ebiten.SetWindowSize(480, 320)
66	ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
67	if err := ebiten.RunGame(NewGame()); err != nil {
68		panic(err)
69	}
70}
1root := widget.NewContainer(
2	widget.ContainerOpts.BackgroundImage(
3		image.NewNineSliceColor(colornames.Gainsboro),
4	),
5	widget.ContainerOpts.Layout(widget.NewGridLayout(
6		widget.GridLayoutOpts.Columns(4),
7	)),
8)

all

 1package main
 2
 3import (
 4	"image/color"
 5	"github.com/ebitenui/ebitenui"
 6	"github.com/ebitenui/ebitenui/image"
 7	"github.com/ebitenui/ebitenui/widget"
 8	"github.com/hajimehoshi/ebiten/v2"
 9	"golang.org/x/image/colornames"
10)
11
12type Game struct {
13	ui *ebitenui.UI
14}
15
16func NewGame() *Game {
17	root := widget.NewContainer(
18		widget.ContainerOpts.BackgroundImage(
19			image.NewNineSliceColor(colornames.Gainsboro),
20		),
21		widget.ContainerOpts.Layout(widget.NewGridLayout(
22			widget.GridLayoutOpts.Columns(4),
23		)),
24	)
25	colors := []color.Color{
26		colornames.Indianred,
27		colornames.Goldenrod,
28		colornames.Steelblue,
29		colornames.Mediumseagreen,
30		colornames.Darkslategray,
31	}
32	for i := 0; i < 5; i++ {
33		child := widget.NewContainer(
34			widget.ContainerOpts.BackgroundImage(
35				image.NewNineSliceColor(colors[i%len(colors)]),
36			),
37			widget.ContainerOpts.WidgetOpts(
38				widget.WidgetOpts.LayoutData(widget.GridLayoutData{}),
39				widget.WidgetOpts.MinSize(64, 64),
40			),
41			widget.ContainerOpts.Layout(widget.NewAnchorLayout()),
42		)
43		root.AddChild(child)
44	}
45
46	return &Game{
47		ui: &ebitenui.UI{Container: root},
48	}
49}
50
51func (g *Game) Update() error {
52	g.ui.Update()
53	return nil
54}
55
56func (g *Game) Draw(screen *ebiten.Image) {
57	g.ui.Draw(screen)
58}
59
60func (g *Game) Layout(w, h int) (int, int) {
61	return w, h
62}
63
64func main() {
65	ebiten.SetWindowSize(480, 320)
66	ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
67	if err := ebiten.RunGame(NewGame()); err != nil {
68		panic(err)
69	}
70}
1root := widget.NewContainer(
2	widget.ContainerOpts.BackgroundImage(
3		image.NewNineSliceColor(colornames.Gainsboro),
4	),
5	widget.ContainerOpts.Layout(widget.NewGridLayout(
6		widget.GridLayoutOpts.Columns(5),
7	)),
8)

all

 1package main
 2
 3import (
 4	"image/color"
 5	"github.com/ebitenui/ebitenui"
 6	"github.com/ebitenui/ebitenui/image"
 7	"github.com/ebitenui/ebitenui/widget"
 8	"github.com/hajimehoshi/ebiten/v2"
 9	"golang.org/x/image/colornames"
10)
11
12type Game struct {
13	ui *ebitenui.UI
14}
15
16func NewGame() *Game {
17	root := widget.NewContainer(
18		widget.ContainerOpts.BackgroundImage(
19			image.NewNineSliceColor(colornames.Gainsboro),
20		),
21		widget.ContainerOpts.Layout(widget.NewGridLayout(
22			widget.GridLayoutOpts.Columns(5),
23		)),
24	)
25	colors := []color.Color{
26		colornames.Indianred,
27		colornames.Goldenrod,
28		colornames.Steelblue,
29		colornames.Mediumseagreen,
30		colornames.Darkslategray,
31	}
32	for i := 0; i < 5; i++ {
33		child := widget.NewContainer(
34			widget.ContainerOpts.BackgroundImage(
35				image.NewNineSliceColor(colors[i%len(colors)]),
36			),
37			widget.ContainerOpts.WidgetOpts(
38				widget.WidgetOpts.LayoutData(widget.GridLayoutData{}),
39				widget.WidgetOpts.MinSize(64, 64),
40			),
41			widget.ContainerOpts.Layout(widget.NewAnchorLayout()),
42		)
43		root.AddChild(child)
44	}
45
46	return &Game{
47		ui: &ebitenui.UI{Container: root},
48	}
49}
50
51func (g *Game) Update() error {
52	g.ui.Update()
53	return nil
54}
55
56func (g *Game) Draw(screen *ebiten.Image) {
57	g.ui.Draw(screen)
58}
59
60func (g *Game) Layout(w, h int) (int, int) {
61	return w, h
62}
63
64func main() {
65	ebiten.SetWindowSize(480, 320)
66	ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
67	if err := ebiten.RunGame(NewGame()); err != nil {
68		panic(err)
69	}
70}
Stretch

Responsible for choosing cell coordinates across each axis that will evenly occupy the remaining space.

Stretch:
 1root := widget.NewContainer(
 2	widget.ContainerOpts.BackgroundImage(
 3		image.NewNineSliceColor(colornames.Gainsboro),
 4	),
 5	widget.ContainerOpts.Layout(widget.NewGridLayout(
 6		widget.GridLayoutOpts.Columns(5),
 7		widget.GridLayoutOpts.Stretch(
 8			[]bool{true, true, true, true, true},
 9			[]bool{true, true, true, true, true},
10		),
11	)),
12)

all

 1package main
 2
 3import (
 4	"image/color"
 5	"github.com/ebitenui/ebitenui"
 6	"github.com/ebitenui/ebitenui/image"
 7	"github.com/ebitenui/ebitenui/widget"
 8	"github.com/hajimehoshi/ebiten/v2"
 9	"golang.org/x/image/colornames"
10)
11
12type Game struct {
13	ui *ebitenui.UI
14}
15
16func NewGame() *Game {
17	root := widget.NewContainer(
18		widget.ContainerOpts.BackgroundImage(
19			image.NewNineSliceColor(colornames.Gainsboro),
20		),
21		widget.ContainerOpts.Layout(widget.NewGridLayout(
22			widget.GridLayoutOpts.Columns(5),
23			widget.GridLayoutOpts.Stretch(
24				[]bool{true, true, true, true, true},
25				[]bool{true, true, true, true, true},
26			),
27		)),
28	)
29	colors := []color.Color{
30		colornames.Indianred,
31		colornames.Goldenrod,
32		colornames.Steelblue,
33		colornames.Mediumseagreen,
34		colornames.Darkslategray,
35	}
36	for y := 0; y < 5; y++ {
37		for x := 0; x < 5; x++ {
38			child := widget.NewContainer(
39				widget.ContainerOpts.BackgroundImage(
40					image.NewNineSliceColor(colors[(x+y)%len(colors)]),
41				),
42				widget.ContainerOpts.WidgetOpts(
43					widget.WidgetOpts.LayoutData(widget.GridLayoutData{}),
44					widget.WidgetOpts.MinSize(16, 16),
45				),
46				widget.ContainerOpts.Layout(widget.NewAnchorLayout()),
47			)
48			root.AddChild(child)
49		}
50	}
51
52	return &Game{
53		ui: &ebitenui.UI{Container: root},
54	}
55}
56
57func (g *Game) Update() error {
58	g.ui.Update()
59	return nil
60}
61
62func (g *Game) Draw(screen *ebiten.Image) {
63	g.ui.Draw(screen)
64}
65
66func (g *Game) Layout(w, h int) (int, int) {
67	return w, h
68}
69
70func main() {
71	ebiten.SetWindowSize(480, 320)
72	ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
73	if err := ebiten.RunGame(NewGame()); err != nil {
74		panic(err)
75	}
76}
 1root := widget.NewContainer(
 2	widget.ContainerOpts.BackgroundImage(
 3		image.NewNineSliceColor(colornames.Gainsboro),
 4	),
 5	widget.ContainerOpts.Layout(widget.NewGridLayout(
 6		widget.GridLayoutOpts.Columns(5),
 7		widget.GridLayoutOpts.Stretch(
 8			[]bool{true, true, true, true, true},
 9			[]bool{false, false, true, false, false},
10		),
11	)),
12)

row

 1package main
 2
 3import (
 4	"image/color"
 5	"github.com/ebitenui/ebitenui"
 6	"github.com/ebitenui/ebitenui/image"
 7	"github.com/ebitenui/ebitenui/widget"
 8	"github.com/hajimehoshi/ebiten/v2"
 9	"golang.org/x/image/colornames"
10)
11
12type Game struct {
13	ui *ebitenui.UI
14}
15
16func NewGame() *Game {
17	root := widget.NewContainer(
18		widget.ContainerOpts.BackgroundImage(
19			image.NewNineSliceColor(colornames.Gainsboro),
20		),
21		widget.ContainerOpts.Layout(widget.NewGridLayout(
22			widget.GridLayoutOpts.Columns(5),
23			widget.GridLayoutOpts.Stretch(
24				[]bool{true, true, true, true, true},
25				[]bool{false, false, true, false, false},
26			),
27		)),
28	)
29	colors := []color.Color{
30		colornames.Indianred,
31		colornames.Goldenrod,
32		colornames.Steelblue,
33		colornames.Mediumseagreen,
34		colornames.Darkslategray,
35	}
36	for y := 0; y < 5; y++ {
37		for x := 0; x < 5; x++ {
38			child := widget.NewContainer(
39				widget.ContainerOpts.BackgroundImage(
40					image.NewNineSliceColor(colors[(x+y)%len(colors)]),
41				),
42				widget.ContainerOpts.WidgetOpts(
43					widget.WidgetOpts.LayoutData(widget.GridLayoutData{}),
44					widget.WidgetOpts.MinSize(16, 16),
45				),
46				widget.ContainerOpts.Layout(widget.NewAnchorLayout()),
47			)
48			root.AddChild(child)
49		}
50	}
51
52	return &Game{
53		ui: &ebitenui.UI{Container: root},
54	}
55}
56
57func (g *Game) Update() error {
58	g.ui.Update()
59	return nil
60}
61
62func (g *Game) Draw(screen *ebiten.Image) {
63	g.ui.Draw(screen)
64}
65
66func (g *Game) Layout(w, h int) (int, int) {
67	return w, h
68}
69
70func main() {
71	ebiten.SetWindowSize(480, 320)
72	ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
73	if err := ebiten.RunGame(NewGame()); err != nil {
74		panic(err)
75	}
76}
 1root := widget.NewContainer(
 2	widget.ContainerOpts.BackgroundImage(
 3		image.NewNineSliceColor(colornames.Gainsboro),
 4	),
 5	widget.ContainerOpts.Layout(widget.NewGridLayout(
 6		widget.GridLayoutOpts.Columns(5),
 7		widget.GridLayoutOpts.Stretch(
 8			[]bool{false, false, true, false, false},
 9			[]bool{true, true, true, true, true},
10		),
11	)),
12)

col

 1package main
 2
 3import (
 4	"image/color"
 5	"github.com/ebitenui/ebitenui"
 6	"github.com/ebitenui/ebitenui/image"
 7	"github.com/ebitenui/ebitenui/widget"
 8	"github.com/hajimehoshi/ebiten/v2"
 9	"golang.org/x/image/colornames"
10)
11
12type Game struct {
13	ui *ebitenui.UI
14}
15
16func NewGame() *Game {
17	root := widget.NewContainer(
18		widget.ContainerOpts.BackgroundImage(
19			image.NewNineSliceColor(colornames.Gainsboro),
20		),
21		widget.ContainerOpts.Layout(widget.NewGridLayout(
22			widget.GridLayoutOpts.Columns(5),
23			widget.GridLayoutOpts.Stretch(
24				[]bool{false, false, true, false, false},
25				[]bool{true, true, true, true, true},
26			),
27		)),
28	)
29	colors := []color.Color{
30		colornames.Indianred,
31		colornames.Goldenrod,
32		colornames.Steelblue,
33		colornames.Mediumseagreen,
34		colornames.Darkslategray,
35	}
36	for y := 0; y < 5; y++ {
37		for x := 0; x < 5; x++ {
38			child := widget.NewContainer(
39				widget.ContainerOpts.BackgroundImage(
40					image.NewNineSliceColor(colors[(x+y)%len(colors)]),
41				),
42				widget.ContainerOpts.WidgetOpts(
43					widget.WidgetOpts.LayoutData(widget.GridLayoutData{}),
44					widget.WidgetOpts.MinSize(16, 16),
45				),
46				widget.ContainerOpts.Layout(widget.NewAnchorLayout()),
47			)
48			root.AddChild(child)
49		}
50	}
51
52	return &Game{
53		ui: &ebitenui.UI{Container: root},
54	}
55}
56
57func (g *Game) Update() error {
58	g.ui.Update()
59	return nil
60}
61
62func (g *Game) Draw(screen *ebiten.Image) {
63	g.ui.Draw(screen)
64}
65
66func (g *Game) Layout(w, h int) (int, int) {
67	return w, h
68}
69
70func main() {
71	ebiten.SetWindowSize(480, 320)
72	ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
73	if err := ebiten.RunGame(NewGame()); err != nil {
74		panic(err)
75	}
76}
 1root := widget.NewContainer(
 2	widget.ContainerOpts.BackgroundImage(
 3		image.NewNineSliceColor(colornames.Gainsboro),
 4	),
 5	widget.ContainerOpts.Layout(widget.NewGridLayout(
 6		widget.GridLayoutOpts.Columns(5),
 7		widget.GridLayoutOpts.Stretch(
 8			[]bool{true, false, false, false, false},
 9			[]bool{true, false, false, false, false},
10		),
11	)),
12)

1x1

 1package main
 2
 3import (
 4	"image/color"
 5	"github.com/ebitenui/ebitenui"
 6	"github.com/ebitenui/ebitenui/image"
 7	"github.com/ebitenui/ebitenui/widget"
 8	"github.com/hajimehoshi/ebiten/v2"
 9	"golang.org/x/image/colornames"
10)
11
12type Game struct {
13	ui *ebitenui.UI
14}
15
16func NewGame() *Game {
17	root := widget.NewContainer(
18		widget.ContainerOpts.BackgroundImage(
19			image.NewNineSliceColor(colornames.Gainsboro),
20		),
21		widget.ContainerOpts.Layout(widget.NewGridLayout(
22			widget.GridLayoutOpts.Columns(5),
23			widget.GridLayoutOpts.Stretch(
24				[]bool{true, false, false, false, false},
25				[]bool{true, false, false, false, false},
26			),
27		)),
28	)
29	colors := []color.Color{
30		colornames.Indianred,
31		colornames.Goldenrod,
32		colornames.Steelblue,
33		colornames.Mediumseagreen,
34		colornames.Darkslategray,
35	}
36	for y := 0; y < 5; y++ {
37		for x := 0; x < 5; x++ {
38			child := widget.NewContainer(
39				widget.ContainerOpts.BackgroundImage(
40					image.NewNineSliceColor(colors[(x+y)%len(colors)]),
41				),
42				widget.ContainerOpts.WidgetOpts(
43					widget.WidgetOpts.LayoutData(widget.GridLayoutData{}),
44					widget.WidgetOpts.MinSize(16, 16),
45				),
46				widget.ContainerOpts.Layout(widget.NewAnchorLayout()),
47			)
48			root.AddChild(child)
49		}
50	}
51
52	return &Game{
53		ui: &ebitenui.UI{Container: root},
54	}
55}
56
57func (g *Game) Update() error {
58	g.ui.Update()
59	return nil
60}
61
62func (g *Game) Draw(screen *ebiten.Image) {
63	g.ui.Draw(screen)
64}
65
66func (g *Game) Layout(w, h int) (int, int) {
67	return w, h
68}
69
70func main() {
71	ebiten.SetWindowSize(480, 320)
72	ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
73	if err := ebiten.RunGame(NewGame()); err != nil {
74		panic(err)
75	}
76}
 1root := widget.NewContainer(
 2	widget.ContainerOpts.BackgroundImage(
 3		image.NewNineSliceColor(colornames.Gainsboro),
 4	),
 5	widget.ContainerOpts.Layout(widget.NewGridLayout(
 6		widget.GridLayoutOpts.Columns(5),
 7		widget.GridLayoutOpts.Stretch(
 8			[]bool{false, false, true, false, false},
 9			[]bool{false, false, true, false, false},
10		),
11	)),
12)

3x3

 1package main
 2
 3import (
 4	"image/color"
 5	"github.com/ebitenui/ebitenui"
 6	"github.com/ebitenui/ebitenui/image"
 7	"github.com/ebitenui/ebitenui/widget"
 8	"github.com/hajimehoshi/ebiten/v2"
 9	"golang.org/x/image/colornames"
10)
11
12type Game struct {
13	ui *ebitenui.UI
14}
15
16func NewGame() *Game {
17	root := widget.NewContainer(
18		widget.ContainerOpts.BackgroundImage(
19			image.NewNineSliceColor(colornames.Gainsboro),
20		),
21		widget.ContainerOpts.Layout(widget.NewGridLayout(
22			widget.GridLayoutOpts.Columns(5),
23			widget.GridLayoutOpts.Stretch(
24				[]bool{false, false, true, false, false},
25				[]bool{false, false, true, false, false},
26			),
27		)),
28	)
29	colors := []color.Color{
30		colornames.Indianred,
31		colornames.Goldenrod,
32		colornames.Steelblue,
33		colornames.Mediumseagreen,
34		colornames.Darkslategray,
35	}
36	for y := 0; y < 5; y++ {
37		for x := 0; x < 5; x++ {
38			child := widget.NewContainer(
39				widget.ContainerOpts.BackgroundImage(
40					image.NewNineSliceColor(colors[(x+y)%len(colors)]),
41				),
42				widget.ContainerOpts.WidgetOpts(
43					widget.WidgetOpts.LayoutData(widget.GridLayoutData{}),
44					widget.WidgetOpts.MinSize(16, 16),
45				),
46				widget.ContainerOpts.Layout(widget.NewAnchorLayout()),
47			)
48			root.AddChild(child)
49		}
50	}
51
52	return &Game{
53		ui: &ebitenui.UI{Container: root},
54	}
55}
56
57func (g *Game) Update() error {
58	g.ui.Update()
59	return nil
60}
61
62func (g *Game) Draw(screen *ebiten.Image) {
63	g.ui.Draw(screen)
64}
65
66func (g *Game) Layout(w, h int) (int, int) {
67	return w, h
68}
69
70func main() {
71	ebiten.SetWindowSize(480, 320)
72	ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
73	if err := ebiten.RunGame(NewGame()); err != nil {
74		panic(err)
75	}
76}
 1root := widget.NewContainer(
 2	widget.ContainerOpts.BackgroundImage(
 3		image.NewNineSliceColor(colornames.Gainsboro),
 4	),
 5	widget.ContainerOpts.Layout(widget.NewGridLayout(
 6		widget.GridLayoutOpts.Columns(5),
 7		widget.GridLayoutOpts.Stretch(
 8			[]bool{false, false, false, false, true},
 9			[]bool{false, false, false, false, true},
10		),
11	)),
12)

5x5

 1package main
 2
 3import (
 4	"image/color"
 5	"github.com/ebitenui/ebitenui"
 6	"github.com/ebitenui/ebitenui/image"
 7	"github.com/ebitenui/ebitenui/widget"
 8	"github.com/hajimehoshi/ebiten/v2"
 9	"golang.org/x/image/colornames"
10)
11
12type Game struct {
13	ui *ebitenui.UI
14}
15
16func NewGame() *Game {
17	root := widget.NewContainer(
18		widget.ContainerOpts.BackgroundImage(
19			image.NewNineSliceColor(colornames.Gainsboro),
20		),
21		widget.ContainerOpts.Layout(widget.NewGridLayout(
22			widget.GridLayoutOpts.Columns(5),
23			widget.GridLayoutOpts.Stretch(
24				[]bool{false, false, false, false, true},
25				[]bool{false, false, false, false, true},
26			),
27		)),
28	)
29	colors := []color.Color{
30		colornames.Indianred,
31		colornames.Goldenrod,
32		colornames.Steelblue,
33		colornames.Mediumseagreen,
34		colornames.Darkslategray,
35	}
36	for y := 0; y < 5; y++ {
37		for x := 0; x < 5; x++ {
38			child := widget.NewContainer(
39				widget.ContainerOpts.BackgroundImage(
40					image.NewNineSliceColor(colors[(x+y)%len(colors)]),
41				),
42				widget.ContainerOpts.WidgetOpts(
43					widget.WidgetOpts.LayoutData(widget.GridLayoutData{}),
44					widget.WidgetOpts.MinSize(16, 16),
45				),
46				widget.ContainerOpts.Layout(widget.NewAnchorLayout()),
47			)
48			root.AddChild(child)
49		}
50	}
51
52	return &Game{
53		ui: &ebitenui.UI{Container: root},
54	}
55}
56
57func (g *Game) Update() error {
58	g.ui.Update()
59	return nil
60}
61
62func (g *Game) Draw(screen *ebiten.Image) {
63	g.ui.Draw(screen)
64}
65
66func (g *Game) Layout(w, h int) (int, int) {
67	return w, h
68}
69
70func main() {
71	ebiten.SetWindowSize(480, 320)
72	ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
73	if err := ebiten.RunGame(NewGame()); err != nil {
74		panic(err)
75	}
76}
 1root := widget.NewContainer(
 2	widget.ContainerOpts.BackgroundImage(
 3		image.NewNineSliceColor(colornames.Gainsboro),
 4	),
 5	widget.ContainerOpts.Layout(widget.NewGridLayout(
 6		widget.GridLayoutOpts.Columns(5),
 7		widget.GridLayoutOpts.Stretch(
 8			[]bool{false, true, true, true, false},
 9			[]bool{false, false, true, false, false},
10		),
11	)),
12)

234x3

 1package main
 2
 3import (
 4	"image/color"
 5	"github.com/ebitenui/ebitenui"
 6	"github.com/ebitenui/ebitenui/image"
 7	"github.com/ebitenui/ebitenui/widget"
 8	"github.com/hajimehoshi/ebiten/v2"
 9	"golang.org/x/image/colornames"
10)
11
12type Game struct {
13	ui *ebitenui.UI
14}
15
16func NewGame() *Game {
17	root := widget.NewContainer(
18		widget.ContainerOpts.BackgroundImage(
19			image.NewNineSliceColor(colornames.Gainsboro),
20		),
21		widget.ContainerOpts.Layout(widget.NewGridLayout(
22			widget.GridLayoutOpts.Columns(5),
23			widget.GridLayoutOpts.Stretch(
24				[]bool{false, true, true, true, false},
25				[]bool{false, false, true, false, false},
26			),
27		)),
28	)
29	colors := []color.Color{
30		colornames.Indianred,
31		colornames.Goldenrod,
32		colornames.Steelblue,
33		colornames.Mediumseagreen,
34		colornames.Darkslategray,
35	}
36	for y := 0; y < 5; y++ {
37		for x := 0; x < 5; x++ {
38			child := widget.NewContainer(
39				widget.ContainerOpts.BackgroundImage(
40					image.NewNineSliceColor(colors[(x+y)%len(colors)]),
41				),
42				widget.ContainerOpts.WidgetOpts(
43					widget.WidgetOpts.LayoutData(widget.GridLayoutData{}),
44					widget.WidgetOpts.MinSize(16, 16),
45				),
46				widget.ContainerOpts.Layout(widget.NewAnchorLayout()),
47			)
48			root.AddChild(child)
49		}
50	}
51
52	return &Game{
53		ui: &ebitenui.UI{Container: root},
54	}
55}
56
57func (g *Game) Update() error {
58	g.ui.Update()
59	return nil
60}
61
62func (g *Game) Draw(screen *ebiten.Image) {
63	g.ui.Draw(screen)
64}
65
66func (g *Game) Layout(w, h int) (int, int) {
67	return w, h
68}
69
70func main() {
71	ebiten.SetWindowSize(480, 320)
72	ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
73	if err := ebiten.RunGame(NewGame()); err != nil {
74		panic(err)
75	}
76}
 1root := widget.NewContainer(
 2	widget.ContainerOpts.BackgroundImage(
 3		image.NewNineSliceColor(colornames.Gainsboro),
 4	),
 5	widget.ContainerOpts.Layout(widget.NewGridLayout(
 6		widget.GridLayoutOpts.Columns(5),
 7		widget.GridLayoutOpts.Stretch(
 8			[]bool{false, false, true, false, false},
 9			[]bool{false, true, true, true, false},
10		),
11	)),
12)

3x234

 1package main
 2
 3import (
 4	"image/color"
 5	"github.com/ebitenui/ebitenui"
 6	"github.com/ebitenui/ebitenui/image"
 7	"github.com/ebitenui/ebitenui/widget"
 8	"github.com/hajimehoshi/ebiten/v2"
 9	"golang.org/x/image/colornames"
10)
11
12type Game struct {
13	ui *ebitenui.UI
14}
15
16func NewGame() *Game {
17	root := widget.NewContainer(
18		widget.ContainerOpts.BackgroundImage(
19			image.NewNineSliceColor(colornames.Gainsboro),
20		),
21		widget.ContainerOpts.Layout(widget.NewGridLayout(
22			widget.GridLayoutOpts.Columns(5),
23			widget.GridLayoutOpts.Stretch(
24				[]bool{false, false, true, false, false},
25				[]bool{false, true, true, true, false},
26			),
27		)),
28	)
29	colors := []color.Color{
30		colornames.Indianred,
31		colornames.Goldenrod,
32		colornames.Steelblue,
33		colornames.Mediumseagreen,
34		colornames.Darkslategray,
35	}
36	for y := 0; y < 5; y++ {
37		for x := 0; x < 5; x++ {
38			child := widget.NewContainer(
39				widget.ContainerOpts.BackgroundImage(
40					image.NewNineSliceColor(colors[(x+y)%len(colors)]),
41				),
42				widget.ContainerOpts.WidgetOpts(
43					widget.WidgetOpts.LayoutData(widget.GridLayoutData{}),
44					widget.WidgetOpts.MinSize(16, 16),
45				),
46				widget.ContainerOpts.Layout(widget.NewAnchorLayout()),
47			)
48			root.AddChild(child)
49		}
50	}
51
52	return &Game{
53		ui: &ebitenui.UI{Container: root},
54	}
55}
56
57func (g *Game) Update() error {
58	g.ui.Update()
59	return nil
60}
61
62func (g *Game) Draw(screen *ebiten.Image) {
63	g.ui.Draw(screen)
64}
65
66func (g *Game) Layout(w, h int) (int, int) {
67	return w, h
68}
69
70func main() {
71	ebiten.SetWindowSize(480, 320)
72	ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
73	if err := ebiten.RunGame(NewGame()); err != nil {
74		panic(err)
75	}
76}
 1root := widget.NewContainer(
 2	widget.ContainerOpts.BackgroundImage(
 3		image.NewNineSliceColor(colornames.Gainsboro),
 4	),
 5	widget.ContainerOpts.Layout(widget.NewGridLayout(
 6		widget.GridLayoutOpts.Columns(5),
 7		widget.GridLayoutOpts.Stretch(
 8			[]bool{false, true, true, true, false},
 9			[]bool{false, true, true, true, false},
10		),
11	)),
12)

234x234

 1package main
 2
 3import (
 4	"image/color"
 5	"github.com/ebitenui/ebitenui"
 6	"github.com/ebitenui/ebitenui/image"
 7	"github.com/ebitenui/ebitenui/widget"
 8	"github.com/hajimehoshi/ebiten/v2"
 9	"golang.org/x/image/colornames"
10)
11
12type Game struct {
13	ui *ebitenui.UI
14}
15
16func NewGame() *Game {
17	root := widget.NewContainer(
18		widget.ContainerOpts.BackgroundImage(
19			image.NewNineSliceColor(colornames.Gainsboro),
20		),
21		widget.ContainerOpts.Layout(widget.NewGridLayout(
22			widget.GridLayoutOpts.Columns(5),
23			widget.GridLayoutOpts.Stretch(
24				[]bool{false, true, true, true, false},
25				[]bool{false, true, true, true, false},
26			),
27		)),
28	)
29	colors := []color.Color{
30		colornames.Indianred,
31		colornames.Goldenrod,
32		colornames.Steelblue,
33		colornames.Mediumseagreen,
34		colornames.Darkslategray,
35	}
36	for y := 0; y < 5; y++ {
37		for x := 0; x < 5; x++ {
38			child := widget.NewContainer(
39				widget.ContainerOpts.BackgroundImage(
40					image.NewNineSliceColor(colors[(x+y)%len(colors)]),
41				),
42				widget.ContainerOpts.WidgetOpts(
43					widget.WidgetOpts.LayoutData(widget.GridLayoutData{}),
44					widget.WidgetOpts.MinSize(16, 16),
45				),
46				widget.ContainerOpts.Layout(widget.NewAnchorLayout()),
47			)
48			root.AddChild(child)
49		}
50	}
51
52	return &Game{
53		ui: &ebitenui.UI{Container: root},
54	}
55}
56
57func (g *Game) Update() error {
58	g.ui.Update()
59	return nil
60}
61
62func (g *Game) Draw(screen *ebiten.Image) {
63	g.ui.Draw(screen)
64}
65
66func (g *Game) Layout(w, h int) (int, int) {
67	return w, h
68}
69
70func main() {
71	ebiten.SetWindowSize(480, 320)
72	ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
73	if err := ebiten.RunGame(NewGame()); err != nil {
74		panic(err)
75	}
76}
 1root := widget.NewContainer(
 2	widget.ContainerOpts.BackgroundImage(
 3		image.NewNineSliceColor(colornames.Gainsboro),
 4	),
 5	widget.ContainerOpts.Layout(widget.NewGridLayout(
 6		widget.GridLayoutOpts.Columns(5),
 7		widget.GridLayoutOpts.Stretch(
 8			[]bool{true, true, true, true, true},
 9			[]bool{false, false, false, false, false},
10		),
11	)),
12)

off

 1package main
 2
 3import (
 4	"image/color"
 5	"github.com/ebitenui/ebitenui"
 6	"github.com/ebitenui/ebitenui/image"
 7	"github.com/ebitenui/ebitenui/widget"
 8	"github.com/hajimehoshi/ebiten/v2"
 9	"golang.org/x/image/colornames"
10)
11
12type Game struct {
13	ui *ebitenui.UI
14}
15
16func NewGame() *Game {
17	root := widget.NewContainer(
18		widget.ContainerOpts.BackgroundImage(
19			image.NewNineSliceColor(colornames.Gainsboro),
20		),
21		widget.ContainerOpts.Layout(widget.NewGridLayout(
22			widget.GridLayoutOpts.Columns(5),
23			widget.GridLayoutOpts.Stretch(
24				[]bool{true, true, true, true, true},
25				[]bool{false, false, false, false, false},
26			),
27		)),
28	)
29	colors := []color.Color{
30		colornames.Indianred,
31		colornames.Goldenrod,
32		colornames.Steelblue,
33		colornames.Mediumseagreen,
34		colornames.Darkslategray,
35	}
36	for y := 0; y < 5; y++ {
37		for x := 0; x < 5; x++ {
38			child := widget.NewContainer(
39				widget.ContainerOpts.BackgroundImage(
40					image.NewNineSliceColor(colors[(x+y)%len(colors)]),
41				),
42				widget.ContainerOpts.WidgetOpts(
43					widget.WidgetOpts.LayoutData(widget.GridLayoutData{}),
44					widget.WidgetOpts.MinSize(16, 16),
45				),
46				widget.ContainerOpts.Layout(widget.NewAnchorLayout()),
47			)
48			root.AddChild(child)
49		}
50	}
51
52	return &Game{
53		ui: &ebitenui.UI{Container: root},
54	}
55}
56
57func (g *Game) Update() error {
58	g.ui.Update()
59	return nil
60}
61
62func (g *Game) Draw(screen *ebiten.Image) {
63	g.ui.Draw(screen)
64}
65
66func (g *Game) Layout(w, h int) (int, int) {
67	return w, h
68}
69
70func main() {
71	ebiten.SetWindowSize(480, 320)
72	ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
73	if err := ebiten.RunGame(NewGame()); err != nil {
74		panic(err)
75	}
76}
 1root := widget.NewContainer(
 2	widget.ContainerOpts.BackgroundImage(
 3		image.NewNineSliceColor(colornames.Gainsboro),
 4	),
 5	widget.ContainerOpts.Layout(widget.NewGridLayout(
 6		widget.GridLayoutOpts.Columns(5),
 7		widget.GridLayoutOpts.Stretch(
 8			[]bool{false, false, false, false, false},
 9			[]bool{true, true, true, true, true},
10		),
11	)),
12)

off

 1package main
 2
 3import (
 4	"image/color"
 5	"github.com/ebitenui/ebitenui"
 6	"github.com/ebitenui/ebitenui/image"
 7	"github.com/ebitenui/ebitenui/widget"
 8	"github.com/hajimehoshi/ebiten/v2"
 9	"golang.org/x/image/colornames"
10)
11
12type Game struct {
13	ui *ebitenui.UI
14}
15
16func NewGame() *Game {
17	root := widget.NewContainer(
18		widget.ContainerOpts.BackgroundImage(
19			image.NewNineSliceColor(colornames.Gainsboro),
20		),
21		widget.ContainerOpts.Layout(widget.NewGridLayout(
22			widget.GridLayoutOpts.Columns(5),
23			widget.GridLayoutOpts.Stretch(
24				[]bool{false, false, false, false, false},
25				[]bool{true, true, true, true, true},
26			),
27		)),
28	)
29	colors := []color.Color{
30		colornames.Indianred,
31		colornames.Goldenrod,
32		colornames.Steelblue,
33		colornames.Mediumseagreen,
34		colornames.Darkslategray,
35	}
36	for y := 0; y < 5; y++ {
37		for x := 0; x < 5; x++ {
38			child := widget.NewContainer(
39				widget.ContainerOpts.BackgroundImage(
40					image.NewNineSliceColor(colors[(x+y)%len(colors)]),
41				),
42				widget.ContainerOpts.WidgetOpts(
43					widget.WidgetOpts.LayoutData(widget.GridLayoutData{}),
44					widget.WidgetOpts.MinSize(16, 16),
45				),
46				widget.ContainerOpts.Layout(widget.NewAnchorLayout()),
47			)
48			root.AddChild(child)
49		}
50	}
51
52	return &Game{
53		ui: &ebitenui.UI{Container: root},
54	}
55}
56
57func (g *Game) Update() error {
58	g.ui.Update()
59	return nil
60}
61
62func (g *Game) Draw(screen *ebiten.Image) {
63	g.ui.Draw(screen)
64}
65
66func (g *Game) Layout(w, h int) (int, int) {
67	return w, h
68}
69
70func main() {
71	ebiten.SetWindowSize(480, 320)
72	ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
73	if err := ebiten.RunGame(NewGame()); err != nil {
74		panic(err)
75	}
76}
 1root := widget.NewContainer(
 2	widget.ContainerOpts.BackgroundImage(
 3		image.NewNineSliceColor(colornames.Gainsboro),
 4	),
 5	widget.ContainerOpts.Layout(widget.NewGridLayout(
 6		widget.GridLayoutOpts.Columns(5),
 7		widget.GridLayoutOpts.Stretch(
 8			[]bool{false, false, false, false, false},
 9			[]bool{false, false, false, false, false},
10		),
11	)),
12)

off

 1package main
 2
 3import (
 4	"image/color"
 5	"github.com/ebitenui/ebitenui"
 6	"github.com/ebitenui/ebitenui/image"
 7	"github.com/ebitenui/ebitenui/widget"
 8	"github.com/hajimehoshi/ebiten/v2"
 9	"golang.org/x/image/colornames"
10)
11
12type Game struct {
13	ui *ebitenui.UI
14}
15
16func NewGame() *Game {
17	root := widget.NewContainer(
18		widget.ContainerOpts.BackgroundImage(
19			image.NewNineSliceColor(colornames.Gainsboro),
20		),
21		widget.ContainerOpts.Layout(widget.NewGridLayout(
22			widget.GridLayoutOpts.Columns(5),
23			widget.GridLayoutOpts.Stretch(
24				[]bool{false, false, false, false, false},
25				[]bool{false, false, false, false, false},
26			),
27		)),
28	)
29	colors := []color.Color{
30		colornames.Indianred,
31		colornames.Goldenrod,
32		colornames.Steelblue,
33		colornames.Mediumseagreen,
34		colornames.Darkslategray,
35	}
36	for y := 0; y < 5; y++ {
37		for x := 0; x < 5; x++ {
38			child := widget.NewContainer(
39				widget.ContainerOpts.BackgroundImage(
40					image.NewNineSliceColor(colors[(x+y)%len(colors)]),
41				),
42				widget.ContainerOpts.WidgetOpts(
43					widget.WidgetOpts.LayoutData(widget.GridLayoutData{}),
44					widget.WidgetOpts.MinSize(16, 16),
45				),
46				widget.ContainerOpts.Layout(widget.NewAnchorLayout()),
47			)
48			root.AddChild(child)
49		}
50	}
51
52	return &Game{
53		ui: &ebitenui.UI{Container: root},
54	}
55}
56
57func (g *Game) Update() error {
58	g.ui.Update()
59	return nil
60}
61
62func (g *Game) Draw(screen *ebiten.Image) {
63	g.ui.Draw(screen)
64}
65
66func (g *Game) Layout(w, h int) (int, int) {
67	return w, h
68}
69
70func main() {
71	ebiten.SetWindowSize(480, 320)
72	ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
73	if err := ebiten.RunGame(NewGame()); err != nil {
74		panic(err)
75	}
76}
Default stretch

Responsible for selecting all cells along each axis. Can be used instead of the previous option to avoid listing all cells. It can also be overridden by a regular property.

Stretch:
1root := widget.NewContainer(
2	widget.ContainerOpts.BackgroundImage(
3		image.NewNineSliceColor(colornames.Gainsboro),
4	),
5	widget.ContainerOpts.Layout(widget.NewGridLayout(
6		widget.GridLayoutOpts.Columns(5),
7		widget.GridLayoutOpts.DefaultStretch(true, true),
8	)),
9)

all

 1package main
 2
 3import (
 4	"image/color"
 5	"github.com/ebitenui/ebitenui"
 6	"github.com/ebitenui/ebitenui/image"
 7	"github.com/ebitenui/ebitenui/widget"
 8	"github.com/hajimehoshi/ebiten/v2"
 9	"golang.org/x/image/colornames"
10)
11
12type Game struct {
13	ui *ebitenui.UI
14}
15
16func NewGame() *Game {
17	root := widget.NewContainer(
18		widget.ContainerOpts.BackgroundImage(
19			image.NewNineSliceColor(colornames.Gainsboro),
20		),
21		widget.ContainerOpts.Layout(widget.NewGridLayout(
22			widget.GridLayoutOpts.Columns(5),
23			widget.GridLayoutOpts.DefaultStretch(true, true),
24		)),
25	)
26	colors := []color.Color{
27		colornames.Indianred,
28		colornames.Goldenrod,
29		colornames.Steelblue,
30		colornames.Mediumseagreen,
31		colornames.Darkslategray,
32	}
33	for y := 0; y < 5; y++ {
34		for x := 0; x < 5; x++ {
35			child := widget.NewContainer(
36				widget.ContainerOpts.BackgroundImage(
37					image.NewNineSliceColor(colors[(x+y)%len(colors)]),
38				),
39				widget.ContainerOpts.WidgetOpts(
40					widget.WidgetOpts.LayoutData(widget.GridLayoutData{}),
41					widget.WidgetOpts.MinSize(16, 16),
42				),
43				widget.ContainerOpts.Layout(widget.NewAnchorLayout()),
44			)
45			root.AddChild(child)
46		}
47	}
48
49	return &Game{
50		ui: &ebitenui.UI{Container: root},
51	}
52}
53
54func (g *Game) Update() error {
55	g.ui.Update()
56	return nil
57}
58
59func (g *Game) Draw(screen *ebiten.Image) {
60	g.ui.Draw(screen)
61}
62
63func (g *Game) Layout(w, h int) (int, int) {
64	return w, h
65}
66
67func main() {
68	ebiten.SetWindowSize(480, 320)
69	ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
70	if err := ebiten.RunGame(NewGame()); err != nil {
71		panic(err)
72	}
73}
1root := widget.NewContainer(
2	widget.ContainerOpts.BackgroundImage(
3		image.NewNineSliceColor(colornames.Gainsboro),
4	),
5	widget.ContainerOpts.Layout(widget.NewGridLayout(
6		widget.GridLayoutOpts.Columns(5),
7		widget.GridLayoutOpts.DefaultStretch(true, false),
8	)),
9)

all

 1package main
 2
 3import (
 4	"image/color"
 5	"github.com/ebitenui/ebitenui"
 6	"github.com/ebitenui/ebitenui/image"
 7	"github.com/ebitenui/ebitenui/widget"
 8	"github.com/hajimehoshi/ebiten/v2"
 9	"golang.org/x/image/colornames"
10)
11
12type Game struct {
13	ui *ebitenui.UI
14}
15
16func NewGame() *Game {
17	root := widget.NewContainer(
18		widget.ContainerOpts.BackgroundImage(
19			image.NewNineSliceColor(colornames.Gainsboro),
20		),
21		widget.ContainerOpts.Layout(widget.NewGridLayout(
22			widget.GridLayoutOpts.Columns(5),
23			widget.GridLayoutOpts.DefaultStretch(true, false),
24		)),
25	)
26	colors := []color.Color{
27		colornames.Indianred,
28		colornames.Goldenrod,
29		colornames.Steelblue,
30		colornames.Mediumseagreen,
31		colornames.Darkslategray,
32	}
33	for y := 0; y < 5; y++ {
34		for x := 0; x < 5; x++ {
35			child := widget.NewContainer(
36				widget.ContainerOpts.BackgroundImage(
37					image.NewNineSliceColor(colors[(x+y)%len(colors)]),
38				),
39				widget.ContainerOpts.WidgetOpts(
40					widget.WidgetOpts.LayoutData(widget.GridLayoutData{}),
41					widget.WidgetOpts.MinSize(16, 16),
42				),
43				widget.ContainerOpts.Layout(widget.NewAnchorLayout()),
44			)
45			root.AddChild(child)
46		}
47	}
48
49	return &Game{
50		ui: &ebitenui.UI{Container: root},
51	}
52}
53
54func (g *Game) Update() error {
55	g.ui.Update()
56	return nil
57}
58
59func (g *Game) Draw(screen *ebiten.Image) {
60	g.ui.Draw(screen)
61}
62
63func (g *Game) Layout(w, h int) (int, int) {
64	return w, h
65}
66
67func main() {
68	ebiten.SetWindowSize(480, 320)
69	ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
70	if err := ebiten.RunGame(NewGame()); err != nil {
71		panic(err)
72	}
73}
1root := widget.NewContainer(
2	widget.ContainerOpts.BackgroundImage(
3		image.NewNineSliceColor(colornames.Gainsboro),
4	),
5	widget.ContainerOpts.Layout(widget.NewGridLayout(
6		widget.GridLayoutOpts.Columns(5),
7		widget.GridLayoutOpts.DefaultStretch(false, true),
8	)),
9)

all

 1package main
 2
 3import (
 4	"image/color"
 5	"github.com/ebitenui/ebitenui"
 6	"github.com/ebitenui/ebitenui/image"
 7	"github.com/ebitenui/ebitenui/widget"
 8	"github.com/hajimehoshi/ebiten/v2"
 9	"golang.org/x/image/colornames"
10)
11
12type Game struct {
13	ui *ebitenui.UI
14}
15
16func NewGame() *Game {
17	root := widget.NewContainer(
18		widget.ContainerOpts.BackgroundImage(
19			image.NewNineSliceColor(colornames.Gainsboro),
20		),
21		widget.ContainerOpts.Layout(widget.NewGridLayout(
22			widget.GridLayoutOpts.Columns(5),
23			widget.GridLayoutOpts.DefaultStretch(false, true),
24		)),
25	)
26	colors := []color.Color{
27		colornames.Indianred,
28		colornames.Goldenrod,
29		colornames.Steelblue,
30		colornames.Mediumseagreen,
31		colornames.Darkslategray,
32	}
33	for y := 0; y < 5; y++ {
34		for x := 0; x < 5; x++ {
35			child := widget.NewContainer(
36				widget.ContainerOpts.BackgroundImage(
37					image.NewNineSliceColor(colors[(x+y)%len(colors)]),
38				),
39				widget.ContainerOpts.WidgetOpts(
40					widget.WidgetOpts.LayoutData(widget.GridLayoutData{}),
41					widget.WidgetOpts.MinSize(16, 16),
42				),
43				widget.ContainerOpts.Layout(widget.NewAnchorLayout()),
44			)
45			root.AddChild(child)
46		}
47	}
48
49	return &Game{
50		ui: &ebitenui.UI{Container: root},
51	}
52}
53
54func (g *Game) Update() error {
55	g.ui.Update()
56	return nil
57}
58
59func (g *Game) Draw(screen *ebiten.Image) {
60	g.ui.Draw(screen)
61}
62
63func (g *Game) Layout(w, h int) (int, int) {
64	return w, h
65}
66
67func main() {
68	ebiten.SetWindowSize(480, 320)
69	ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
70	if err := ebiten.RunGame(NewGame()); err != nil {
71		panic(err)
72	}
73}
1root := widget.NewContainer(
2	widget.ContainerOpts.BackgroundImage(
3		image.NewNineSliceColor(colornames.Gainsboro),
4	),
5	widget.ContainerOpts.Layout(widget.NewGridLayout(
6		widget.GridLayoutOpts.Columns(5),
7		widget.GridLayoutOpts.DefaultStretch(false, false),
8	)),
9)

all

 1package main
 2
 3import (
 4	"image/color"
 5	"github.com/ebitenui/ebitenui"
 6	"github.com/ebitenui/ebitenui/image"
 7	"github.com/ebitenui/ebitenui/widget"
 8	"github.com/hajimehoshi/ebiten/v2"
 9	"golang.org/x/image/colornames"
10)
11
12type Game struct {
13	ui *ebitenui.UI
14}
15
16func NewGame() *Game {
17	root := widget.NewContainer(
18		widget.ContainerOpts.BackgroundImage(
19			image.NewNineSliceColor(colornames.Gainsboro),
20		),
21		widget.ContainerOpts.Layout(widget.NewGridLayout(
22			widget.GridLayoutOpts.Columns(5),
23			widget.GridLayoutOpts.DefaultStretch(false, false),
24		)),
25	)
26	colors := []color.Color{
27		colornames.Indianred,
28		colornames.Goldenrod,
29		colornames.Steelblue,
30		colornames.Mediumseagreen,
31		colornames.Darkslategray,
32	}
33	for y := 0; y < 5; y++ {
34		for x := 0; x < 5; x++ {
35			child := widget.NewContainer(
36				widget.ContainerOpts.BackgroundImage(
37					image.NewNineSliceColor(colors[(x+y)%len(colors)]),
38				),
39				widget.ContainerOpts.WidgetOpts(
40					widget.WidgetOpts.LayoutData(widget.GridLayoutData{}),
41					widget.WidgetOpts.MinSize(16, 16),
42				),
43				widget.ContainerOpts.Layout(widget.NewAnchorLayout()),
44			)
45			root.AddChild(child)
46		}
47	}
48
49	return &Game{
50		ui: &ebitenui.UI{Container: root},
51	}
52}
53
54func (g *Game) Update() error {
55	g.ui.Update()
56	return nil
57}
58
59func (g *Game) Draw(screen *ebiten.Image) {
60	g.ui.Draw(screen)
61}
62
63func (g *Game) Layout(w, h int) (int, int) {
64	return w, h
65}
66
67func main() {
68	ebiten.SetWindowSize(480, 320)
69	ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
70	if err := ebiten.RunGame(NewGame()); err != nil {
71		panic(err)
72	}
73}
Padding

Responsible for the offset of the parent container.

Padding:
 1root := widget.NewContainer(
 2	widget.ContainerOpts.BackgroundImage(
 3		image.NewNineSliceColor(colornames.Gainsboro),
 4	),
 5	widget.ContainerOpts.Layout(widget.NewGridLayout(
 6		widget.GridLayoutOpts.Columns(5),
 7		widget.GridLayoutOpts.DefaultStretch(true, true),
 8		widget.GridLayoutOpts.Padding(widget.Insets{
 9			Left: 50,
10		}),
11	)),
12)

lef

 1package main
 2
 3import (
 4	"image/color"
 5	"github.com/ebitenui/ebitenui"
 6	"github.com/ebitenui/ebitenui/image"
 7	"github.com/ebitenui/ebitenui/widget"
 8	"github.com/hajimehoshi/ebiten/v2"
 9	"golang.org/x/image/colornames"
10)
11
12type Game struct {
13	ui *ebitenui.UI
14}
15
16func NewGame() *Game {
17	root := widget.NewContainer(
18		widget.ContainerOpts.BackgroundImage(
19			image.NewNineSliceColor(colornames.Gainsboro),
20		),
21		widget.ContainerOpts.Layout(widget.NewGridLayout(
22			widget.GridLayoutOpts.Columns(5),
23			widget.GridLayoutOpts.DefaultStretch(true, true),
24			widget.GridLayoutOpts.Padding(widget.Insets{
25				Left: 50,
26			}),
27		)),
28	)
29	colors := []color.Color{
30		colornames.Indianred,
31		colornames.Goldenrod,
32		colornames.Steelblue,
33		colornames.Mediumseagreen,
34		colornames.Darkslategray,
35	}
36	for y := 0; y < 5; y++ {
37		for x := 0; x < 5; x++ {
38			child := widget.NewContainer(
39				widget.ContainerOpts.BackgroundImage(
40					image.NewNineSliceColor(colors[(x+y)%len(colors)]),
41				),
42				widget.ContainerOpts.WidgetOpts(
43					widget.WidgetOpts.LayoutData(widget.GridLayoutData{}),
44					widget.WidgetOpts.MinSize(16, 16),
45				),
46				widget.ContainerOpts.Layout(widget.NewAnchorLayout()),
47			)
48			root.AddChild(child)
49		}
50	}
51
52	return &Game{
53		ui: &ebitenui.UI{Container: root},
54	}
55}
56
57func (g *Game) Update() error {
58	g.ui.Update()
59	return nil
60}
61
62func (g *Game) Draw(screen *ebiten.Image) {
63	g.ui.Draw(screen)
64}
65
66func (g *Game) Layout(w, h int) (int, int) {
67	return w, h
68}
69
70func main() {
71	ebiten.SetWindowSize(480, 320)
72	ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
73	if err := ebiten.RunGame(NewGame()); err != nil {
74		panic(err)
75	}
76}
 1root := widget.NewContainer(
 2	widget.ContainerOpts.BackgroundImage(
 3		image.NewNineSliceColor(colornames.Gainsboro),
 4	),
 5	widget.ContainerOpts.Layout(widget.NewGridLayout(
 6		widget.GridLayoutOpts.Columns(5),
 7		widget.GridLayoutOpts.DefaultStretch(true, true),
 8		widget.GridLayoutOpts.Padding(widget.Insets{
 9			Right: 50,
10		}),
11	)),
12)

rig

 1package main
 2
 3import (
 4	"image/color"
 5	"github.com/ebitenui/ebitenui"
 6	"github.com/ebitenui/ebitenui/image"
 7	"github.com/ebitenui/ebitenui/widget"
 8	"github.com/hajimehoshi/ebiten/v2"
 9	"golang.org/x/image/colornames"
10)
11
12type Game struct {
13	ui *ebitenui.UI
14}
15
16func NewGame() *Game {
17	root := widget.NewContainer(
18		widget.ContainerOpts.BackgroundImage(
19			image.NewNineSliceColor(colornames.Gainsboro),
20		),
21		widget.ContainerOpts.Layout(widget.NewGridLayout(
22			widget.GridLayoutOpts.Columns(5),
23			widget.GridLayoutOpts.DefaultStretch(true, true),
24			widget.GridLayoutOpts.Padding(widget.Insets{
25				Right: 50,
26			}),
27		)),
28	)
29	colors := []color.Color{
30		colornames.Indianred,
31		colornames.Goldenrod,
32		colornames.Steelblue,
33		colornames.Mediumseagreen,
34		colornames.Darkslategray,
35	}
36	for y := 0; y < 5; y++ {
37		for x := 0; x < 5; x++ {
38			child := widget.NewContainer(
39				widget.ContainerOpts.BackgroundImage(
40					image.NewNineSliceColor(colors[(x+y)%len(colors)]),
41				),
42				widget.ContainerOpts.WidgetOpts(
43					widget.WidgetOpts.LayoutData(widget.GridLayoutData{}),
44					widget.WidgetOpts.MinSize(16, 16),
45				),
46				widget.ContainerOpts.Layout(widget.NewAnchorLayout()),
47			)
48			root.AddChild(child)
49		}
50	}
51
52	return &Game{
53		ui: &ebitenui.UI{Container: root},
54	}
55}
56
57func (g *Game) Update() error {
58	g.ui.Update()
59	return nil
60}
61
62func (g *Game) Draw(screen *ebiten.Image) {
63	g.ui.Draw(screen)
64}
65
66func (g *Game) Layout(w, h int) (int, int) {
67	return w, h
68}
69
70func main() {
71	ebiten.SetWindowSize(480, 320)
72	ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
73	if err := ebiten.RunGame(NewGame()); err != nil {
74		panic(err)
75	}
76}
 1root := widget.NewContainer(
 2	widget.ContainerOpts.BackgroundImage(
 3		image.NewNineSliceColor(colornames.Gainsboro),
 4	),
 5	widget.ContainerOpts.Layout(widget.NewGridLayout(
 6		widget.GridLayoutOpts.Columns(5),
 7		widget.GridLayoutOpts.DefaultStretch(true, true),
 8		widget.GridLayoutOpts.Padding(widget.Insets{
 9			Top: 50,
10		}),
11	)),
12)

top

 1package main
 2
 3import (
 4	"image/color"
 5	"github.com/ebitenui/ebitenui"
 6	"github.com/ebitenui/ebitenui/image"
 7	"github.com/ebitenui/ebitenui/widget"
 8	"github.com/hajimehoshi/ebiten/v2"
 9	"golang.org/x/image/colornames"
10)
11
12type Game struct {
13	ui *ebitenui.UI
14}
15
16func NewGame() *Game {
17	root := widget.NewContainer(
18		widget.ContainerOpts.BackgroundImage(
19			image.NewNineSliceColor(colornames.Gainsboro),
20		),
21		widget.ContainerOpts.Layout(widget.NewGridLayout(
22			widget.GridLayoutOpts.Columns(5),
23			widget.GridLayoutOpts.DefaultStretch(true, true),
24			widget.GridLayoutOpts.Padding(widget.Insets{
25				Top: 50,
26			}),
27		)),
28	)
29	colors := []color.Color{
30		colornames.Indianred,
31		colornames.Goldenrod,
32		colornames.Steelblue,
33		colornames.Mediumseagreen,
34		colornames.Darkslategray,
35	}
36	for y := 0; y < 5; y++ {
37		for x := 0; x < 5; x++ {
38			child := widget.NewContainer(
39				widget.ContainerOpts.BackgroundImage(
40					image.NewNineSliceColor(colors[(x+y)%len(colors)]),
41				),
42				widget.ContainerOpts.WidgetOpts(
43					widget.WidgetOpts.LayoutData(widget.GridLayoutData{}),
44					widget.WidgetOpts.MinSize(16, 16),
45				),
46				widget.ContainerOpts.Layout(widget.NewAnchorLayout()),
47			)
48			root.AddChild(child)
49		}
50	}
51
52	return &Game{
53		ui: &ebitenui.UI{Container: root},
54	}
55}
56
57func (g *Game) Update() error {
58	g.ui.Update()
59	return nil
60}
61
62func (g *Game) Draw(screen *ebiten.Image) {
63	g.ui.Draw(screen)
64}
65
66func (g *Game) Layout(w, h int) (int, int) {
67	return w, h
68}
69
70func main() {
71	ebiten.SetWindowSize(480, 320)
72	ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
73	if err := ebiten.RunGame(NewGame()); err != nil {
74		panic(err)
75	}
76}
 1root := widget.NewContainer(
 2	widget.ContainerOpts.BackgroundImage(
 3		image.NewNineSliceColor(colornames.Gainsboro),
 4	),
 5	widget.ContainerOpts.Layout(widget.NewGridLayout(
 6		widget.GridLayoutOpts.Columns(5),
 7		widget.GridLayoutOpts.DefaultStretch(true, true),
 8		widget.GridLayoutOpts.Padding(widget.Insets{
 9			Bottom: 50,
10		}),
11	)),
12)

top

 1package main
 2
 3import (
 4	"image/color"
 5	"github.com/ebitenui/ebitenui"
 6	"github.com/ebitenui/ebitenui/image"
 7	"github.com/ebitenui/ebitenui/widget"
 8	"github.com/hajimehoshi/ebiten/v2"
 9	"golang.org/x/image/colornames"
10)
11
12type Game struct {
13	ui *ebitenui.UI
14}
15
16func NewGame() *Game {
17	root := widget.NewContainer(
18		widget.ContainerOpts.BackgroundImage(
19			image.NewNineSliceColor(colornames.Gainsboro),
20		),
21		widget.ContainerOpts.Layout(widget.NewGridLayout(
22			widget.GridLayoutOpts.Columns(5),
23			widget.GridLayoutOpts.DefaultStretch(true, true),
24			widget.GridLayoutOpts.Padding(widget.Insets{
25				Bottom: 50,
26			}),
27		)),
28	)
29	colors := []color.Color{
30		colornames.Indianred,
31		colornames.Goldenrod,
32		colornames.Steelblue,
33		colornames.Mediumseagreen,
34		colornames.Darkslategray,
35	}
36	for y := 0; y < 5; y++ {
37		for x := 0; x < 5; x++ {
38			child := widget.NewContainer(
39				widget.ContainerOpts.BackgroundImage(
40					image.NewNineSliceColor(colors[(x+y)%len(colors)]),
41				),
42				widget.ContainerOpts.WidgetOpts(
43					widget.WidgetOpts.LayoutData(widget.GridLayoutData{}),
44					widget.WidgetOpts.MinSize(16, 16),
45				),
46				widget.ContainerOpts.Layout(widget.NewAnchorLayout()),
47			)
48			root.AddChild(child)
49		}
50	}
51
52	return &Game{
53		ui: &ebitenui.UI{Container: root},
54	}
55}
56
57func (g *Game) Update() error {
58	g.ui.Update()
59	return nil
60}
61
62func (g *Game) Draw(screen *ebiten.Image) {
63	g.ui.Draw(screen)
64}
65
66func (g *Game) Layout(w, h int) (int, int) {
67	return w, h
68}
69
70func main() {
71	ebiten.SetWindowSize(480, 320)
72	ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
73	if err := ebiten.RunGame(NewGame()); err != nil {
74		panic(err)
75	}
76}
Spacing

Responsible for the offset between child elements.

Spacing:
 1root := widget.NewContainer(
 2	widget.ContainerOpts.BackgroundImage(
 3		image.NewNineSliceColor(colornames.Gainsboro),
 4	),
 5	widget.ContainerOpts.Layout(widget.NewGridLayout(
 6		widget.GridLayoutOpts.Columns(5),
 7		widget.GridLayoutOpts.DefaultStretch(true, true),
 8		widget.GridLayoutOpts.Spacing(0, 0),
 9	)),
10)

0

 1package main
 2
 3import (
 4	"image/color"
 5	"github.com/ebitenui/ebitenui"
 6	"github.com/ebitenui/ebitenui/image"
 7	"github.com/ebitenui/ebitenui/widget"
 8	"github.com/hajimehoshi/ebiten/v2"
 9	"golang.org/x/image/colornames"
10)
11
12type Game struct {
13	ui *ebitenui.UI
14}
15
16func NewGame() *Game {
17	root := widget.NewContainer(
18		widget.ContainerOpts.BackgroundImage(
19			image.NewNineSliceColor(colornames.Gainsboro),
20		),
21		widget.ContainerOpts.Layout(widget.NewGridLayout(
22			widget.GridLayoutOpts.Columns(5),
23			widget.GridLayoutOpts.DefaultStretch(true, true),
24			widget.GridLayoutOpts.Spacing(0, 0),
25		)),
26	)
27	colors := []color.Color{
28		colornames.Indianred,
29		colornames.Goldenrod,
30		colornames.Steelblue,
31		colornames.Mediumseagreen,
32		colornames.Darkslategray,
33	}
34	for y := 0; y < 5; y++ {
35		for x := 0; x < 5; x++ {
36			child := widget.NewContainer(
37				widget.ContainerOpts.BackgroundImage(
38					image.NewNineSliceColor(colors[(x+y)%len(colors)]),
39				),
40				widget.ContainerOpts.WidgetOpts(
41					widget.WidgetOpts.LayoutData(widget.GridLayoutData{}),
42					widget.WidgetOpts.MinSize(16, 16),
43				),
44				widget.ContainerOpts.Layout(widget.NewAnchorLayout()),
45			)
46			root.AddChild(child)
47		}
48	}
49
50	return &Game{
51		ui: &ebitenui.UI{Container: root},
52	}
53}
54
55func (g *Game) Update() error {
56	g.ui.Update()
57	return nil
58}
59
60func (g *Game) Draw(screen *ebiten.Image) {
61	g.ui.Draw(screen)
62}
63
64func (g *Game) Layout(w, h int) (int, int) {
65	return w, h
66}
67
68func main() {
69	ebiten.SetWindowSize(480, 320)
70	ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
71	if err := ebiten.RunGame(NewGame()); err != nil {
72		panic(err)
73	}
74}
 1root := widget.NewContainer(
 2	widget.ContainerOpts.BackgroundImage(
 3		image.NewNineSliceColor(colornames.Gainsboro),
 4	),
 5	widget.ContainerOpts.Layout(widget.NewGridLayout(
 6		widget.GridLayoutOpts.Columns(5),
 7		widget.GridLayoutOpts.DefaultStretch(true, true),
 8		widget.GridLayoutOpts.Spacing(0, 25),
 9	)),
10)

25

 1package main
 2
 3import (
 4	"image/color"
 5	"github.com/ebitenui/ebitenui"
 6	"github.com/ebitenui/ebitenui/image"
 7	"github.com/ebitenui/ebitenui/widget"
 8	"github.com/hajimehoshi/ebiten/v2"
 9	"golang.org/x/image/colornames"
10)
11
12type Game struct {
13	ui *ebitenui.UI
14}
15
16func NewGame() *Game {
17	root := widget.NewContainer(
18		widget.ContainerOpts.BackgroundImage(
19			image.NewNineSliceColor(colornames.Gainsboro),
20		),
21		widget.ContainerOpts.Layout(widget.NewGridLayout(
22			widget.GridLayoutOpts.Columns(5),
23			widget.GridLayoutOpts.DefaultStretch(true, true),
24			widget.GridLayoutOpts.Spacing(0, 25),
25		)),
26	)
27	colors := []color.Color{
28		colornames.Indianred,
29		colornames.Goldenrod,
30		colornames.Steelblue,
31		colornames.Mediumseagreen,
32		colornames.Darkslategray,
33	}
34	for y := 0; y < 5; y++ {
35		for x := 0; x < 5; x++ {
36			child := widget.NewContainer(
37				widget.ContainerOpts.BackgroundImage(
38					image.NewNineSliceColor(colors[(x+y)%len(colors)]),
39				),
40				widget.ContainerOpts.WidgetOpts(
41					widget.WidgetOpts.LayoutData(widget.GridLayoutData{}),
42					widget.WidgetOpts.MinSize(16, 16),
43				),
44				widget.ContainerOpts.Layout(widget.NewAnchorLayout()),
45			)
46			root.AddChild(child)
47		}
48	}
49
50	return &Game{
51		ui: &ebitenui.UI{Container: root},
52	}
53}
54
55func (g *Game) Update() error {
56	g.ui.Update()
57	return nil
58}
59
60func (g *Game) Draw(screen *ebiten.Image) {
61	g.ui.Draw(screen)
62}
63
64func (g *Game) Layout(w, h int) (int, int) {
65	return w, h
66}
67
68func main() {
69	ebiten.SetWindowSize(480, 320)
70	ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
71	if err := ebiten.RunGame(NewGame()); err != nil {
72		panic(err)
73	}
74}
 1root := widget.NewContainer(
 2	widget.ContainerOpts.BackgroundImage(
 3		image.NewNineSliceColor(colornames.Gainsboro),
 4	),
 5	widget.ContainerOpts.Layout(widget.NewGridLayout(
 6		widget.GridLayoutOpts.Columns(5),
 7		widget.GridLayoutOpts.DefaultStretch(true, true),
 8		widget.GridLayoutOpts.Spacing(25, 0),
 9	)),
10)

50

 1package main
 2
 3import (
 4	"image/color"
 5	"github.com/ebitenui/ebitenui"
 6	"github.com/ebitenui/ebitenui/image"
 7	"github.com/ebitenui/ebitenui/widget"
 8	"github.com/hajimehoshi/ebiten/v2"
 9	"golang.org/x/image/colornames"
10)
11
12type Game struct {
13	ui *ebitenui.UI
14}
15
16func NewGame() *Game {
17	root := widget.NewContainer(
18		widget.ContainerOpts.BackgroundImage(
19			image.NewNineSliceColor(colornames.Gainsboro),
20		),
21		widget.ContainerOpts.Layout(widget.NewGridLayout(
22			widget.GridLayoutOpts.Columns(5),
23			widget.GridLayoutOpts.DefaultStretch(true, true),
24			widget.GridLayoutOpts.Spacing(25, 0),
25		)),
26	)
27	colors := []color.Color{
28		colornames.Indianred,
29		colornames.Goldenrod,
30		colornames.Steelblue,
31		colornames.Mediumseagreen,
32		colornames.Darkslategray,
33	}
34	for y := 0; y < 5; y++ {
35		for x := 0; x < 5; x++ {
36			child := widget.NewContainer(
37				widget.ContainerOpts.BackgroundImage(
38					image.NewNineSliceColor(colors[(x+y)%len(colors)]),
39				),
40				widget.ContainerOpts.WidgetOpts(
41					widget.WidgetOpts.LayoutData(widget.GridLayoutData{}),
42					widget.WidgetOpts.MinSize(16, 16),
43				),
44				widget.ContainerOpts.Layout(widget.NewAnchorLayout()),
45			)
46			root.AddChild(child)
47		}
48	}
49
50	return &Game{
51		ui: &ebitenui.UI{Container: root},
52	}
53}
54
55func (g *Game) Update() error {
56	g.ui.Update()
57	return nil
58}
59
60func (g *Game) Draw(screen *ebiten.Image) {
61	g.ui.Draw(screen)
62}
63
64func (g *Game) Layout(w, h int) (int, int) {
65	return w, h
66}
67
68func main() {
69	ebiten.SetWindowSize(480, 320)
70	ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
71	if err := ebiten.RunGame(NewGame()); err != nil {
72		panic(err)
73	}
74}
 1root := widget.NewContainer(
 2	widget.ContainerOpts.BackgroundImage(
 3		image.NewNineSliceColor(colornames.Gainsboro),
 4	),
 5	widget.ContainerOpts.Layout(widget.NewGridLayout(
 6		widget.GridLayoutOpts.Columns(5),
 7		widget.GridLayoutOpts.DefaultStretch(true, true),
 8		widget.GridLayoutOpts.Spacing(25, 25),
 9	)),
10)

50

 1package main
 2
 3import (
 4	"image/color"
 5	"github.com/ebitenui/ebitenui"
 6	"github.com/ebitenui/ebitenui/image"
 7	"github.com/ebitenui/ebitenui/widget"
 8	"github.com/hajimehoshi/ebiten/v2"
 9	"golang.org/x/image/colornames"
10)
11
12type Game struct {
13	ui *ebitenui.UI
14}
15
16func NewGame() *Game {
17	root := widget.NewContainer(
18		widget.ContainerOpts.BackgroundImage(
19			image.NewNineSliceColor(colornames.Gainsboro),
20		),
21		widget.ContainerOpts.Layout(widget.NewGridLayout(
22			widget.GridLayoutOpts.Columns(5),
23			widget.GridLayoutOpts.DefaultStretch(true, true),
24			widget.GridLayoutOpts.Spacing(25, 25),
25		)),
26	)
27	colors := []color.Color{
28		colornames.Indianred,
29		colornames.Goldenrod,
30		colornames.Steelblue,
31		colornames.Mediumseagreen,
32		colornames.Darkslategray,
33	}
34	for y := 0; y < 5; y++ {
35		for x := 0; x < 5; x++ {
36			child := widget.NewContainer(
37				widget.ContainerOpts.BackgroundImage(
38					image.NewNineSliceColor(colors[(x+y)%len(colors)]),
39				),
40				widget.ContainerOpts.WidgetOpts(
41					widget.WidgetOpts.LayoutData(widget.GridLayoutData{}),
42					widget.WidgetOpts.MinSize(16, 16),
43				),
44				widget.ContainerOpts.Layout(widget.NewAnchorLayout()),
45			)
46			root.AddChild(child)
47		}
48	}
49
50	return &Game{
51		ui: &ebitenui.UI{Container: root},
52	}
53}
54
55func (g *Game) Update() error {
56	g.ui.Update()
57	return nil
58}
59
60func (g *Game) Draw(screen *ebiten.Image) {
61	g.ui.Draw(screen)
62}
63
64func (g *Game) Layout(w, h int) (int, int) {
65	return w, h
66}
67
68func main() {
69	ebiten.SetWindowSize(480, 320)
70	ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
71	if err := ebiten.RunGame(NewGame()); err != nil {
72		panic(err)
73	}
74}

Layout data

Max size

Responsible for the allowable size of the child containers.

Max:
 1child := widget.NewContainer(
 2	widget.ContainerOpts.BackgroundImage(
 3		image.NewNineSliceColor(colors[(x+y)%len(colors)]),
 4	),
 5	widget.ContainerOpts.WidgetOpts(
 6		widget.WidgetOpts.LayoutData(widget.GridLayoutData{}),
 7		widget.WidgetOpts.MinSize(64, 64),
 8	),
 9	widget.ContainerOpts.Layout(widget.NewAnchorLayout()),
10)

wid

 1package main
 2
 3import (
 4	"image/color"
 5	"github.com/ebitenui/ebitenui"
 6	"github.com/ebitenui/ebitenui/image"
 7	"github.com/ebitenui/ebitenui/widget"
 8	"github.com/hajimehoshi/ebiten/v2"
 9	"golang.org/x/image/colornames"
10)
11
12type Game struct {
13	ui *ebitenui.UI
14}
15
16func NewGame() *Game {
17	root := widget.NewContainer(
18		widget.ContainerOpts.BackgroundImage(
19			image.NewNineSliceColor(colornames.Gainsboro),
20		),
21		widget.ContainerOpts.Layout(widget.NewGridLayout(
22			widget.GridLayoutOpts.Columns(5),
23			widget.GridLayoutOpts.DefaultStretch(true, true),
24		)),
25	)
26	colors := []color.Color{
27		colornames.Indianred,
28		colornames.Goldenrod,
29		colornames.Steelblue,
30		colornames.Mediumseagreen,
31		colornames.Darkslategray,
32	}
33	for y := 0; y < 5; y++ {
34		for x := 0; x < 5; x++ {
35			child := widget.NewContainer(
36				widget.ContainerOpts.BackgroundImage(
37					image.NewNineSliceColor(colors[(x+y)%len(colors)]),
38				),
39				widget.ContainerOpts.WidgetOpts(
40					widget.WidgetOpts.LayoutData(widget.GridLayoutData{}),
41					widget.WidgetOpts.MinSize(64, 64),
42				),
43				widget.ContainerOpts.Layout(widget.NewAnchorLayout()),
44			)
45			root.AddChild(child)
46		}
47	}
48
49	return &Game{
50		ui: &ebitenui.UI{Container: root},
51	}
52}
53
54func (g *Game) Update() error {
55	g.ui.Update()
56	return nil
57}
58
59func (g *Game) Draw(screen *ebiten.Image) {
60	g.ui.Draw(screen)
61}
62
63func (g *Game) Layout(w, h int) (int, int) {
64	return w, h
65}
66
67func main() {
68	ebiten.SetWindowSize(480, 320)
69	ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
70	if err := ebiten.RunGame(NewGame()); err != nil {
71		panic(err)
72	}
73}
 1child := widget.NewContainer(
 2	widget.ContainerOpts.BackgroundImage(
 3		image.NewNineSliceColor(colors[(x+y)%len(colors)]),
 4	),
 5	widget.ContainerOpts.WidgetOpts(
 6		widget.WidgetOpts.LayoutData(widget.GridLayoutData{
 7			MaxWidth: 32,
 8		}),
 9		widget.WidgetOpts.MinSize(64, 64),
10	),
11	widget.ContainerOpts.Layout(widget.NewAnchorLayout()),
12)

wid

 1package main
 2
 3import (
 4	"image/color"
 5	"github.com/ebitenui/ebitenui"
 6	"github.com/ebitenui/ebitenui/image"
 7	"github.com/ebitenui/ebitenui/widget"
 8	"github.com/hajimehoshi/ebiten/v2"
 9	"golang.org/x/image/colornames"
10)
11
12type Game struct {
13	ui *ebitenui.UI
14}
15
16func NewGame() *Game {
17	root := widget.NewContainer(
18		widget.ContainerOpts.BackgroundImage(
19			image.NewNineSliceColor(colornames.Gainsboro),
20		),
21		widget.ContainerOpts.Layout(widget.NewGridLayout(
22			widget.GridLayoutOpts.Columns(5),
23			widget.GridLayoutOpts.DefaultStretch(true, true),
24		)),
25	)
26	colors := []color.Color{
27		colornames.Indianred,
28		colornames.Goldenrod,
29		colornames.Steelblue,
30		colornames.Mediumseagreen,
31		colornames.Darkslategray,
32	}
33	for y := 0; y < 5; y++ {
34		for x := 0; x < 5; x++ {
35			child := widget.NewContainer(
36				widget.ContainerOpts.BackgroundImage(
37					image.NewNineSliceColor(colors[(x+y)%len(colors)]),
38				),
39				widget.ContainerOpts.WidgetOpts(
40					widget.WidgetOpts.LayoutData(widget.GridLayoutData{
41						MaxWidth: 32,
42					}),
43					widget.WidgetOpts.MinSize(64, 64),
44				),
45				widget.ContainerOpts.Layout(widget.NewAnchorLayout()),
46			)
47			root.AddChild(child)
48		}
49	}
50
51	return &Game{
52		ui: &ebitenui.UI{Container: root},
53	}
54}
55
56func (g *Game) Update() error {
57	g.ui.Update()
58	return nil
59}
60
61func (g *Game) Draw(screen *ebiten.Image) {
62	g.ui.Draw(screen)
63}
64
65func (g *Game) Layout(w, h int) (int, int) {
66	return w, h
67}
68
69func main() {
70	ebiten.SetWindowSize(480, 320)
71	ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
72	if err := ebiten.RunGame(NewGame()); err != nil {
73		panic(err)
74	}
75}
 1child := widget.NewContainer(
 2	widget.ContainerOpts.BackgroundImage(
 3		image.NewNineSliceColor(colors[(x+y)%len(colors)]),
 4	),
 5	widget.ContainerOpts.WidgetOpts(
 6		widget.WidgetOpts.LayoutData(widget.GridLayoutData{
 7			MaxHeight: 32,
 8		}),
 9		widget.WidgetOpts.MinSize(64, 64),
10	),
11	widget.ContainerOpts.Layout(widget.NewAnchorLayout()),
12)

hei

 1package main
 2
 3import (
 4	"image/color"
 5	"github.com/ebitenui/ebitenui"
 6	"github.com/ebitenui/ebitenui/image"
 7	"github.com/ebitenui/ebitenui/widget"
 8	"github.com/hajimehoshi/ebiten/v2"
 9	"golang.org/x/image/colornames"
10)
11
12type Game struct {
13	ui *ebitenui.UI
14}
15
16func NewGame() *Game {
17	root := widget.NewContainer(
18		widget.ContainerOpts.BackgroundImage(
19			image.NewNineSliceColor(colornames.Gainsboro),
20		),
21		widget.ContainerOpts.Layout(widget.NewGridLayout(
22			widget.GridLayoutOpts.Columns(5),
23			widget.GridLayoutOpts.DefaultStretch(true, true),
24		)),
25	)
26	colors := []color.Color{
27		colornames.Indianred,
28		colornames.Goldenrod,
29		colornames.Steelblue,
30		colornames.Mediumseagreen,
31		colornames.Darkslategray,
32	}
33	for y := 0; y < 5; y++ {
34		for x := 0; x < 5; x++ {
35			child := widget.NewContainer(
36				widget.ContainerOpts.BackgroundImage(
37					image.NewNineSliceColor(colors[(x+y)%len(colors)]),
38				),
39				widget.ContainerOpts.WidgetOpts(
40					widget.WidgetOpts.LayoutData(widget.GridLayoutData{
41						MaxHeight: 32,
42					}),
43					widget.WidgetOpts.MinSize(64, 64),
44				),
45				widget.ContainerOpts.Layout(widget.NewAnchorLayout()),
46			)
47			root.AddChild(child)
48		}
49	}
50
51	return &Game{
52		ui: &ebitenui.UI{Container: root},
53	}
54}
55
56func (g *Game) Update() error {
57	g.ui.Update()
58	return nil
59}
60
61func (g *Game) Draw(screen *ebiten.Image) {
62	g.ui.Draw(screen)
63}
64
65func (g *Game) Layout(w, h int) (int, int) {
66	return w, h
67}
68
69func main() {
70	ebiten.SetWindowSize(480, 320)
71	ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
72	if err := ebiten.RunGame(NewGame()); err != nil {
73		panic(err)
74	}
75}
 1child := widget.NewContainer(
 2	widget.ContainerOpts.BackgroundImage(
 3		image.NewNineSliceColor(colors[(x+y)%len(colors)]),
 4	),
 5	widget.ContainerOpts.WidgetOpts(
 6		widget.WidgetOpts.LayoutData(widget.GridLayoutData{
 7			MaxWidth:  32,
 8			MaxHeight: 32,
 9		}),
10		widget.WidgetOpts.MinSize(64, 64),
11	),
12	widget.ContainerOpts.Layout(widget.NewAnchorLayout()),
13)

wid

 1package main
 2
 3import (
 4	"image/color"
 5	"github.com/ebitenui/ebitenui"
 6	"github.com/ebitenui/ebitenui/image"
 7	"github.com/ebitenui/ebitenui/widget"
 8	"github.com/hajimehoshi/ebiten/v2"
 9	"golang.org/x/image/colornames"
10)
11
12type Game struct {
13	ui *ebitenui.UI
14}
15
16func NewGame() *Game {
17	root := widget.NewContainer(
18		widget.ContainerOpts.BackgroundImage(
19			image.NewNineSliceColor(colornames.Gainsboro),
20		),
21		widget.ContainerOpts.Layout(widget.NewGridLayout(
22			widget.GridLayoutOpts.Columns(5),
23			widget.GridLayoutOpts.DefaultStretch(true, true),
24		)),
25	)
26	colors := []color.Color{
27		colornames.Indianred,
28		colornames.Goldenrod,
29		colornames.Steelblue,
30		colornames.Mediumseagreen,
31		colornames.Darkslategray,
32	}
33	for y := 0; y < 5; y++ {
34		for x := 0; x < 5; x++ {
35			child := widget.NewContainer(
36				widget.ContainerOpts.BackgroundImage(
37					image.NewNineSliceColor(colors[(x+y)%len(colors)]),
38				),
39				widget.ContainerOpts.WidgetOpts(
40					widget.WidgetOpts.LayoutData(widget.GridLayoutData{
41						MaxWidth:  32,
42						MaxHeight: 32,
43					}),
44					widget.WidgetOpts.MinSize(64, 64),
45				),
46				widget.ContainerOpts.Layout(widget.NewAnchorLayout()),
47			)
48			root.AddChild(child)
49		}
50	}
51
52	return &Game{
53		ui: &ebitenui.UI{Container: root},
54	}
55}
56
57func (g *Game) Update() error {
58	g.ui.Update()
59	return nil
60}
61
62func (g *Game) Draw(screen *ebiten.Image) {
63	g.ui.Draw(screen)
64}
65
66func (g *Game) Layout(w, h int) (int, int) {
67	return w, h
68}
69
70func main() {
71	ebiten.SetWindowSize(480, 320)
72	ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
73	if err := ebiten.RunGame(NewGame()); err != nil {
74		panic(err)
75	}
76}
Position

Responsible for the allowable size of the child containers. It works when the size of the cells is so limited by the maximum size that it is smaller than the size of the stretched cells that there is free space between them.

Position:
 1child := widget.NewContainer(
 2	widget.ContainerOpts.BackgroundImage(
 3		image.NewNineSliceColor(colors[(x+y)%len(colors)]),
 4	),
 5	widget.ContainerOpts.WidgetOpts(
 6		widget.WidgetOpts.LayoutData(widget.GridLayoutData{
 7			MaxWidth:           32,
 8			MaxHeight:          32,
 9			HorizontalPosition: widget.GridLayoutPositionStart,
10			VerticalPosition:   widget.GridLayoutPositionStart,
11		}),
12		widget.WidgetOpts.MinSize(64, 64),
13	),
14	widget.ContainerOpts.Layout(widget.NewAnchorLayout()),
15)

wid

 1package main
 2
 3import (
 4	"image/color"
 5	"github.com/ebitenui/ebitenui"
 6	"github.com/ebitenui/ebitenui/image"
 7	"github.com/ebitenui/ebitenui/widget"
 8	"github.com/hajimehoshi/ebiten/v2"
 9	"golang.org/x/image/colornames"
10)
11
12type Game struct {
13	ui *ebitenui.UI
14}
15
16func NewGame() *Game {
17	root := widget.NewContainer(
18		widget.ContainerOpts.BackgroundImage(
19			image.NewNineSliceColor(colornames.Gainsboro),
20		),
21		widget.ContainerOpts.Layout(widget.NewGridLayout(
22			widget.GridLayoutOpts.Columns(5),
23			widget.GridLayoutOpts.DefaultStretch(true, true),
24		)),
25	)
26	colors := []color.Color{
27		colornames.Indianred,
28		colornames.Goldenrod,
29		colornames.Steelblue,
30		colornames.Mediumseagreen,
31		colornames.Darkslategray,
32	}
33	for y := 0; y < 5; y++ {
34		for x := 0; x < 5; x++ {
35			child := widget.NewContainer(
36				widget.ContainerOpts.BackgroundImage(
37					image.NewNineSliceColor(colors[(x+y)%len(colors)]),
38				),
39				widget.ContainerOpts.WidgetOpts(
40					widget.WidgetOpts.LayoutData(widget.GridLayoutData{
41						MaxWidth:           32,
42						MaxHeight:          32,
43						HorizontalPosition: widget.GridLayoutPositionStart,
44						VerticalPosition:   widget.GridLayoutPositionStart,
45					}),
46					widget.WidgetOpts.MinSize(64, 64),
47				),
48				widget.ContainerOpts.Layout(widget.NewAnchorLayout()),
49			)
50			root.AddChild(child)
51		}
52	}
53
54	return &Game{
55		ui: &ebitenui.UI{Container: root},
56	}
57}
58
59func (g *Game) Update() error {
60	g.ui.Update()
61	return nil
62}
63
64func (g *Game) Draw(screen *ebiten.Image) {
65	g.ui.Draw(screen)
66}
67
68func (g *Game) Layout(w, h int) (int, int) {
69	return w, h
70}
71
72func main() {
73	ebiten.SetWindowSize(480, 320)
74	ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
75	if err := ebiten.RunGame(NewGame()); err != nil {
76		panic(err)
77	}
78}
 1child := widget.NewContainer(
 2	widget.ContainerOpts.BackgroundImage(
 3		image.NewNineSliceColor(colors[(x+y)%len(colors)]),
 4	),
 5	widget.ContainerOpts.WidgetOpts(
 6		widget.WidgetOpts.LayoutData(widget.GridLayoutData{
 7			MaxWidth:           32,
 8			MaxHeight:          32,
 9			HorizontalPosition: widget.GridLayoutPositionCenter,
10			VerticalPosition:   widget.GridLayoutPositionStart,
11		}),
12		widget.WidgetOpts.MinSize(64, 64),
13	),
14	widget.ContainerOpts.Layout(widget.NewAnchorLayout()),
15)

wid

 1package main
 2
 3import (
 4	"image/color"
 5	"github.com/ebitenui/ebitenui"
 6	"github.com/ebitenui/ebitenui/image"
 7	"github.com/ebitenui/ebitenui/widget"
 8	"github.com/hajimehoshi/ebiten/v2"
 9	"golang.org/x/image/colornames"
10)
11
12type Game struct {
13	ui *ebitenui.UI
14}
15
16func NewGame() *Game {
17	root := widget.NewContainer(
18		widget.ContainerOpts.BackgroundImage(
19			image.NewNineSliceColor(colornames.Gainsboro),
20		),
21		widget.ContainerOpts.Layout(widget.NewGridLayout(
22			widget.GridLayoutOpts.Columns(5),
23			widget.GridLayoutOpts.DefaultStretch(true, true),
24		)),
25	)
26	colors := []color.Color{
27		colornames.Indianred,
28		colornames.Goldenrod,
29		colornames.Steelblue,
30		colornames.Mediumseagreen,
31		colornames.Darkslategray,
32	}
33	for y := 0; y < 5; y++ {
34		for x := 0; x < 5; x++ {
35			child := widget.NewContainer(
36				widget.ContainerOpts.BackgroundImage(
37					image.NewNineSliceColor(colors[(x+y)%len(colors)]),
38				),
39				widget.ContainerOpts.WidgetOpts(
40					widget.WidgetOpts.LayoutData(widget.GridLayoutData{
41						MaxWidth:           32,
42						MaxHeight:          32,
43						HorizontalPosition: widget.GridLayoutPositionCenter,
44						VerticalPosition:   widget.GridLayoutPositionStart,
45					}),
46					widget.WidgetOpts.MinSize(64, 64),
47				),
48				widget.ContainerOpts.Layout(widget.NewAnchorLayout()),
49			)
50			root.AddChild(child)
51		}
52	}
53
54	return &Game{
55		ui: &ebitenui.UI{Container: root},
56	}
57}
58
59func (g *Game) Update() error {
60	g.ui.Update()
61	return nil
62}
63
64func (g *Game) Draw(screen *ebiten.Image) {
65	g.ui.Draw(screen)
66}
67
68func (g *Game) Layout(w, h int) (int, int) {
69	return w, h
70}
71
72func main() {
73	ebiten.SetWindowSize(480, 320)
74	ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
75	if err := ebiten.RunGame(NewGame()); err != nil {
76		panic(err)
77	}
78}
 1child := widget.NewContainer(
 2	widget.ContainerOpts.BackgroundImage(
 3		image.NewNineSliceColor(colors[(x+y)%len(colors)]),
 4	),
 5	widget.ContainerOpts.WidgetOpts(
 6		widget.WidgetOpts.LayoutData(widget.GridLayoutData{
 7			MaxWidth:           32,
 8			MaxHeight:          32,
 9			HorizontalPosition: widget.GridLayoutPositionEnd,
10			VerticalPosition:   widget.GridLayoutPositionStart,
11		}),
12		widget.WidgetOpts.MinSize(64, 64),
13	),
14	widget.ContainerOpts.Layout(widget.NewAnchorLayout()),
15)

hei

 1package main
 2
 3import (
 4	"image/color"
 5	"github.com/ebitenui/ebitenui"
 6	"github.com/ebitenui/ebitenui/image"
 7	"github.com/ebitenui/ebitenui/widget"
 8	"github.com/hajimehoshi/ebiten/v2"
 9	"golang.org/x/image/colornames"
10)
11
12type Game struct {
13	ui *ebitenui.UI
14}
15
16func NewGame() *Game {
17	root := widget.NewContainer(
18		widget.ContainerOpts.BackgroundImage(
19			image.NewNineSliceColor(colornames.Gainsboro),
20		),
21		widget.ContainerOpts.Layout(widget.NewGridLayout(
22			widget.GridLayoutOpts.Columns(5),
23			widget.GridLayoutOpts.DefaultStretch(true, true),
24		)),
25	)
26	colors := []color.Color{
27		colornames.Indianred,
28		colornames.Goldenrod,
29		colornames.Steelblue,
30		colornames.Mediumseagreen,
31		colornames.Darkslategray,
32	}
33	for y := 0; y < 5; y++ {
34		for x := 0; x < 5; x++ {
35			child := widget.NewContainer(
36				widget.ContainerOpts.BackgroundImage(
37					image.NewNineSliceColor(colors[(x+y)%len(colors)]),
38				),
39				widget.ContainerOpts.WidgetOpts(
40					widget.WidgetOpts.LayoutData(widget.GridLayoutData{
41						MaxWidth:           32,
42						MaxHeight:          32,
43						HorizontalPosition: widget.GridLayoutPositionEnd,
44						VerticalPosition:   widget.GridLayoutPositionStart,
45					}),
46					widget.WidgetOpts.MinSize(64, 64),
47				),
48				widget.ContainerOpts.Layout(widget.NewAnchorLayout()),
49			)
50			root.AddChild(child)
51		}
52	}
53
54	return &Game{
55		ui: &ebitenui.UI{Container: root},
56	}
57}
58
59func (g *Game) Update() error {
60	g.ui.Update()
61	return nil
62}
63
64func (g *Game) Draw(screen *ebiten.Image) {
65	g.ui.Draw(screen)
66}
67
68func (g *Game) Layout(w, h int) (int, int) {
69	return w, h
70}
71
72func main() {
73	ebiten.SetWindowSize(480, 320)
74	ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
75	if err := ebiten.RunGame(NewGame()); err != nil {
76		panic(err)
77	}
78}
 1child := widget.NewContainer(
 2	widget.ContainerOpts.BackgroundImage(
 3		image.NewNineSliceColor(colors[(x+y)%len(colors)]),
 4	),
 5	widget.ContainerOpts.WidgetOpts(
 6		widget.WidgetOpts.LayoutData(widget.GridLayoutData{
 7			MaxWidth:           32,
 8			MaxHeight:          32,
 9			HorizontalPosition: widget.GridLayoutPositionStart,
10			VerticalPosition:   widget.GridLayoutPositionCenter,
11		}),
12		widget.WidgetOpts.MinSize(64, 64),
13	),
14	widget.ContainerOpts.Layout(widget.NewAnchorLayout()),
15)

wid

 1package main
 2
 3import (
 4	"image/color"
 5	"github.com/ebitenui/ebitenui"
 6	"github.com/ebitenui/ebitenui/image"
 7	"github.com/ebitenui/ebitenui/widget"
 8	"github.com/hajimehoshi/ebiten/v2"
 9	"golang.org/x/image/colornames"
10)
11
12type Game struct {
13	ui *ebitenui.UI
14}
15
16func NewGame() *Game {
17	root := widget.NewContainer(
18		widget.ContainerOpts.BackgroundImage(
19			image.NewNineSliceColor(colornames.Gainsboro),
20		),
21		widget.ContainerOpts.Layout(widget.NewGridLayout(
22			widget.GridLayoutOpts.Columns(5),
23			widget.GridLayoutOpts.DefaultStretch(true, true),
24		)),
25	)
26	colors := []color.Color{
27		colornames.Indianred,
28		colornames.Goldenrod,
29		colornames.Steelblue,
30		colornames.Mediumseagreen,
31		colornames.Darkslategray,
32	}
33	for y := 0; y < 5; y++ {
34		for x := 0; x < 5; x++ {
35			child := widget.NewContainer(
36				widget.ContainerOpts.BackgroundImage(
37					image.NewNineSliceColor(colors[(x+y)%len(colors)]),
38				),
39				widget.ContainerOpts.WidgetOpts(
40					widget.WidgetOpts.LayoutData(widget.GridLayoutData{
41						MaxWidth:           32,
42						MaxHeight:          32,
43						HorizontalPosition: widget.GridLayoutPositionStart,
44						VerticalPosition:   widget.GridLayoutPositionCenter,
45					}),
46					widget.WidgetOpts.MinSize(64, 64),
47				),
48				widget.ContainerOpts.Layout(widget.NewAnchorLayout()),
49			)
50			root.AddChild(child)
51		}
52	}
53
54	return &Game{
55		ui: &ebitenui.UI{Container: root},
56	}
57}
58
59func (g *Game) Update() error {
60	g.ui.Update()
61	return nil
62}
63
64func (g *Game) Draw(screen *ebiten.Image) {
65	g.ui.Draw(screen)
66}
67
68func (g *Game) Layout(w, h int) (int, int) {
69	return w, h
70}
71
72func main() {
73	ebiten.SetWindowSize(480, 320)
74	ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
75	if err := ebiten.RunGame(NewGame()); err != nil {
76		panic(err)
77	}
78}
 1child := widget.NewContainer(
 2	widget.ContainerOpts.BackgroundImage(
 3		image.NewNineSliceColor(colors[(x+y)%len(colors)]),
 4	),
 5	widget.ContainerOpts.WidgetOpts(
 6		widget.WidgetOpts.LayoutData(widget.GridLayoutData{
 7			MaxWidth:           32,
 8			MaxHeight:          32,
 9			HorizontalPosition: widget.GridLayoutPositionCenter,
10			VerticalPosition:   widget.GridLayoutPositionCenter,
11		}),
12		widget.WidgetOpts.MinSize(64, 64),
13	),
14	widget.ContainerOpts.Layout(widget.NewAnchorLayout()),
15)

wid

 1package main
 2
 3import (
 4	"image/color"
 5	"github.com/ebitenui/ebitenui"
 6	"github.com/ebitenui/ebitenui/image"
 7	"github.com/ebitenui/ebitenui/widget"
 8	"github.com/hajimehoshi/ebiten/v2"
 9	"golang.org/x/image/colornames"
10)
11
12type Game struct {
13	ui *ebitenui.UI
14}
15
16func NewGame() *Game {
17	root := widget.NewContainer(
18		widget.ContainerOpts.BackgroundImage(
19			image.NewNineSliceColor(colornames.Gainsboro),
20		),
21		widget.ContainerOpts.Layout(widget.NewGridLayout(
22			widget.GridLayoutOpts.Columns(5),
23			widget.GridLayoutOpts.DefaultStretch(true, true),
24		)),
25	)
26	colors := []color.Color{
27		colornames.Indianred,
28		colornames.Goldenrod,
29		colornames.Steelblue,
30		colornames.Mediumseagreen,
31		colornames.Darkslategray,
32	}
33	for y := 0; y < 5; y++ {
34		for x := 0; x < 5; x++ {
35			child := widget.NewContainer(
36				widget.ContainerOpts.BackgroundImage(
37					image.NewNineSliceColor(colors[(x+y)%len(colors)]),
38				),
39				widget.ContainerOpts.WidgetOpts(
40					widget.WidgetOpts.LayoutData(widget.GridLayoutData{
41						MaxWidth:           32,
42						MaxHeight:          32,
43						HorizontalPosition: widget.GridLayoutPositionCenter,
44						VerticalPosition:   widget.GridLayoutPositionCenter,
45					}),
46					widget.WidgetOpts.MinSize(64, 64),
47				),
48				widget.ContainerOpts.Layout(widget.NewAnchorLayout()),
49			)
50			root.AddChild(child)
51		}
52	}
53
54	return &Game{
55		ui: &ebitenui.UI{Container: root},
56	}
57}
58
59func (g *Game) Update() error {
60	g.ui.Update()
61	return nil
62}
63
64func (g *Game) Draw(screen *ebiten.Image) {
65	g.ui.Draw(screen)
66}
67
68func (g *Game) Layout(w, h int) (int, int) {
69	return w, h
70}
71
72func main() {
73	ebiten.SetWindowSize(480, 320)
74	ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
75	if err := ebiten.RunGame(NewGame()); err != nil {
76		panic(err)
77	}
78}
 1child := widget.NewContainer(
 2	widget.ContainerOpts.BackgroundImage(
 3		image.NewNineSliceColor(colors[(x+y)%len(colors)]),
 4	),
 5	widget.ContainerOpts.WidgetOpts(
 6		widget.WidgetOpts.LayoutData(widget.GridLayoutData{
 7			MaxWidth:           32,
 8			MaxHeight:          32,
 9			HorizontalPosition: widget.GridLayoutPositionEnd,
10			VerticalPosition:   widget.GridLayoutPositionCenter,
11		}),
12		widget.WidgetOpts.MinSize(64, 64),
13	),
14	widget.ContainerOpts.Layout(widget.NewAnchorLayout()),
15)

wid

 1package main
 2
 3import (
 4	"image/color"
 5	"github.com/ebitenui/ebitenui"
 6	"github.com/ebitenui/ebitenui/image"
 7	"github.com/ebitenui/ebitenui/widget"
 8	"github.com/hajimehoshi/ebiten/v2"
 9	"golang.org/x/image/colornames"
10)
11
12type Game struct {
13	ui *ebitenui.UI
14}
15
16func NewGame() *Game {
17	root := widget.NewContainer(
18		widget.ContainerOpts.BackgroundImage(
19			image.NewNineSliceColor(colornames.Gainsboro),
20		),
21		widget.ContainerOpts.Layout(widget.NewGridLayout(
22			widget.GridLayoutOpts.Columns(5),
23			widget.GridLayoutOpts.DefaultStretch(true, true),
24		)),
25	)
26	colors := []color.Color{
27		colornames.Indianred,
28		colornames.Goldenrod,
29		colornames.Steelblue,
30		colornames.Mediumseagreen,
31		colornames.Darkslategray,
32	}
33	for y := 0; y < 5; y++ {
34		for x := 0; x < 5; x++ {
35			child := widget.NewContainer(
36				widget.ContainerOpts.BackgroundImage(
37					image.NewNineSliceColor(colors[(x+y)%len(colors)]),
38				),
39				widget.ContainerOpts.WidgetOpts(
40					widget.WidgetOpts.LayoutData(widget.GridLayoutData{
41						MaxWidth:           32,
42						MaxHeight:          32,
43						HorizontalPosition: widget.GridLayoutPositionEnd,
44						VerticalPosition:   widget.GridLayoutPositionCenter,
45					}),
46					widget.WidgetOpts.MinSize(64, 64),
47				),
48				widget.ContainerOpts.Layout(widget.NewAnchorLayout()),
49			)
50			root.AddChild(child)
51		}
52	}
53
54	return &Game{
55		ui: &ebitenui.UI{Container: root},
56	}
57}
58
59func (g *Game) Update() error {
60	g.ui.Update()
61	return nil
62}
63
64func (g *Game) Draw(screen *ebiten.Image) {
65	g.ui.Draw(screen)
66}
67
68func (g *Game) Layout(w, h int) (int, int) {
69	return w, h
70}
71
72func main() {
73	ebiten.SetWindowSize(480, 320)
74	ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
75	if err := ebiten.RunGame(NewGame()); err != nil {
76		panic(err)
77	}
78}
 1child := widget.NewContainer(
 2	widget.ContainerOpts.BackgroundImage(
 3		image.NewNineSliceColor(colors[(x+y)%len(colors)]),
 4	),
 5	widget.ContainerOpts.WidgetOpts(
 6		widget.WidgetOpts.LayoutData(widget.GridLayoutData{
 7			MaxWidth:           32,
 8			MaxHeight:          32,
 9			HorizontalPosition: widget.GridLayoutPositionStart,
10			VerticalPosition:   widget.GridLayoutPositionEnd,
11		}),
12		widget.WidgetOpts.MinSize(64, 64),
13	),
14	widget.ContainerOpts.Layout(widget.NewAnchorLayout()),
15)

wid

 1package main
 2
 3import (
 4	"image/color"
 5	"github.com/ebitenui/ebitenui"
 6	"github.com/ebitenui/ebitenui/image"
 7	"github.com/ebitenui/ebitenui/widget"
 8	"github.com/hajimehoshi/ebiten/v2"
 9	"golang.org/x/image/colornames"
10)
11
12type Game struct {
13	ui *ebitenui.UI
14}
15
16func NewGame() *Game {
17	root := widget.NewContainer(
18		widget.ContainerOpts.BackgroundImage(
19			image.NewNineSliceColor(colornames.Gainsboro),
20		),
21		widget.ContainerOpts.Layout(widget.NewGridLayout(
22			widget.GridLayoutOpts.Columns(5),
23			widget.GridLayoutOpts.DefaultStretch(true, true),
24		)),
25	)
26	colors := []color.Color{
27		colornames.Indianred,
28		colornames.Goldenrod,
29		colornames.Steelblue,
30		colornames.Mediumseagreen,
31		colornames.Darkslategray,
32	}
33	for y := 0; y < 5; y++ {
34		for x := 0; x < 5; x++ {
35			child := widget.NewContainer(
36				widget.ContainerOpts.BackgroundImage(
37					image.NewNineSliceColor(colors[(x+y)%len(colors)]),
38				),
39				widget.ContainerOpts.WidgetOpts(
40					widget.WidgetOpts.LayoutData(widget.GridLayoutData{
41						MaxWidth:           32,
42						MaxHeight:          32,
43						HorizontalPosition: widget.GridLayoutPositionStart,
44						VerticalPosition:   widget.GridLayoutPositionEnd,
45					}),
46					widget.WidgetOpts.MinSize(64, 64),
47				),
48				widget.ContainerOpts.Layout(widget.NewAnchorLayout()),
49			)
50			root.AddChild(child)
51		}
52	}
53
54	return &Game{
55		ui: &ebitenui.UI{Container: root},
56	}
57}
58
59func (g *Game) Update() error {
60	g.ui.Update()
61	return nil
62}
63
64func (g *Game) Draw(screen *ebiten.Image) {
65	g.ui.Draw(screen)
66}
67
68func (g *Game) Layout(w, h int) (int, int) {
69	return w, h
70}
71
72func main() {
73	ebiten.SetWindowSize(480, 320)
74	ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
75	if err := ebiten.RunGame(NewGame()); err != nil {
76		panic(err)
77	}
78}
 1child := widget.NewContainer(
 2	widget.ContainerOpts.BackgroundImage(
 3		image.NewNineSliceColor(colors[(x+y)%len(colors)]),
 4	),
 5	widget.ContainerOpts.WidgetOpts(
 6		widget.WidgetOpts.LayoutData(widget.GridLayoutData{
 7			MaxWidth:           32,
 8			MaxHeight:          32,
 9			HorizontalPosition: widget.GridLayoutPositionCenter,
10			VerticalPosition:   widget.GridLayoutPositionEnd,
11		}),
12		widget.WidgetOpts.MinSize(64, 64),
13	),
14	widget.ContainerOpts.Layout(widget.NewAnchorLayout()),
15)

wid

 1package main
 2
 3import (
 4	"image/color"
 5	"github.com/ebitenui/ebitenui"
 6	"github.com/ebitenui/ebitenui/image"
 7	"github.com/ebitenui/ebitenui/widget"
 8	"github.com/hajimehoshi/ebiten/v2"
 9	"golang.org/x/image/colornames"
10)
11
12type Game struct {
13	ui *ebitenui.UI
14}
15
16func NewGame() *Game {
17	root := widget.NewContainer(
18		widget.ContainerOpts.BackgroundImage(
19			image.NewNineSliceColor(colornames.Gainsboro),
20		),
21		widget.ContainerOpts.Layout(widget.NewGridLayout(
22			widget.GridLayoutOpts.Columns(5),
23			widget.GridLayoutOpts.DefaultStretch(true, true),
24		)),
25	)
26	colors := []color.Color{
27		colornames.Indianred,
28		colornames.Goldenrod,
29		colornames.Steelblue,
30		colornames.Mediumseagreen,
31		colornames.Darkslategray,
32	}
33	for y := 0; y < 5; y++ {
34		for x := 0; x < 5; x++ {
35			child := widget.NewContainer(
36				widget.ContainerOpts.BackgroundImage(
37					image.NewNineSliceColor(colors[(x+y)%len(colors)]),
38				),
39				widget.ContainerOpts.WidgetOpts(
40					widget.WidgetOpts.LayoutData(widget.GridLayoutData{
41						MaxWidth:           32,
42						MaxHeight:          32,
43						HorizontalPosition: widget.GridLayoutPositionCenter,
44						VerticalPosition:   widget.GridLayoutPositionEnd,
45					}),
46					widget.WidgetOpts.MinSize(64, 64),
47				),
48				widget.ContainerOpts.Layout(widget.NewAnchorLayout()),
49			)
50			root.AddChild(child)
51		}
52	}
53
54	return &Game{
55		ui: &ebitenui.UI{Container: root},
56	}
57}
58
59func (g *Game) Update() error {
60	g.ui.Update()
61	return nil
62}
63
64func (g *Game) Draw(screen *ebiten.Image) {
65	g.ui.Draw(screen)
66}
67
68func (g *Game) Layout(w, h int) (int, int) {
69	return w, h
70}
71
72func main() {
73	ebiten.SetWindowSize(480, 320)
74	ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
75	if err := ebiten.RunGame(NewGame()); err != nil {
76		panic(err)
77	}
78}
 1child := widget.NewContainer(
 2	widget.ContainerOpts.BackgroundImage(
 3		image.NewNineSliceColor(colors[(x+y)%len(colors)]),
 4	),
 5	widget.ContainerOpts.WidgetOpts(
 6		widget.WidgetOpts.LayoutData(widget.GridLayoutData{
 7			MaxWidth:           32,
 8			MaxHeight:          32,
 9			HorizontalPosition: widget.GridLayoutPositionEnd,
10			VerticalPosition:   widget.GridLayoutPositionEnd,
11		}),
12		widget.WidgetOpts.MinSize(64, 64),
13	),
14	widget.ContainerOpts.Layout(widget.NewAnchorLayout()),
15)

wid

 1package main
 2
 3import (
 4	"image/color"
 5	"github.com/ebitenui/ebitenui"
 6	"github.com/ebitenui/ebitenui/image"
 7	"github.com/ebitenui/ebitenui/widget"
 8	"github.com/hajimehoshi/ebiten/v2"
 9	"golang.org/x/image/colornames"
10)
11
12type Game struct {
13	ui *ebitenui.UI
14}
15
16func NewGame() *Game {
17	root := widget.NewContainer(
18		widget.ContainerOpts.BackgroundImage(
19			image.NewNineSliceColor(colornames.Gainsboro),
20		),
21		widget.ContainerOpts.Layout(widget.NewGridLayout(
22			widget.GridLayoutOpts.Columns(5),
23			widget.GridLayoutOpts.DefaultStretch(true, true),
24		)),
25	)
26	colors := []color.Color{
27		colornames.Indianred,
28		colornames.Goldenrod,
29		colornames.Steelblue,
30		colornames.Mediumseagreen,
31		colornames.Darkslategray,
32	}
33	for y := 0; y < 5; y++ {
34		for x := 0; x < 5; x++ {
35			child := widget.NewContainer(
36				widget.ContainerOpts.BackgroundImage(
37					image.NewNineSliceColor(colors[(x+y)%len(colors)]),
38				),
39				widget.ContainerOpts.WidgetOpts(
40					widget.WidgetOpts.LayoutData(widget.GridLayoutData{
41						MaxWidth:           32,
42						MaxHeight:          32,
43						HorizontalPosition: widget.GridLayoutPositionEnd,
44						VerticalPosition:   widget.GridLayoutPositionEnd,
45					}),
46					widget.WidgetOpts.MinSize(64, 64),
47				),
48				widget.ContainerOpts.Layout(widget.NewAnchorLayout()),
49			)
50			root.AddChild(child)
51		}
52	}
53
54	return &Game{
55		ui: &ebitenui.UI{Container: root},
56	}
57}
58
59func (g *Game) Update() error {
60	g.ui.Update()
61	return nil
62}
63
64func (g *Game) Draw(screen *ebiten.Image) {
65	g.ui.Draw(screen)
66}
67
68func (g *Game) Layout(w, h int) (int, int) {
69	return w, h
70}
71
72func main() {
73	ebiten.SetWindowSize(480, 320)
74	ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
75	if err := ebiten.RunGame(NewGame()); err != nil {
76		panic(err)
77	}
78}