-
Notifications
You must be signed in to change notification settings - Fork 7
/
adaptive.go
97 lines (79 loc) · 2.52 KB
/
adaptive.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package material
import (
"golang.org/x/mobile/exp/f32"
"golang.org/x/mobile/gl"
)
type Behavior int
const (
// When screen space is available, a surface is always visible.
VisibilityPermanent Behavior = iota
// Surface visibility can be toggled between visible and hidden. When visible,
// interacting with other elements on the screen does not change visibility.
VisibilityPersistent
// Surface visibility can be toggled between visible and hidden. When visible,
// interacting with other elements on the screen toggles the surface to become
// hidden or minimized.
VisibilityTemporary
// Element width stays the same when screen size changes.
WidthFixed
// Element width grows as screen size changes.
WidthFluid
// Element width is fixed until influenced by another element or breakpoint.
WidthSticky
// Element width contracts as a panel is revealed
WidthSqueeze
// Element width stays the same, its position changes horizontally as a panel
// appears, and it may be partially occluded by a screen’s edge.
WidthPush
// Element width and position stays the same as a panel appears over content.
WidthOverlay
// The z position, and shadow of an element. A flat element will have no shadow.
DescriptorFlat
DescriptorRaised
)
type Grid struct {
Margin float32
Gutter float32
Columns int
debug *Material
}
func (gd *Grid) StepSize() float32 {
return (float32(windowSize.WidthPx) - (gd.Margin * 2)) / float32(gd.Columns)
}
// TODO avoid the pointer
func NewGrid() *Grid {
// by breakpoints
g := &Grid{Margin: 24, Gutter: 24, Columns: 12}
if windowSize.WidthPx < int(Dp(600).Px()) || windowSize.HeightPx < int(Dp(600).Px()) {
g.Margin, g.Gutter = 16, 16 // TODO dp vals
}
if windowSize.WidthPx < int(Dp(480).Px()) {
g.Columns = 4
} else if windowSize.WidthPx < int(Dp(720).Px()) {
g.Columns = 8
}
return g
}
func (gd *Grid) draw(ctx gl.Context, view, proj f32.Mat4) {
if gd.debug == nil {
gd.debug = New(ctx, Color(0x03A9F499))
gd.debug.world.Identity()
gd.debug.world[0][0] = gd.Gutter + gd.Margin
gd.debug.world[1][1] = float32(windowSize.HeightPx)
}
step := gd.StepSize()
for i := 0; i <= gd.Columns; i++ {
if i == 0 {
gd.debug.world[0][0] = gd.Margin
gd.debug.world[0][3] = 0
} else if i == gd.Columns {
gd.debug.world[0][0] = gd.Margin
gd.debug.world[0][3] = gd.Margin + float32(i)*step
} else {
gd.debug.world[0][0] = gd.Gutter
gd.debug.world[0][3] = gd.Margin + float32(i)*step - gd.Gutter/2.0
}
// TODO add to environment
// gd.debug.Draw(ctx, view, proj)
}
}