-
Notifications
You must be signed in to change notification settings - Fork 1
/
flex.go
57 lines (49 loc) · 1.16 KB
/
flex.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
"image"
"image/color"
"gioui.org/app"
"gioui.org/io/system"
"gioui.org/layout"
"gioui.org/op"
"gioui.org/op/clip"
"gioui.org/op/paint"
)
func main() {
go func() {
w := app.NewWindow()
var ops op.Ops
for e := range w.Events() {
if e, ok := e.(system.FrameEvent); ok {
gtx := layout.NewContext(&ops, e)
drawRects(gtx)
e.Frame(gtx.Ops)
}
}
}()
app.Main()
}
// START OMIT
func drawRects(gtx layout.Context) layout.Dimensions {
return layout.Flex{}.Layout(gtx,
// Red.
layout.Flexed(0.5, func(gtx layout.Context) layout.Dimensions {
return drawRect(gtx, color.RGBA{A: 0xff, R: 0xff})
}),
// Green.
layout.Flexed(0.25, func(gtx layout.Context) layout.Dimensions {
return drawRect(gtx, color.RGBA{A: 0xff, G: 0xff})
}),
// Blue.
layout.Flexed(0.25, func(gtx layout.Context) layout.Dimensions {
return drawRect(gtx, color.RGBA{A: 0xff, B: 0xff})
}),
)
}
// END OMIT
func drawRect(gtx layout.Context, color color.RGBA) layout.Dimensions {
cs := gtx.Constraints
square := image.Rectangle{Max: cs.Max}
paint.FillShape(gtx.Ops, color, clip.Rect(square).Op())
return layout.Dimensions{Size: cs.Max}
}