Row
Row layout places all child containers in one row or column. It can be useful for creating lists of widgets.
1package main
2
3import (
4 "github.com/ebitenui/ebitenui"
5 "github.com/ebitenui/ebitenui/image"
6 "github.com/ebitenui/ebitenui/widget"
7 "github.com/hajimehoshi/ebiten/v2"
8 "golang.org/x/image/colornames"
9)
10
11type Game struct {
12 ui *ebitenui.UI
13}
14
15func NewGame() *Game {
16 a := widget.NewContainer(
17 widget.ContainerOpts.BackgroundImage(
18 image.NewNineSliceColor(colornames.Indianred),
19 ),
20 widget.ContainerOpts.WidgetOpts(
21 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
22 Stretch: true,
23 }),
24 widget.WidgetOpts.MinSize(96, 50),
25 ),
26 )
27 b := widget.NewContainer(
28 widget.ContainerOpts.BackgroundImage(
29 image.NewNineSliceColor(colornames.Goldenrod),
30 ),
31 widget.ContainerOpts.WidgetOpts(
32 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
33 Stretch: true,
34 }),
35 widget.WidgetOpts.MinSize(96, 50),
36 ),
37 )
38 c := widget.NewContainer(
39 widget.ContainerOpts.BackgroundImage(
40 image.NewNineSliceColor(colornames.Steelblue),
41 ),
42 widget.ContainerOpts.WidgetOpts(
43 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
44 Stretch: true,
45 }),
46 widget.WidgetOpts.MinSize(96, 50),
47 ),
48 )
49 d := widget.NewContainer(
50 widget.ContainerOpts.BackgroundImage(
51 image.NewNineSliceColor(colornames.Mediumseagreen),
52 ),
53 widget.ContainerOpts.WidgetOpts(
54 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
55 Stretch: true,
56 }),
57 widget.WidgetOpts.MinSize(96, 50),
58 ),
59 )
60 e := widget.NewContainer(
61 widget.ContainerOpts.BackgroundImage(
62 image.NewNineSliceColor(colornames.Darkslategray),
63 ),
64 widget.ContainerOpts.WidgetOpts(
65 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
66 Stretch: true,
67 }),
68 widget.WidgetOpts.MinSize(96, 50),
69 ),
70 )
71 root := widget.NewContainer(
72 widget.ContainerOpts.BackgroundImage(
73 image.NewNineSliceColor(colornames.Gainsboro),
74 ),
75 widget.ContainerOpts.Layout(widget.NewRowLayout(
76 widget.RowLayoutOpts.Direction(
77 widget.DirectionVertical,
78 ),
79 widget.RowLayoutOpts.Spacing(5),
80 widget.RowLayoutOpts.Padding(widget.NewInsetsSimple(25)),
81 )),
82 )
83 root.AddChild(a)
84 root.AddChild(b)
85 root.AddChild(c)
86 root.AddChild(d)
87 root.AddChild(e)
88
89 return &Game{
90 ui: &ebitenui.UI{Container: root},
91 }
92}
93
94func (g *Game) Update() error {
95 g.ui.Update()
96 return nil
97}
98
99func (g *Game) Draw(screen *ebiten.Image) {
100 g.ui.Draw(screen)
101}
102
103func (g *Game) Layout(w, h int) (int, int) {
104 return w, h
105}
106
107func main() {
108 ebiten.SetWindowSize(480, 320)
109 ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
110 if err := ebiten.RunGame(NewGame()); err != nil {
111 panic(err)
112 }
113}
Layout options
Direction
Responsible for whether child containers will follow each other in rows or columns.
Direction:
1root := widget.NewContainer(
2 widget.ContainerOpts.BackgroundImage(
3 image.NewNineSliceColor(colornames.Gainsboro),
4 ),
5 widget.ContainerOpts.Layout(widget.NewRowLayout(
6 widget.RowLayoutOpts.Direction(
7 widget.DirectionVertical,
8 ),
9 )),
10)
1package main
2
3import (
4 "github.com/ebitenui/ebitenui"
5 "github.com/ebitenui/ebitenui/image"
6 "github.com/ebitenui/ebitenui/widget"
7 "github.com/hajimehoshi/ebiten/v2"
8 "golang.org/x/image/colornames"
9)
10
11type Game struct {
12 ui *ebitenui.UI
13}
14
15func NewGame() *Game {
16 a := widget.NewContainer(
17 widget.ContainerOpts.BackgroundImage(
18 image.NewNineSliceColor(colornames.Indianred),
19 ),
20 widget.ContainerOpts.WidgetOpts(
21 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
22 Stretch: true,
23 }),
24 widget.WidgetOpts.MinSize(96, 64),
25 ),
26 )
27 b := widget.NewContainer(
28 widget.ContainerOpts.BackgroundImage(
29 image.NewNineSliceColor(colornames.Goldenrod),
30 ),
31 widget.ContainerOpts.WidgetOpts(
32 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
33 Stretch: true,
34 }),
35 widget.WidgetOpts.MinSize(96, 64),
36 ),
37 )
38 c := widget.NewContainer(
39 widget.ContainerOpts.BackgroundImage(
40 image.NewNineSliceColor(colornames.Steelblue),
41 ),
42 widget.ContainerOpts.WidgetOpts(
43 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
44 Stretch: true,
45 }),
46 widget.WidgetOpts.MinSize(96, 64),
47 ),
48 )
49 d := widget.NewContainer(
50 widget.ContainerOpts.BackgroundImage(
51 image.NewNineSliceColor(colornames.Mediumseagreen),
52 ),
53 widget.ContainerOpts.WidgetOpts(
54 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
55 Stretch: true,
56 }),
57 widget.WidgetOpts.MinSize(96, 64),
58 ),
59 )
60 e := widget.NewContainer(
61 widget.ContainerOpts.BackgroundImage(
62 image.NewNineSliceColor(colornames.Darkslategray),
63 ),
64 widget.ContainerOpts.WidgetOpts(
65 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
66 Stretch: true,
67 }),
68 widget.WidgetOpts.MinSize(96, 64),
69 ),
70 )
71 root := widget.NewContainer(
72 widget.ContainerOpts.BackgroundImage(
73 image.NewNineSliceColor(colornames.Gainsboro),
74 ),
75 widget.ContainerOpts.Layout(widget.NewRowLayout(
76 widget.RowLayoutOpts.Direction(
77 widget.DirectionVertical,
78 ),
79 )),
80 )
81 root.AddChild(a)
82 root.AddChild(b)
83 root.AddChild(c)
84 root.AddChild(d)
85 root.AddChild(e)
86
87 return &Game{
88 ui: &ebitenui.UI{Container: root},
89 }
90}
91
92func (g *Game) Update() error {
93 g.ui.Update()
94 return nil
95}
96
97func (g *Game) Draw(screen *ebiten.Image) {
98 g.ui.Draw(screen)
99}
100
101func (g *Game) Layout(w, h int) (int, int) {
102 return w, h
103}
104
105func main() {
106 ebiten.SetWindowSize(480, 320)
107 ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
108 if err := ebiten.RunGame(NewGame()); err != nil {
109 panic(err)
110 }
111}
1root := widget.NewContainer(
2 widget.ContainerOpts.BackgroundImage(
3 image.NewNineSliceColor(colornames.Gainsboro),
4 ),
5 widget.ContainerOpts.Layout(widget.NewRowLayout(
6 widget.RowLayoutOpts.Direction(
7 widget.DirectionHorizontal,
8 ),
9 )),
10)
1package main
2
3import (
4 "github.com/ebitenui/ebitenui"
5 "github.com/ebitenui/ebitenui/image"
6 "github.com/ebitenui/ebitenui/widget"
7 "github.com/hajimehoshi/ebiten/v2"
8 "golang.org/x/image/colornames"
9)
10
11type Game struct {
12 ui *ebitenui.UI
13}
14
15func NewGame() *Game {
16 a := widget.NewContainer(
17 widget.ContainerOpts.BackgroundImage(
18 image.NewNineSliceColor(colornames.Indianred),
19 ),
20 widget.ContainerOpts.WidgetOpts(
21 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
22 Stretch: true,
23 }),
24 widget.WidgetOpts.MinSize(96, 64),
25 ),
26 )
27 b := widget.NewContainer(
28 widget.ContainerOpts.BackgroundImage(
29 image.NewNineSliceColor(colornames.Goldenrod),
30 ),
31 widget.ContainerOpts.WidgetOpts(
32 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
33 Stretch: true,
34 }),
35 widget.WidgetOpts.MinSize(96, 64),
36 ),
37 )
38 c := widget.NewContainer(
39 widget.ContainerOpts.BackgroundImage(
40 image.NewNineSliceColor(colornames.Steelblue),
41 ),
42 widget.ContainerOpts.WidgetOpts(
43 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
44 Stretch: true,
45 }),
46 widget.WidgetOpts.MinSize(96, 64),
47 ),
48 )
49 d := widget.NewContainer(
50 widget.ContainerOpts.BackgroundImage(
51 image.NewNineSliceColor(colornames.Mediumseagreen),
52 ),
53 widget.ContainerOpts.WidgetOpts(
54 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
55 Stretch: true,
56 }),
57 widget.WidgetOpts.MinSize(96, 64),
58 ),
59 )
60 e := widget.NewContainer(
61 widget.ContainerOpts.BackgroundImage(
62 image.NewNineSliceColor(colornames.Darkslategray),
63 ),
64 widget.ContainerOpts.WidgetOpts(
65 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
66 Stretch: true,
67 }),
68 widget.WidgetOpts.MinSize(96, 64),
69 ),
70 )
71 root := widget.NewContainer(
72 widget.ContainerOpts.BackgroundImage(
73 image.NewNineSliceColor(colornames.Gainsboro),
74 ),
75 widget.ContainerOpts.Layout(widget.NewRowLayout(
76 widget.RowLayoutOpts.Direction(
77 widget.DirectionHorizontal,
78 ),
79 )),
80 )
81 root.AddChild(a)
82 root.AddChild(b)
83 root.AddChild(c)
84 root.AddChild(d)
85 root.AddChild(e)
86
87 return &Game{
88 ui: &ebitenui.UI{Container: root},
89 }
90}
91
92func (g *Game) Update() error {
93 g.ui.Update()
94 return nil
95}
96
97func (g *Game) Draw(screen *ebiten.Image) {
98 g.ui.Draw(screen)
99}
100
101func (g *Game) Layout(w, h int) (int, int) {
102 return w, h
103}
104
105func main() {
106 ebiten.SetWindowSize(480, 320)
107 ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
108 if err := ebiten.RunGame(NewGame()); err != nil {
109 panic(err)
110 }
111}
Padding
Layout allows you to specify padding for all child elements but not the itself. Please note that its not possible to specify padding at the end, so the direction will changed accordingly.
Padding:
1root := widget.NewContainer(
2 widget.ContainerOpts.BackgroundImage(
3 image.NewNineSliceColor(colornames.Gainsboro),
4 ),
5 widget.ContainerOpts.Layout(widget.NewRowLayout(
6 widget.RowLayoutOpts.Direction(
7 widget.DirectionVertical,
8 ),
9 widget.RowLayoutOpts.Padding(widget.Insets{
10 Left: 50,
11 }),
12 )),
13)
1package main
2
3import (
4 "github.com/ebitenui/ebitenui"
5 "github.com/ebitenui/ebitenui/image"
6 "github.com/ebitenui/ebitenui/widget"
7 "github.com/hajimehoshi/ebiten/v2"
8 "golang.org/x/image/colornames"
9)
10
11type Game struct {
12 ui *ebitenui.UI
13}
14
15func NewGame() *Game {
16 a := widget.NewContainer(
17 widget.ContainerOpts.BackgroundImage(
18 image.NewNineSliceColor(colornames.Indianred),
19 ),
20 widget.ContainerOpts.WidgetOpts(
21 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
22 Stretch: true,
23 }),
24 widget.WidgetOpts.MinSize(96, 64),
25 ),
26 )
27 b := widget.NewContainer(
28 widget.ContainerOpts.BackgroundImage(
29 image.NewNineSliceColor(colornames.Goldenrod),
30 ),
31 widget.ContainerOpts.WidgetOpts(
32 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
33 Stretch: true,
34 }),
35 widget.WidgetOpts.MinSize(96, 64),
36 ),
37 )
38 c := widget.NewContainer(
39 widget.ContainerOpts.BackgroundImage(
40 image.NewNineSliceColor(colornames.Steelblue),
41 ),
42 widget.ContainerOpts.WidgetOpts(
43 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
44 Stretch: true,
45 }),
46 widget.WidgetOpts.MinSize(96, 64),
47 ),
48 )
49 d := widget.NewContainer(
50 widget.ContainerOpts.BackgroundImage(
51 image.NewNineSliceColor(colornames.Mediumseagreen),
52 ),
53 widget.ContainerOpts.WidgetOpts(
54 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
55 Stretch: true,
56 }),
57 widget.WidgetOpts.MinSize(96, 64),
58 ),
59 )
60 e := widget.NewContainer(
61 widget.ContainerOpts.BackgroundImage(
62 image.NewNineSliceColor(colornames.Darkslategray),
63 ),
64 widget.ContainerOpts.WidgetOpts(
65 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
66 Stretch: true,
67 }),
68 widget.WidgetOpts.MinSize(96, 64),
69 ),
70 )
71 root := widget.NewContainer(
72 widget.ContainerOpts.BackgroundImage(
73 image.NewNineSliceColor(colornames.Gainsboro),
74 ),
75 widget.ContainerOpts.Layout(widget.NewRowLayout(
76 widget.RowLayoutOpts.Direction(
77 widget.DirectionVertical,
78 ),
79 widget.RowLayoutOpts.Padding(widget.Insets{
80 Left: 50,
81 }),
82 )),
83 )
84 root.AddChild(a)
85 root.AddChild(b)
86 root.AddChild(c)
87 root.AddChild(d)
88 root.AddChild(e)
89
90 return &Game{
91 ui: &ebitenui.UI{Container: root},
92 }
93}
94
95func (g *Game) Update() error {
96 g.ui.Update()
97 return nil
98}
99
100func (g *Game) Draw(screen *ebiten.Image) {
101 g.ui.Draw(screen)
102}
103
104func (g *Game) Layout(w, h int) (int, int) {
105 return w, h
106}
107
108func main() {
109 ebiten.SetWindowSize(480, 320)
110 ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
111 if err := ebiten.RunGame(NewGame()); err != nil {
112 panic(err)
113 }
114}
1root := widget.NewContainer(
2 widget.ContainerOpts.BackgroundImage(
3 image.NewNineSliceColor(colornames.Gainsboro),
4 ),
5 widget.ContainerOpts.Layout(widget.NewRowLayout(
6 widget.RowLayoutOpts.Direction(
7 widget.DirectionVertical,
8 ),
9 widget.RowLayoutOpts.Padding(widget.Insets{
10 Right: 50,
11 }),
12 )),
13)
1package main
2
3import (
4 "github.com/ebitenui/ebitenui"
5 "github.com/ebitenui/ebitenui/image"
6 "github.com/ebitenui/ebitenui/widget"
7 "github.com/hajimehoshi/ebiten/v2"
8 "golang.org/x/image/colornames"
9)
10
11type Game struct {
12 ui *ebitenui.UI
13}
14
15func NewGame() *Game {
16 a := widget.NewContainer(
17 widget.ContainerOpts.BackgroundImage(
18 image.NewNineSliceColor(colornames.Indianred),
19 ),
20 widget.ContainerOpts.WidgetOpts(
21 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
22 Stretch: true,
23 }),
24 widget.WidgetOpts.MinSize(96, 64),
25 ),
26 )
27 b := widget.NewContainer(
28 widget.ContainerOpts.BackgroundImage(
29 image.NewNineSliceColor(colornames.Goldenrod),
30 ),
31 widget.ContainerOpts.WidgetOpts(
32 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
33 Stretch: true,
34 }),
35 widget.WidgetOpts.MinSize(96, 64),
36 ),
37 )
38 c := widget.NewContainer(
39 widget.ContainerOpts.BackgroundImage(
40 image.NewNineSliceColor(colornames.Steelblue),
41 ),
42 widget.ContainerOpts.WidgetOpts(
43 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
44 Stretch: true,
45 }),
46 widget.WidgetOpts.MinSize(96, 64),
47 ),
48 )
49 d := widget.NewContainer(
50 widget.ContainerOpts.BackgroundImage(
51 image.NewNineSliceColor(colornames.Mediumseagreen),
52 ),
53 widget.ContainerOpts.WidgetOpts(
54 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
55 Stretch: true,
56 }),
57 widget.WidgetOpts.MinSize(96, 64),
58 ),
59 )
60 e := widget.NewContainer(
61 widget.ContainerOpts.BackgroundImage(
62 image.NewNineSliceColor(colornames.Darkslategray),
63 ),
64 widget.ContainerOpts.WidgetOpts(
65 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
66 Stretch: true,
67 }),
68 widget.WidgetOpts.MinSize(96, 64),
69 ),
70 )
71 root := widget.NewContainer(
72 widget.ContainerOpts.BackgroundImage(
73 image.NewNineSliceColor(colornames.Gainsboro),
74 ),
75 widget.ContainerOpts.Layout(widget.NewRowLayout(
76 widget.RowLayoutOpts.Direction(
77 widget.DirectionVertical,
78 ),
79 widget.RowLayoutOpts.Padding(widget.Insets{
80 Right: 50,
81 }),
82 )),
83 )
84 root.AddChild(a)
85 root.AddChild(b)
86 root.AddChild(c)
87 root.AddChild(d)
88 root.AddChild(e)
89
90 return &Game{
91 ui: &ebitenui.UI{Container: root},
92 }
93}
94
95func (g *Game) Update() error {
96 g.ui.Update()
97 return nil
98}
99
100func (g *Game) Draw(screen *ebiten.Image) {
101 g.ui.Draw(screen)
102}
103
104func (g *Game) Layout(w, h int) (int, int) {
105 return w, h
106}
107
108func main() {
109 ebiten.SetWindowSize(480, 320)
110 ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
111 if err := ebiten.RunGame(NewGame()); err != nil {
112 panic(err)
113 }
114}
1root := widget.NewContainer(
2 widget.ContainerOpts.BackgroundImage(
3 image.NewNineSliceColor(colornames.Gainsboro),
4 ),
5 widget.ContainerOpts.Layout(widget.NewRowLayout(
6 widget.RowLayoutOpts.Direction(
7 widget.DirectionHorizontal,
8 ),
9 widget.RowLayoutOpts.Padding(widget.Insets{
10 Top: 50,
11 }),
12 )),
13)
1package main
2
3import (
4 "github.com/ebitenui/ebitenui"
5 "github.com/ebitenui/ebitenui/image"
6 "github.com/ebitenui/ebitenui/widget"
7 "github.com/hajimehoshi/ebiten/v2"
8 "golang.org/x/image/colornames"
9)
10
11type Game struct {
12 ui *ebitenui.UI
13}
14
15func NewGame() *Game {
16 a := widget.NewContainer(
17 widget.ContainerOpts.BackgroundImage(
18 image.NewNineSliceColor(colornames.Indianred),
19 ),
20 widget.ContainerOpts.WidgetOpts(
21 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
22 Stretch: true,
23 }),
24 widget.WidgetOpts.MinSize(96, 64),
25 ),
26 )
27 b := widget.NewContainer(
28 widget.ContainerOpts.BackgroundImage(
29 image.NewNineSliceColor(colornames.Goldenrod),
30 ),
31 widget.ContainerOpts.WidgetOpts(
32 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
33 Stretch: true,
34 }),
35 widget.WidgetOpts.MinSize(96, 64),
36 ),
37 )
38 c := widget.NewContainer(
39 widget.ContainerOpts.BackgroundImage(
40 image.NewNineSliceColor(colornames.Steelblue),
41 ),
42 widget.ContainerOpts.WidgetOpts(
43 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
44 Stretch: true,
45 }),
46 widget.WidgetOpts.MinSize(96, 64),
47 ),
48 )
49 d := widget.NewContainer(
50 widget.ContainerOpts.BackgroundImage(
51 image.NewNineSliceColor(colornames.Mediumseagreen),
52 ),
53 widget.ContainerOpts.WidgetOpts(
54 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
55 Stretch: true,
56 }),
57 widget.WidgetOpts.MinSize(96, 64),
58 ),
59 )
60 e := widget.NewContainer(
61 widget.ContainerOpts.BackgroundImage(
62 image.NewNineSliceColor(colornames.Darkslategray),
63 ),
64 widget.ContainerOpts.WidgetOpts(
65 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
66 Stretch: true,
67 }),
68 widget.WidgetOpts.MinSize(96, 64),
69 ),
70 )
71 root := widget.NewContainer(
72 widget.ContainerOpts.BackgroundImage(
73 image.NewNineSliceColor(colornames.Gainsboro),
74 ),
75 widget.ContainerOpts.Layout(widget.NewRowLayout(
76 widget.RowLayoutOpts.Direction(
77 widget.DirectionHorizontal,
78 ),
79 widget.RowLayoutOpts.Padding(widget.Insets{
80 Top: 50,
81 }),
82 )),
83 )
84 root.AddChild(a)
85 root.AddChild(b)
86 root.AddChild(c)
87 root.AddChild(d)
88 root.AddChild(e)
89
90 return &Game{
91 ui: &ebitenui.UI{Container: root},
92 }
93}
94
95func (g *Game) Update() error {
96 g.ui.Update()
97 return nil
98}
99
100func (g *Game) Draw(screen *ebiten.Image) {
101 g.ui.Draw(screen)
102}
103
104func (g *Game) Layout(w, h int) (int, int) {
105 return w, h
106}
107
108func main() {
109 ebiten.SetWindowSize(480, 320)
110 ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
111 if err := ebiten.RunGame(NewGame()); err != nil {
112 panic(err)
113 }
114}
1root := widget.NewContainer(
2 widget.ContainerOpts.BackgroundImage(
3 image.NewNineSliceColor(colornames.Gainsboro),
4 ),
5 widget.ContainerOpts.Layout(widget.NewRowLayout(
6 widget.RowLayoutOpts.Direction(
7 widget.DirectionHorizontal,
8 ),
9 widget.RowLayoutOpts.Padding(widget.Insets{
10 Bottom: 50,
11 }),
12 )),
13)
1package main
2
3import (
4 "github.com/ebitenui/ebitenui"
5 "github.com/ebitenui/ebitenui/image"
6 "github.com/ebitenui/ebitenui/widget"
7 "github.com/hajimehoshi/ebiten/v2"
8 "golang.org/x/image/colornames"
9)
10
11type Game struct {
12 ui *ebitenui.UI
13}
14
15func NewGame() *Game {
16 a := widget.NewContainer(
17 widget.ContainerOpts.BackgroundImage(
18 image.NewNineSliceColor(colornames.Indianred),
19 ),
20 widget.ContainerOpts.WidgetOpts(
21 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
22 Stretch: true,
23 }),
24 widget.WidgetOpts.MinSize(96, 64),
25 ),
26 )
27 b := widget.NewContainer(
28 widget.ContainerOpts.BackgroundImage(
29 image.NewNineSliceColor(colornames.Goldenrod),
30 ),
31 widget.ContainerOpts.WidgetOpts(
32 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
33 Stretch: true,
34 }),
35 widget.WidgetOpts.MinSize(96, 64),
36 ),
37 )
38 c := widget.NewContainer(
39 widget.ContainerOpts.BackgroundImage(
40 image.NewNineSliceColor(colornames.Steelblue),
41 ),
42 widget.ContainerOpts.WidgetOpts(
43 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
44 Stretch: true,
45 }),
46 widget.WidgetOpts.MinSize(96, 64),
47 ),
48 )
49 d := widget.NewContainer(
50 widget.ContainerOpts.BackgroundImage(
51 image.NewNineSliceColor(colornames.Mediumseagreen),
52 ),
53 widget.ContainerOpts.WidgetOpts(
54 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
55 Stretch: true,
56 }),
57 widget.WidgetOpts.MinSize(96, 64),
58 ),
59 )
60 e := widget.NewContainer(
61 widget.ContainerOpts.BackgroundImage(
62 image.NewNineSliceColor(colornames.Darkslategray),
63 ),
64 widget.ContainerOpts.WidgetOpts(
65 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
66 Stretch: true,
67 }),
68 widget.WidgetOpts.MinSize(96, 64),
69 ),
70 )
71 root := widget.NewContainer(
72 widget.ContainerOpts.BackgroundImage(
73 image.NewNineSliceColor(colornames.Gainsboro),
74 ),
75 widget.ContainerOpts.Layout(widget.NewRowLayout(
76 widget.RowLayoutOpts.Direction(
77 widget.DirectionHorizontal,
78 ),
79 widget.RowLayoutOpts.Padding(widget.Insets{
80 Bottom: 50,
81 }),
82 )),
83 )
84 root.AddChild(a)
85 root.AddChild(b)
86 root.AddChild(c)
87 root.AddChild(d)
88 root.AddChild(e)
89
90 return &Game{
91 ui: &ebitenui.UI{Container: root},
92 }
93}
94
95func (g *Game) Update() error {
96 g.ui.Update()
97 return nil
98}
99
100func (g *Game) Draw(screen *ebiten.Image) {
101 g.ui.Draw(screen)
102}
103
104func (g *Game) Layout(w, h int) (int, int) {
105 return w, h
106}
107
108func main() {
109 ebiten.SetWindowSize(480, 320)
110 ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
111 if err := ebiten.RunGame(NewGame()); err != nil {
112 panic(err)
113 }
114}
Spacing
Layout allows you to specify padding for all child elements but not the itself.
Spacing:
1root := widget.NewContainer(
2 widget.ContainerOpts.BackgroundImage(
3 image.NewNineSliceColor(colornames.Gainsboro),
4 ),
5 widget.ContainerOpts.Layout(widget.NewRowLayout(
6 widget.RowLayoutOpts.Direction(
7 widget.DirectionVertical,
8 ),
9 widget.RowLayoutOpts.Spacing(0),
10 )),
11)
1package main
2
3import (
4 "github.com/ebitenui/ebitenui"
5 "github.com/ebitenui/ebitenui/image"
6 "github.com/ebitenui/ebitenui/widget"
7 "github.com/hajimehoshi/ebiten/v2"
8 "golang.org/x/image/colornames"
9)
10
11type Game struct {
12 ui *ebitenui.UI
13}
14
15func NewGame() *Game {
16 a := widget.NewContainer(
17 widget.ContainerOpts.BackgroundImage(
18 image.NewNineSliceColor(colornames.Indianred),
19 ),
20 widget.ContainerOpts.WidgetOpts(
21 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
22 Stretch: true,
23 }),
24 widget.WidgetOpts.MinSize(96, 64),
25 ),
26 )
27 b := widget.NewContainer(
28 widget.ContainerOpts.BackgroundImage(
29 image.NewNineSliceColor(colornames.Goldenrod),
30 ),
31 widget.ContainerOpts.WidgetOpts(
32 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
33 Stretch: true,
34 }),
35 widget.WidgetOpts.MinSize(96, 64),
36 ),
37 )
38 c := widget.NewContainer(
39 widget.ContainerOpts.BackgroundImage(
40 image.NewNineSliceColor(colornames.Steelblue),
41 ),
42 widget.ContainerOpts.WidgetOpts(
43 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
44 Stretch: true,
45 }),
46 widget.WidgetOpts.MinSize(96, 64),
47 ),
48 )
49 d := widget.NewContainer(
50 widget.ContainerOpts.BackgroundImage(
51 image.NewNineSliceColor(colornames.Mediumseagreen),
52 ),
53 widget.ContainerOpts.WidgetOpts(
54 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
55 Stretch: true,
56 }),
57 widget.WidgetOpts.MinSize(96, 64),
58 ),
59 )
60 e := widget.NewContainer(
61 widget.ContainerOpts.BackgroundImage(
62 image.NewNineSliceColor(colornames.Darkslategray),
63 ),
64 widget.ContainerOpts.WidgetOpts(
65 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
66 Stretch: true,
67 }),
68 widget.WidgetOpts.MinSize(96, 64),
69 ),
70 )
71 root := widget.NewContainer(
72 widget.ContainerOpts.BackgroundImage(
73 image.NewNineSliceColor(colornames.Gainsboro),
74 ),
75 widget.ContainerOpts.Layout(widget.NewRowLayout(
76 widget.RowLayoutOpts.Direction(
77 widget.DirectionVertical,
78 ),
79 widget.RowLayoutOpts.Spacing(0),
80 )),
81 )
82 root.AddChild(a)
83 root.AddChild(b)
84 root.AddChild(c)
85 root.AddChild(d)
86 root.AddChild(e)
87
88 return &Game{
89 ui: &ebitenui.UI{Container: root},
90 }
91}
92
93func (g *Game) Update() error {
94 g.ui.Update()
95 return nil
96}
97
98func (g *Game) Draw(screen *ebiten.Image) {
99 g.ui.Draw(screen)
100}
101
102func (g *Game) Layout(w, h int) (int, int) {
103 return w, h
104}
105
106func main() {
107 ebiten.SetWindowSize(480, 320)
108 ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
109 if err := ebiten.RunGame(NewGame()); err != nil {
110 panic(err)
111 }
112}
1root := widget.NewContainer(
2 widget.ContainerOpts.BackgroundImage(
3 image.NewNineSliceColor(colornames.Gainsboro),
4 ),
5 widget.ContainerOpts.Layout(widget.NewRowLayout(
6 widget.RowLayoutOpts.Direction(
7 widget.DirectionVertical,
8 ),
9 widget.RowLayoutOpts.Spacing(25),
10 )),
11)
1package main
2
3import (
4 "github.com/ebitenui/ebitenui"
5 "github.com/ebitenui/ebitenui/image"
6 "github.com/ebitenui/ebitenui/widget"
7 "github.com/hajimehoshi/ebiten/v2"
8 "golang.org/x/image/colornames"
9)
10
11type Game struct {
12 ui *ebitenui.UI
13}
14
15func NewGame() *Game {
16 a := widget.NewContainer(
17 widget.ContainerOpts.BackgroundImage(
18 image.NewNineSliceColor(colornames.Indianred),
19 ),
20 widget.ContainerOpts.WidgetOpts(
21 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
22 Stretch: true,
23 }),
24 widget.WidgetOpts.MinSize(96, 64),
25 ),
26 )
27 b := widget.NewContainer(
28 widget.ContainerOpts.BackgroundImage(
29 image.NewNineSliceColor(colornames.Goldenrod),
30 ),
31 widget.ContainerOpts.WidgetOpts(
32 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
33 Stretch: true,
34 }),
35 widget.WidgetOpts.MinSize(96, 64),
36 ),
37 )
38 c := widget.NewContainer(
39 widget.ContainerOpts.BackgroundImage(
40 image.NewNineSliceColor(colornames.Steelblue),
41 ),
42 widget.ContainerOpts.WidgetOpts(
43 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
44 Stretch: true,
45 }),
46 widget.WidgetOpts.MinSize(96, 64),
47 ),
48 )
49 d := widget.NewContainer(
50 widget.ContainerOpts.BackgroundImage(
51 image.NewNineSliceColor(colornames.Mediumseagreen),
52 ),
53 widget.ContainerOpts.WidgetOpts(
54 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
55 Stretch: true,
56 }),
57 widget.WidgetOpts.MinSize(96, 64),
58 ),
59 )
60 e := widget.NewContainer(
61 widget.ContainerOpts.BackgroundImage(
62 image.NewNineSliceColor(colornames.Darkslategray),
63 ),
64 widget.ContainerOpts.WidgetOpts(
65 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
66 Stretch: true,
67 }),
68 widget.WidgetOpts.MinSize(96, 64),
69 ),
70 )
71 root := widget.NewContainer(
72 widget.ContainerOpts.BackgroundImage(
73 image.NewNineSliceColor(colornames.Gainsboro),
74 ),
75 widget.ContainerOpts.Layout(widget.NewRowLayout(
76 widget.RowLayoutOpts.Direction(
77 widget.DirectionVertical,
78 ),
79 widget.RowLayoutOpts.Spacing(25),
80 )),
81 )
82 root.AddChild(a)
83 root.AddChild(b)
84 root.AddChild(c)
85 root.AddChild(d)
86 root.AddChild(e)
87
88 return &Game{
89 ui: &ebitenui.UI{Container: root},
90 }
91}
92
93func (g *Game) Update() error {
94 g.ui.Update()
95 return nil
96}
97
98func (g *Game) Draw(screen *ebiten.Image) {
99 g.ui.Draw(screen)
100}
101
102func (g *Game) Layout(w, h int) (int, int) {
103 return w, h
104}
105
106func main() {
107 ebiten.SetWindowSize(480, 320)
108 ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
109 if err := ebiten.RunGame(NewGame()); err != nil {
110 panic(err)
111 }
112}
1root := widget.NewContainer(
2 widget.ContainerOpts.BackgroundImage(
3 image.NewNineSliceColor(colornames.Gainsboro),
4 ),
5 widget.ContainerOpts.Layout(widget.NewRowLayout(
6 widget.RowLayoutOpts.Direction(
7 widget.DirectionVertical,
8 ),
9 widget.RowLayoutOpts.Spacing(50),
10 )),
11)
1package main
2
3import (
4 "github.com/ebitenui/ebitenui"
5 "github.com/ebitenui/ebitenui/image"
6 "github.com/ebitenui/ebitenui/widget"
7 "github.com/hajimehoshi/ebiten/v2"
8 "golang.org/x/image/colornames"
9)
10
11type Game struct {
12 ui *ebitenui.UI
13}
14
15func NewGame() *Game {
16 a := widget.NewContainer(
17 widget.ContainerOpts.BackgroundImage(
18 image.NewNineSliceColor(colornames.Indianred),
19 ),
20 widget.ContainerOpts.WidgetOpts(
21 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
22 Stretch: true,
23 }),
24 widget.WidgetOpts.MinSize(96, 64),
25 ),
26 )
27 b := widget.NewContainer(
28 widget.ContainerOpts.BackgroundImage(
29 image.NewNineSliceColor(colornames.Goldenrod),
30 ),
31 widget.ContainerOpts.WidgetOpts(
32 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
33 Stretch: true,
34 }),
35 widget.WidgetOpts.MinSize(96, 64),
36 ),
37 )
38 c := widget.NewContainer(
39 widget.ContainerOpts.BackgroundImage(
40 image.NewNineSliceColor(colornames.Steelblue),
41 ),
42 widget.ContainerOpts.WidgetOpts(
43 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
44 Stretch: true,
45 }),
46 widget.WidgetOpts.MinSize(96, 64),
47 ),
48 )
49 d := widget.NewContainer(
50 widget.ContainerOpts.BackgroundImage(
51 image.NewNineSliceColor(colornames.Mediumseagreen),
52 ),
53 widget.ContainerOpts.WidgetOpts(
54 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
55 Stretch: true,
56 }),
57 widget.WidgetOpts.MinSize(96, 64),
58 ),
59 )
60 e := widget.NewContainer(
61 widget.ContainerOpts.BackgroundImage(
62 image.NewNineSliceColor(colornames.Darkslategray),
63 ),
64 widget.ContainerOpts.WidgetOpts(
65 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
66 Stretch: true,
67 }),
68 widget.WidgetOpts.MinSize(96, 64),
69 ),
70 )
71 root := widget.NewContainer(
72 widget.ContainerOpts.BackgroundImage(
73 image.NewNineSliceColor(colornames.Gainsboro),
74 ),
75 widget.ContainerOpts.Layout(widget.NewRowLayout(
76 widget.RowLayoutOpts.Direction(
77 widget.DirectionVertical,
78 ),
79 widget.RowLayoutOpts.Spacing(50),
80 )),
81 )
82 root.AddChild(a)
83 root.AddChild(b)
84 root.AddChild(c)
85 root.AddChild(d)
86 root.AddChild(e)
87
88 return &Game{
89 ui: &ebitenui.UI{Container: root},
90 }
91}
92
93func (g *Game) Update() error {
94 g.ui.Update()
95 return nil
96}
97
98func (g *Game) Draw(screen *ebiten.Image) {
99 g.ui.Draw(screen)
100}
101
102func (g *Game) Layout(w, h int) (int, int) {
103 return w, h
104}
105
106func main() {
107 ebiten.SetWindowSize(480, 320)
108 ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
109 if err := ebiten.RunGame(NewGame()); err != nil {
110 panic(err)
111 }
112}
1root := widget.NewContainer(
2 widget.ContainerOpts.BackgroundImage(
3 image.NewNineSliceColor(colornames.Gainsboro),
4 ),
5 widget.ContainerOpts.Layout(widget.NewRowLayout(
6 widget.RowLayoutOpts.Direction(
7 widget.DirectionVertical,
8 ),
9 widget.RowLayoutOpts.Spacing(75),
10 )),
11)
1package main
2
3import (
4 "github.com/ebitenui/ebitenui"
5 "github.com/ebitenui/ebitenui/image"
6 "github.com/ebitenui/ebitenui/widget"
7 "github.com/hajimehoshi/ebiten/v2"
8 "golang.org/x/image/colornames"
9)
10
11type Game struct {
12 ui *ebitenui.UI
13}
14
15func NewGame() *Game {
16 a := widget.NewContainer(
17 widget.ContainerOpts.BackgroundImage(
18 image.NewNineSliceColor(colornames.Indianred),
19 ),
20 widget.ContainerOpts.WidgetOpts(
21 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
22 Stretch: true,
23 }),
24 widget.WidgetOpts.MinSize(96, 64),
25 ),
26 )
27 b := widget.NewContainer(
28 widget.ContainerOpts.BackgroundImage(
29 image.NewNineSliceColor(colornames.Goldenrod),
30 ),
31 widget.ContainerOpts.WidgetOpts(
32 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
33 Stretch: true,
34 }),
35 widget.WidgetOpts.MinSize(96, 64),
36 ),
37 )
38 c := widget.NewContainer(
39 widget.ContainerOpts.BackgroundImage(
40 image.NewNineSliceColor(colornames.Steelblue),
41 ),
42 widget.ContainerOpts.WidgetOpts(
43 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
44 Stretch: true,
45 }),
46 widget.WidgetOpts.MinSize(96, 64),
47 ),
48 )
49 d := widget.NewContainer(
50 widget.ContainerOpts.BackgroundImage(
51 image.NewNineSliceColor(colornames.Mediumseagreen),
52 ),
53 widget.ContainerOpts.WidgetOpts(
54 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
55 Stretch: true,
56 }),
57 widget.WidgetOpts.MinSize(96, 64),
58 ),
59 )
60 e := widget.NewContainer(
61 widget.ContainerOpts.BackgroundImage(
62 image.NewNineSliceColor(colornames.Darkslategray),
63 ),
64 widget.ContainerOpts.WidgetOpts(
65 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
66 Stretch: true,
67 }),
68 widget.WidgetOpts.MinSize(96, 64),
69 ),
70 )
71 root := widget.NewContainer(
72 widget.ContainerOpts.BackgroundImage(
73 image.NewNineSliceColor(colornames.Gainsboro),
74 ),
75 widget.ContainerOpts.Layout(widget.NewRowLayout(
76 widget.RowLayoutOpts.Direction(
77 widget.DirectionVertical,
78 ),
79 widget.RowLayoutOpts.Spacing(75),
80 )),
81 )
82 root.AddChild(a)
83 root.AddChild(b)
84 root.AddChild(c)
85 root.AddChild(d)
86 root.AddChild(e)
87
88 return &Game{
89 ui: &ebitenui.UI{Container: root},
90 }
91}
92
93func (g *Game) Update() error {
94 g.ui.Update()
95 return nil
96}
97
98func (g *Game) Draw(screen *ebiten.Image) {
99 g.ui.Draw(screen)
100}
101
102func (g *Game) Layout(w, h int) (int, int) {
103 return w, h
104}
105
106func main() {
107 ebiten.SetWindowSize(480, 320)
108 ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
109 if err := ebiten.RunGame(NewGame()); err != nil {
110 panic(err)
111 }
112}
Layout data
Stretch
Responsible for stretching the element along the entire length of the opposite axis.
Stretch:
1a := widget.NewContainer(
2 widget.ContainerOpts.BackgroundImage(
3 image.NewNineSliceColor(colornames.Indianred),
4 ),
5 widget.ContainerOpts.WidgetOpts(
6 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
7 Stretch: false,
8 }),
9 widget.WidgetOpts.MinSize(96, 64),
10 ),
11)
1package main
2
3import (
4 "github.com/ebitenui/ebitenui"
5 "github.com/ebitenui/ebitenui/image"
6 "github.com/ebitenui/ebitenui/widget"
7 "github.com/hajimehoshi/ebiten/v2"
8 "golang.org/x/image/colornames"
9)
10
11type Game struct {
12 ui *ebitenui.UI
13}
14
15func NewGame() *Game {
16 a := widget.NewContainer(
17 widget.ContainerOpts.BackgroundImage(
18 image.NewNineSliceColor(colornames.Indianred),
19 ),
20 widget.ContainerOpts.WidgetOpts(
21 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
22 Stretch: false,
23 }),
24 widget.WidgetOpts.MinSize(96, 64),
25 ),
26 )
27 b := widget.NewContainer(
28 widget.ContainerOpts.BackgroundImage(
29 image.NewNineSliceColor(colornames.Goldenrod),
30 ),
31 widget.ContainerOpts.WidgetOpts(
32 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
33 Stretch: false,
34 }),
35 widget.WidgetOpts.MinSize(96, 64),
36 ),
37 )
38 c := widget.NewContainer(
39 widget.ContainerOpts.BackgroundImage(
40 image.NewNineSliceColor(colornames.Steelblue),
41 ),
42 widget.ContainerOpts.WidgetOpts(
43 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
44 Stretch: false,
45 }),
46 widget.WidgetOpts.MinSize(96, 64),
47 ),
48 )
49 d := widget.NewContainer(
50 widget.ContainerOpts.BackgroundImage(
51 image.NewNineSliceColor(colornames.Mediumseagreen),
52 ),
53 widget.ContainerOpts.WidgetOpts(
54 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
55 Stretch: false,
56 }),
57 widget.WidgetOpts.MinSize(96, 64),
58 ),
59 )
60 e := widget.NewContainer(
61 widget.ContainerOpts.BackgroundImage(
62 image.NewNineSliceColor(colornames.Darkslategray),
63 ),
64 widget.ContainerOpts.WidgetOpts(
65 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
66 Stretch: false,
67 }),
68 widget.WidgetOpts.MinSize(96, 64),
69 ),
70 )
71 root := widget.NewContainer(
72 widget.ContainerOpts.BackgroundImage(
73 image.NewNineSliceColor(colornames.Gainsboro),
74 ),
75 widget.ContainerOpts.Layout(widget.NewRowLayout(
76 widget.RowLayoutOpts.Direction(
77 widget.DirectionVertical,
78 ),
79 )),
80 )
81 root.AddChild(a)
82 root.AddChild(b)
83 root.AddChild(c)
84 root.AddChild(d)
85 root.AddChild(e)
86
87 return &Game{
88 ui: &ebitenui.UI{Container: root},
89 }
90}
91
92func (g *Game) Update() error {
93 g.ui.Update()
94 return nil
95}
96
97func (g *Game) Draw(screen *ebiten.Image) {
98 g.ui.Draw(screen)
99}
100
101func (g *Game) Layout(w, h int) (int, int) {
102 return w, h
103}
104
105func main() {
106 ebiten.SetWindowSize(480, 320)
107 ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
108 if err := ebiten.RunGame(NewGame()); err != nil {
109 panic(err)
110 }
111}
1a := widget.NewContainer(
2 widget.ContainerOpts.BackgroundImage(
3 image.NewNineSliceColor(colornames.Indianred),
4 ),
5 widget.ContainerOpts.WidgetOpts(
6 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
7 Stretch: true,
8 }),
9 widget.WidgetOpts.MinSize(96, 64),
10 ),
11)
1package main
2
3import (
4 "github.com/ebitenui/ebitenui"
5 "github.com/ebitenui/ebitenui/image"
6 "github.com/ebitenui/ebitenui/widget"
7 "github.com/hajimehoshi/ebiten/v2"
8 "golang.org/x/image/colornames"
9)
10
11type Game struct {
12 ui *ebitenui.UI
13}
14
15func NewGame() *Game {
16 a := widget.NewContainer(
17 widget.ContainerOpts.BackgroundImage(
18 image.NewNineSliceColor(colornames.Indianred),
19 ),
20 widget.ContainerOpts.WidgetOpts(
21 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
22 Stretch: true,
23 }),
24 widget.WidgetOpts.MinSize(96, 64),
25 ),
26 )
27 b := widget.NewContainer(
28 widget.ContainerOpts.BackgroundImage(
29 image.NewNineSliceColor(colornames.Goldenrod),
30 ),
31 widget.ContainerOpts.WidgetOpts(
32 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
33 Stretch: false,
34 }),
35 widget.WidgetOpts.MinSize(96, 64),
36 ),
37 )
38 c := widget.NewContainer(
39 widget.ContainerOpts.BackgroundImage(
40 image.NewNineSliceColor(colornames.Steelblue),
41 ),
42 widget.ContainerOpts.WidgetOpts(
43 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
44 Stretch: false,
45 }),
46 widget.WidgetOpts.MinSize(96, 64),
47 ),
48 )
49 d := widget.NewContainer(
50 widget.ContainerOpts.BackgroundImage(
51 image.NewNineSliceColor(colornames.Mediumseagreen),
52 ),
53 widget.ContainerOpts.WidgetOpts(
54 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
55 Stretch: false,
56 }),
57 widget.WidgetOpts.MinSize(96, 64),
58 ),
59 )
60 e := widget.NewContainer(
61 widget.ContainerOpts.BackgroundImage(
62 image.NewNineSliceColor(colornames.Darkslategray),
63 ),
64 widget.ContainerOpts.WidgetOpts(
65 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
66 Stretch: false,
67 }),
68 widget.WidgetOpts.MinSize(96, 64),
69 ),
70 )
71 root := widget.NewContainer(
72 widget.ContainerOpts.BackgroundImage(
73 image.NewNineSliceColor(colornames.Gainsboro),
74 ),
75 widget.ContainerOpts.Layout(widget.NewRowLayout(
76 widget.RowLayoutOpts.Direction(
77 widget.DirectionVertical,
78 ),
79 )),
80 )
81 root.AddChild(a)
82 root.AddChild(b)
83 root.AddChild(c)
84 root.AddChild(d)
85 root.AddChild(e)
86
87 return &Game{
88 ui: &ebitenui.UI{Container: root},
89 }
90}
91
92func (g *Game) Update() error {
93 g.ui.Update()
94 return nil
95}
96
97func (g *Game) Draw(screen *ebiten.Image) {
98 g.ui.Draw(screen)
99}
100
101func (g *Game) Layout(w, h int) (int, int) {
102 return w, h
103}
104
105func main() {
106 ebiten.SetWindowSize(480, 320)
107 ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
108 if err := ebiten.RunGame(NewGame()); err != nil {
109 panic(err)
110 }
111}
Position
Responsible for aligning the element along the opposite axis if it is not stretched.
Position:
1a := widget.NewContainer(
2 widget.ContainerOpts.BackgroundImage(
3 image.NewNineSliceColor(colornames.Indianred),
4 ),
5 widget.ContainerOpts.WidgetOpts(
6 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
7 Position: widget.RowLayoutPositionStart,
8 }),
9 widget.WidgetOpts.MinSize(96, 64),
10 ),
11)
1package main
2
3import (
4 "github.com/ebitenui/ebitenui"
5 "github.com/ebitenui/ebitenui/image"
6 "github.com/ebitenui/ebitenui/widget"
7 "github.com/hajimehoshi/ebiten/v2"
8 "golang.org/x/image/colornames"
9)
10
11type Game struct {
12 ui *ebitenui.UI
13}
14
15func NewGame() *Game {
16 a := widget.NewContainer(
17 widget.ContainerOpts.BackgroundImage(
18 image.NewNineSliceColor(colornames.Indianred),
19 ),
20 widget.ContainerOpts.WidgetOpts(
21 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
22 Position: widget.RowLayoutPositionStart,
23 }),
24 widget.WidgetOpts.MinSize(96, 64),
25 ),
26 )
27 b := widget.NewContainer(
28 widget.ContainerOpts.BackgroundImage(
29 image.NewNineSliceColor(colornames.Goldenrod),
30 ),
31 widget.ContainerOpts.WidgetOpts(
32 widget.WidgetOpts.MinSize(96, 64),
33 ),
34 )
35 c := widget.NewContainer(
36 widget.ContainerOpts.BackgroundImage(
37 image.NewNineSliceColor(colornames.Steelblue),
38 ),
39 widget.ContainerOpts.WidgetOpts(
40 widget.WidgetOpts.MinSize(96, 64),
41 ),
42 )
43 d := widget.NewContainer(
44 widget.ContainerOpts.BackgroundImage(
45 image.NewNineSliceColor(colornames.Mediumseagreen),
46 ),
47 widget.ContainerOpts.WidgetOpts(
48 widget.WidgetOpts.MinSize(96, 64),
49 ),
50 )
51 e := widget.NewContainer(
52 widget.ContainerOpts.BackgroundImage(
53 image.NewNineSliceColor(colornames.Darkslategray),
54 ),
55 widget.ContainerOpts.WidgetOpts(
56 widget.WidgetOpts.MinSize(96, 64),
57 ),
58 )
59 root := widget.NewContainer(
60 widget.ContainerOpts.BackgroundImage(
61 image.NewNineSliceColor(colornames.Gainsboro),
62 ),
63 widget.ContainerOpts.Layout(widget.NewRowLayout(
64 widget.RowLayoutOpts.Direction(
65 widget.DirectionVertical,
66 ),
67 )),
68 )
69 root.AddChild(a)
70 root.AddChild(b)
71 root.AddChild(c)
72 root.AddChild(d)
73 root.AddChild(e)
74
75 return &Game{
76 ui: &ebitenui.UI{Container: root},
77 }
78}
79
80func (g *Game) Update() error {
81 g.ui.Update()
82 return nil
83}
84
85func (g *Game) Draw(screen *ebiten.Image) {
86 g.ui.Draw(screen)
87}
88
89func (g *Game) Layout(w, h int) (int, int) {
90 return w, h
91}
92
93func main() {
94 ebiten.SetWindowSize(480, 320)
95 ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
96 if err := ebiten.RunGame(NewGame()); err != nil {
97 panic(err)
98 }
99}
1a := widget.NewContainer(
2 widget.ContainerOpts.BackgroundImage(
3 image.NewNineSliceColor(colornames.Indianred),
4 ),
5 widget.ContainerOpts.WidgetOpts(
6 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
7 Position: widget.RowLayoutPositionCenter,
8 }),
9 widget.WidgetOpts.MinSize(96, 64),
10 ),
11)
1package main
2
3import (
4 "github.com/ebitenui/ebitenui"
5 "github.com/ebitenui/ebitenui/image"
6 "github.com/ebitenui/ebitenui/widget"
7 "github.com/hajimehoshi/ebiten/v2"
8 "golang.org/x/image/colornames"
9)
10
11type Game struct {
12 ui *ebitenui.UI
13}
14
15func NewGame() *Game {
16 a := widget.NewContainer(
17 widget.ContainerOpts.BackgroundImage(
18 image.NewNineSliceColor(colornames.Indianred),
19 ),
20 widget.ContainerOpts.WidgetOpts(
21 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
22 Position: widget.RowLayoutPositionCenter,
23 }),
24 widget.WidgetOpts.MinSize(96, 64),
25 ),
26 )
27 b := widget.NewContainer(
28 widget.ContainerOpts.BackgroundImage(
29 image.NewNineSliceColor(colornames.Goldenrod),
30 ),
31 widget.ContainerOpts.WidgetOpts(
32 widget.WidgetOpts.MinSize(96, 64),
33 ),
34 )
35 c := widget.NewContainer(
36 widget.ContainerOpts.BackgroundImage(
37 image.NewNineSliceColor(colornames.Steelblue),
38 ),
39 widget.ContainerOpts.WidgetOpts(
40 widget.WidgetOpts.MinSize(96, 64),
41 ),
42 )
43 d := widget.NewContainer(
44 widget.ContainerOpts.BackgroundImage(
45 image.NewNineSliceColor(colornames.Mediumseagreen),
46 ),
47 widget.ContainerOpts.WidgetOpts(
48 widget.WidgetOpts.MinSize(96, 64),
49 ),
50 )
51 e := widget.NewContainer(
52 widget.ContainerOpts.BackgroundImage(
53 image.NewNineSliceColor(colornames.Darkslategray),
54 ),
55 widget.ContainerOpts.WidgetOpts(
56 widget.WidgetOpts.MinSize(96, 64),
57 ),
58 )
59 root := widget.NewContainer(
60 widget.ContainerOpts.BackgroundImage(
61 image.NewNineSliceColor(colornames.Gainsboro),
62 ),
63 widget.ContainerOpts.Layout(widget.NewRowLayout(
64 widget.RowLayoutOpts.Direction(
65 widget.DirectionVertical,
66 ),
67 )),
68 )
69 root.AddChild(a)
70 root.AddChild(b)
71 root.AddChild(c)
72 root.AddChild(d)
73 root.AddChild(e)
74
75 return &Game{
76 ui: &ebitenui.UI{Container: root},
77 }
78}
79
80func (g *Game) Update() error {
81 g.ui.Update()
82 return nil
83}
84
85func (g *Game) Draw(screen *ebiten.Image) {
86 g.ui.Draw(screen)
87}
88
89func (g *Game) Layout(w, h int) (int, int) {
90 return w, h
91}
92
93func main() {
94 ebiten.SetWindowSize(480, 320)
95 ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
96 if err := ebiten.RunGame(NewGame()); err != nil {
97 panic(err)
98 }
99}
1a := widget.NewContainer(
2 widget.ContainerOpts.BackgroundImage(
3 image.NewNineSliceColor(colornames.Indianred),
4 ),
5 widget.ContainerOpts.WidgetOpts(
6 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
7 Position: widget.RowLayoutPositionEnd,
8 }),
9 widget.WidgetOpts.MinSize(96, 64),
10 ),
11)
1package main
2
3import (
4 "github.com/ebitenui/ebitenui"
5 "github.com/ebitenui/ebitenui/image"
6 "github.com/ebitenui/ebitenui/widget"
7 "github.com/hajimehoshi/ebiten/v2"
8 "golang.org/x/image/colornames"
9)
10
11type Game struct {
12 ui *ebitenui.UI
13}
14
15func NewGame() *Game {
16 a := widget.NewContainer(
17 widget.ContainerOpts.BackgroundImage(
18 image.NewNineSliceColor(colornames.Indianred),
19 ),
20 widget.ContainerOpts.WidgetOpts(
21 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
22 Position: widget.RowLayoutPositionEnd,
23 }),
24 widget.WidgetOpts.MinSize(96, 64),
25 ),
26 )
27 b := widget.NewContainer(
28 widget.ContainerOpts.BackgroundImage(
29 image.NewNineSliceColor(colornames.Goldenrod),
30 ),
31 widget.ContainerOpts.WidgetOpts(
32 widget.WidgetOpts.MinSize(96, 64),
33 ),
34 )
35 c := widget.NewContainer(
36 widget.ContainerOpts.BackgroundImage(
37 image.NewNineSliceColor(colornames.Steelblue),
38 ),
39 widget.ContainerOpts.WidgetOpts(
40 widget.WidgetOpts.MinSize(96, 64),
41 ),
42 )
43 d := widget.NewContainer(
44 widget.ContainerOpts.BackgroundImage(
45 image.NewNineSliceColor(colornames.Mediumseagreen),
46 ),
47 widget.ContainerOpts.WidgetOpts(
48 widget.WidgetOpts.MinSize(96, 64),
49 ),
50 )
51 e := widget.NewContainer(
52 widget.ContainerOpts.BackgroundImage(
53 image.NewNineSliceColor(colornames.Darkslategray),
54 ),
55 widget.ContainerOpts.WidgetOpts(
56 widget.WidgetOpts.MinSize(96, 64),
57 ),
58 )
59 root := widget.NewContainer(
60 widget.ContainerOpts.BackgroundImage(
61 image.NewNineSliceColor(colornames.Gainsboro),
62 ),
63 widget.ContainerOpts.Layout(widget.NewRowLayout(
64 widget.RowLayoutOpts.Direction(
65 widget.DirectionVertical,
66 ),
67 )),
68 )
69 root.AddChild(a)
70 root.AddChild(b)
71 root.AddChild(c)
72 root.AddChild(d)
73 root.AddChild(e)
74
75 return &Game{
76 ui: &ebitenui.UI{Container: root},
77 }
78}
79
80func (g *Game) Update() error {
81 g.ui.Update()
82 return nil
83}
84
85func (g *Game) Draw(screen *ebiten.Image) {
86 g.ui.Draw(screen)
87}
88
89func (g *Game) Layout(w, h int) (int, int) {
90 return w, h
91}
92
93func main() {
94 ebiten.SetWindowSize(480, 320)
95 ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
96 if err := ebiten.RunGame(NewGame()); err != nil {
97 panic(err)
98 }
99}
Max size
Responsible for the allowable size of the container.
Max:
1a := widget.NewContainer(
2 widget.ContainerOpts.BackgroundImage(
3 image.NewNineSliceColor(colornames.Indianred),
4 ),
5 widget.ContainerOpts.WidgetOpts(
6 widget.WidgetOpts.LayoutData(widget.RowLayoutData{}),
7 widget.WidgetOpts.MinSize(96, 64),
8 ),
9)
1package main
2
3import (
4 "github.com/ebitenui/ebitenui"
5 "github.com/ebitenui/ebitenui/image"
6 "github.com/ebitenui/ebitenui/widget"
7 "github.com/hajimehoshi/ebiten/v2"
8 "golang.org/x/image/colornames"
9)
10
11type Game struct {
12 ui *ebitenui.UI
13}
14
15func NewGame() *Game {
16 a := widget.NewContainer(
17 widget.ContainerOpts.BackgroundImage(
18 image.NewNineSliceColor(colornames.Indianred),
19 ),
20 widget.ContainerOpts.WidgetOpts(
21 widget.WidgetOpts.LayoutData(widget.RowLayoutData{}),
22 widget.WidgetOpts.MinSize(96, 64),
23 ),
24 )
25 b := widget.NewContainer(
26 widget.ContainerOpts.BackgroundImage(
27 image.NewNineSliceColor(colornames.Goldenrod),
28 ),
29 widget.ContainerOpts.WidgetOpts(
30 widget.WidgetOpts.MinSize(96, 64),
31 ),
32 )
33 c := widget.NewContainer(
34 widget.ContainerOpts.BackgroundImage(
35 image.NewNineSliceColor(colornames.Steelblue),
36 ),
37 widget.ContainerOpts.WidgetOpts(
38 widget.WidgetOpts.MinSize(96, 64),
39 ),
40 )
41 d := widget.NewContainer(
42 widget.ContainerOpts.BackgroundImage(
43 image.NewNineSliceColor(colornames.Mediumseagreen),
44 ),
45 widget.ContainerOpts.WidgetOpts(
46 widget.WidgetOpts.MinSize(96, 64),
47 ),
48 )
49 e := widget.NewContainer(
50 widget.ContainerOpts.BackgroundImage(
51 image.NewNineSliceColor(colornames.Darkslategray),
52 ),
53 widget.ContainerOpts.WidgetOpts(
54 widget.WidgetOpts.MinSize(96, 64),
55 ),
56 )
57 root := widget.NewContainer(
58 widget.ContainerOpts.BackgroundImage(
59 image.NewNineSliceColor(colornames.Gainsboro),
60 ),
61 widget.ContainerOpts.Layout(widget.NewRowLayout(
62 widget.RowLayoutOpts.Direction(
63 widget.DirectionVertical,
64 ),
65 )),
66 )
67 root.AddChild(a)
68 root.AddChild(b)
69 root.AddChild(c)
70 root.AddChild(d)
71 root.AddChild(e)
72
73 return &Game{
74 ui: &ebitenui.UI{Container: root},
75 }
76}
77
78func (g *Game) Update() error {
79 g.ui.Update()
80 return nil
81}
82
83func (g *Game) Draw(screen *ebiten.Image) {
84 g.ui.Draw(screen)
85}
86
87func (g *Game) Layout(w, h int) (int, int) {
88 return w, h
89}
90
91func main() {
92 ebiten.SetWindowSize(480, 320)
93 ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
94 if err := ebiten.RunGame(NewGame()); err != nil {
95 panic(err)
96 }
97}
1a := widget.NewContainer(
2 widget.ContainerOpts.BackgroundImage(
3 image.NewNineSliceColor(colornames.Indianred),
4 ),
5 widget.ContainerOpts.WidgetOpts(
6 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
7 MaxWidth: 20,
8 }),
9 widget.WidgetOpts.MinSize(96, 64),
10 ),
11)
1package main
2
3import (
4 "github.com/ebitenui/ebitenui"
5 "github.com/ebitenui/ebitenui/image"
6 "github.com/ebitenui/ebitenui/widget"
7 "github.com/hajimehoshi/ebiten/v2"
8 "golang.org/x/image/colornames"
9)
10
11type Game struct {
12 ui *ebitenui.UI
13}
14
15func NewGame() *Game {
16 a := widget.NewContainer(
17 widget.ContainerOpts.BackgroundImage(
18 image.NewNineSliceColor(colornames.Indianred),
19 ),
20 widget.ContainerOpts.WidgetOpts(
21 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
22 MaxWidth: 20,
23 }),
24 widget.WidgetOpts.MinSize(96, 64),
25 ),
26 )
27 b := widget.NewContainer(
28 widget.ContainerOpts.BackgroundImage(
29 image.NewNineSliceColor(colornames.Goldenrod),
30 ),
31 widget.ContainerOpts.WidgetOpts(
32 widget.WidgetOpts.MinSize(96, 64),
33 ),
34 )
35 c := widget.NewContainer(
36 widget.ContainerOpts.BackgroundImage(
37 image.NewNineSliceColor(colornames.Steelblue),
38 ),
39 widget.ContainerOpts.WidgetOpts(
40 widget.WidgetOpts.MinSize(96, 64),
41 ),
42 )
43 d := widget.NewContainer(
44 widget.ContainerOpts.BackgroundImage(
45 image.NewNineSliceColor(colornames.Mediumseagreen),
46 ),
47 widget.ContainerOpts.WidgetOpts(
48 widget.WidgetOpts.MinSize(96, 64),
49 ),
50 )
51 e := widget.NewContainer(
52 widget.ContainerOpts.BackgroundImage(
53 image.NewNineSliceColor(colornames.Darkslategray),
54 ),
55 widget.ContainerOpts.WidgetOpts(
56 widget.WidgetOpts.MinSize(96, 64),
57 ),
58 )
59 root := widget.NewContainer(
60 widget.ContainerOpts.BackgroundImage(
61 image.NewNineSliceColor(colornames.Gainsboro),
62 ),
63 widget.ContainerOpts.Layout(widget.NewRowLayout(
64 widget.RowLayoutOpts.Direction(
65 widget.DirectionVertical,
66 ),
67 )),
68 )
69 root.AddChild(a)
70 root.AddChild(b)
71 root.AddChild(c)
72 root.AddChild(d)
73 root.AddChild(e)
74
75 return &Game{
76 ui: &ebitenui.UI{Container: root},
77 }
78}
79
80func (g *Game) Update() error {
81 g.ui.Update()
82 return nil
83}
84
85func (g *Game) Draw(screen *ebiten.Image) {
86 g.ui.Draw(screen)
87}
88
89func (g *Game) Layout(w, h int) (int, int) {
90 return w, h
91}
92
93func main() {
94 ebiten.SetWindowSize(480, 320)
95 ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
96 if err := ebiten.RunGame(NewGame()); err != nil {
97 panic(err)
98 }
99}
1a := widget.NewContainer(
2 widget.ContainerOpts.BackgroundImage(
3 image.NewNineSliceColor(colornames.Indianred),
4 ),
5 widget.ContainerOpts.WidgetOpts(
6 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
7 MaxHeight: 20,
8 }),
9 widget.WidgetOpts.MinSize(96, 64),
10 ),
11)
1package main
2
3import (
4 "github.com/ebitenui/ebitenui"
5 "github.com/ebitenui/ebitenui/image"
6 "github.com/ebitenui/ebitenui/widget"
7 "github.com/hajimehoshi/ebiten/v2"
8 "golang.org/x/image/colornames"
9)
10
11type Game struct {
12 ui *ebitenui.UI
13}
14
15func NewGame() *Game {
16 a := widget.NewContainer(
17 widget.ContainerOpts.BackgroundImage(
18 image.NewNineSliceColor(colornames.Indianred),
19 ),
20 widget.ContainerOpts.WidgetOpts(
21 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
22 MaxHeight: 20,
23 }),
24 widget.WidgetOpts.MinSize(96, 64),
25 ),
26 )
27 b := widget.NewContainer(
28 widget.ContainerOpts.BackgroundImage(
29 image.NewNineSliceColor(colornames.Goldenrod),
30 ),
31 widget.ContainerOpts.WidgetOpts(
32 widget.WidgetOpts.MinSize(96, 64),
33 ),
34 )
35 c := widget.NewContainer(
36 widget.ContainerOpts.BackgroundImage(
37 image.NewNineSliceColor(colornames.Steelblue),
38 ),
39 widget.ContainerOpts.WidgetOpts(
40 widget.WidgetOpts.MinSize(96, 64),
41 ),
42 )
43 d := widget.NewContainer(
44 widget.ContainerOpts.BackgroundImage(
45 image.NewNineSliceColor(colornames.Mediumseagreen),
46 ),
47 widget.ContainerOpts.WidgetOpts(
48 widget.WidgetOpts.MinSize(96, 64),
49 ),
50 )
51 e := widget.NewContainer(
52 widget.ContainerOpts.BackgroundImage(
53 image.NewNineSliceColor(colornames.Darkslategray),
54 ),
55 widget.ContainerOpts.WidgetOpts(
56 widget.WidgetOpts.MinSize(96, 64),
57 ),
58 )
59 root := widget.NewContainer(
60 widget.ContainerOpts.BackgroundImage(
61 image.NewNineSliceColor(colornames.Gainsboro),
62 ),
63 widget.ContainerOpts.Layout(widget.NewRowLayout(
64 widget.RowLayoutOpts.Direction(
65 widget.DirectionVertical,
66 ),
67 )),
68 )
69 root.AddChild(a)
70 root.AddChild(b)
71 root.AddChild(c)
72 root.AddChild(d)
73 root.AddChild(e)
74
75 return &Game{
76 ui: &ebitenui.UI{Container: root},
77 }
78}
79
80func (g *Game) Update() error {
81 g.ui.Update()
82 return nil
83}
84
85func (g *Game) Draw(screen *ebiten.Image) {
86 g.ui.Draw(screen)
87}
88
89func (g *Game) Layout(w, h int) (int, int) {
90 return w, h
91}
92
93func main() {
94 ebiten.SetWindowSize(480, 320)
95 ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
96 if err := ebiten.RunGame(NewGame()); err != nil {
97 panic(err)
98 }
99}
1a := widget.NewContainer(
2 widget.ContainerOpts.BackgroundImage(
3 image.NewNineSliceColor(colornames.Indianred),
4 ),
5 widget.ContainerOpts.WidgetOpts(
6 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
7 MaxWidth: 20,
8 MaxHeight: 20,
9 }),
10 widget.WidgetOpts.MinSize(96, 64),
11 ),
12)
1package main
2
3import (
4 "github.com/ebitenui/ebitenui"
5 "github.com/ebitenui/ebitenui/image"
6 "github.com/ebitenui/ebitenui/widget"
7 "github.com/hajimehoshi/ebiten/v2"
8 "golang.org/x/image/colornames"
9)
10
11type Game struct {
12 ui *ebitenui.UI
13}
14
15func NewGame() *Game {
16 a := widget.NewContainer(
17 widget.ContainerOpts.BackgroundImage(
18 image.NewNineSliceColor(colornames.Indianred),
19 ),
20 widget.ContainerOpts.WidgetOpts(
21 widget.WidgetOpts.LayoutData(widget.RowLayoutData{
22 MaxWidth: 20,
23 MaxHeight: 20,
24 }),
25 widget.WidgetOpts.MinSize(96, 64),
26 ),
27 )
28 b := widget.NewContainer(
29 widget.ContainerOpts.BackgroundImage(
30 image.NewNineSliceColor(colornames.Goldenrod),
31 ),
32 widget.ContainerOpts.WidgetOpts(
33 widget.WidgetOpts.MinSize(96, 64),
34 ),
35 )
36 c := widget.NewContainer(
37 widget.ContainerOpts.BackgroundImage(
38 image.NewNineSliceColor(colornames.Steelblue),
39 ),
40 widget.ContainerOpts.WidgetOpts(
41 widget.WidgetOpts.MinSize(96, 64),
42 ),
43 )
44 d := widget.NewContainer(
45 widget.ContainerOpts.BackgroundImage(
46 image.NewNineSliceColor(colornames.Mediumseagreen),
47 ),
48 widget.ContainerOpts.WidgetOpts(
49 widget.WidgetOpts.MinSize(96, 64),
50 ),
51 )
52 e := widget.NewContainer(
53 widget.ContainerOpts.BackgroundImage(
54 image.NewNineSliceColor(colornames.Darkslategray),
55 ),
56 widget.ContainerOpts.WidgetOpts(
57 widget.WidgetOpts.MinSize(96, 64),
58 ),
59 )
60 root := widget.NewContainer(
61 widget.ContainerOpts.BackgroundImage(
62 image.NewNineSliceColor(colornames.Gainsboro),
63 ),
64 widget.ContainerOpts.Layout(widget.NewRowLayout(
65 widget.RowLayoutOpts.Direction(
66 widget.DirectionVertical,
67 ),
68 )),
69 )
70 root.AddChild(a)
71 root.AddChild(b)
72 root.AddChild(c)
73 root.AddChild(d)
74 root.AddChild(e)
75
76 return &Game{
77 ui: &ebitenui.UI{Container: root},
78 }
79}
80
81func (g *Game) Update() error {
82 g.ui.Update()
83 return nil
84}
85
86func (g *Game) Draw(screen *ebiten.Image) {
87 g.ui.Draw(screen)
88}
89
90func (g *Game) Layout(w, h int) (int, int) {
91 return w, h
92}
93
94func main() {
95 ebiten.SetWindowSize(480, 320)
96 ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
97 if err := ebiten.RunGame(NewGame()); err != nil {
98 panic(err)
99 }
100}