/
nav.go
81 lines (75 loc) · 1.78 KB
/
nav.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
package main
import (
"image"
"os"
"gioui.org/app"
"gioui.org/font/gofont"
"gioui.org/io/system"
"gioui.org/layout"
"gioui.org/op"
"gioui.org/unit"
"gioui.org/widget/material"
"gioui.org/x/component"
"github.com/hauntedness/giom/play/common"
"golang.org/x/exp/shiny/materialdesign/icons"
)
// App Bar looks not so powerfull at present
type App struct {
theme *material.Theme
anim *component.VisibilityAnimation
item1 *int
}
func main() {
th := material.NewTheme(gofont.Collection())
item1 := 1
giomApp := App{
theme: th,
anim: &component.VisibilityAnimation{},
item1: &item1,
}
go func() {
window := app.NewWindow(app.Title("Protonet"))
window.Option(
func(m unit.Metric, c *app.Config) {
c.MaxSize = image.Point{
X: m.Dp(320),
Y: m.Dp(640),
}
},
)
if err := Loop(window, &giomApp); err != nil {
panic(err)
}
os.Exit(0)
}()
app.Main()
}
func Loop(w *app.Window, app *App) error {
// theme := material.NewTheme(gofont.Collection())
// backClickTag is meant for tracking user's backClick action, specially on mobile
var ops op.Ops
for e := range w.Events() {
switch e := e.(type) {
case system.DestroyEvent:
return e.Err
case system.FrameEvent:
gtx := layout.NewContext(&ops, e)
draw(gtx, app)
e.Frame(gtx.Ops)
}
}
return nil
}
func draw(gtx layout.Context, app *App) {
layout.Flex{}.Layout(gtx, layout.Flexed(1, func(gtx layout.Context) layout.Dimensions {
navBar := component.NewNav("title", "subtitle")
item := component.NavItem{
Tag: app.item1,
Name: "1st item",
Icon: common.MustIcon(icons.AVAVTimer),
}
navBar.AddNavItem(item)
navBar.SetNavDestination(app.item1)
return navBar.Layout(gtx, app.theme, app.anim)
}))
}