-
Notifications
You must be signed in to change notification settings - Fork 5
/
connect-form-view.go
72 lines (60 loc) · 1.7 KB
/
connect-form-view.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
package main
import (
"gioui.org/layout"
"gioui.org/unit"
"gioui.org/widget/material"
materials "gioui.org/x/component"
"git.sr.ht/~whereswaldon/sprig/core"
sprigWidget "git.sr.ht/~whereswaldon/sprig/widget"
sprigTheme "git.sr.ht/~whereswaldon/sprig/widget/theme"
)
type ConnectFormView struct {
manager ViewManager
Form sprigWidget.TextForm
core.App
}
var _ View = &ConnectFormView{}
func NewConnectFormView(app core.App) View {
c := &ConnectFormView{
App: app,
}
c.Form.TextField.SingleLine = true
c.Form.TextField.Submit = true
return c
}
func (c *ConnectFormView) HandleIntent(intent Intent) {}
func (c *ConnectFormView) BecomeVisible() {
}
func (c *ConnectFormView) NavItem() *materials.NavItem {
return nil
}
func (c *ConnectFormView) AppBarData() (bool, string, []materials.AppBarAction, []materials.OverflowAction) {
return false, "", nil, nil
}
func (c *ConnectFormView) Update(gtx layout.Context) {
if c.Form.Submitted() {
c.Settings().SetAddress(c.Form.TextField.Text())
go c.Settings().Persist()
c.Sprout().ConnectTo(c.Settings().Address())
c.manager.RequestViewSwitch(IdentityFormID)
}
}
func (c *ConnectFormView) Layout(gtx layout.Context) layout.Dimensions {
theme := c.Theme().Current()
inset := layout.UniformInset(unit.Dp(8))
return inset.Layout(gtx, func(gtx C) D {
return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
layout.Rigid(func(gtx C) D {
return inset.Layout(gtx,
material.H6(theme.Theme, "Arbor Relay Address:").Layout,
)
}),
layout.Rigid(func(gtx C) D {
return inset.Layout(gtx, sprigTheme.TextForm(theme, &c.Form, "Connect", "HOST:PORT").Layout)
}),
)
})
}
func (c *ConnectFormView) SetManager(mgr ViewManager) {
c.manager = mgr
}