UI enhancements for horizontal mode, intermediate checkin.
This commit is contained in:
parent
265caa30a2
commit
14bbbf0679
228
main.go
228
main.go
|
@ -102,6 +102,7 @@ func eventloop() {
|
|||
state := "starting"
|
||||
var hr int
|
||||
var periph ble.Peripheral
|
||||
var wide bool
|
||||
periphs := make([]ble.Peripheral, 0)
|
||||
btns := make([]*widget.Button, 0)
|
||||
backBtn := &widget.Button{}
|
||||
|
@ -110,118 +111,136 @@ func eventloop() {
|
|||
|
||||
f := &layout.Flex{Axis: layout.Vertical}
|
||||
offpage = func() {
|
||||
c1 := f.Rigid(gtx, func() {
|
||||
th.Body1("Heart Rate Monitor").Layout(gtx)
|
||||
})
|
||||
c2 := f.Rigid(gtx, func() {
|
||||
th.Body1("Bluetooth is Powered Off").Layout(gtx)
|
||||
})
|
||||
f.Layout(gtx, c1, c2)
|
||||
f.Layout(gtx,
|
||||
f.Rigid(gtx, func() {
|
||||
th.Body1("Heart Rate Monitor").Layout(gtx)
|
||||
}),
|
||||
f.Rigid(gtx, func() {
|
||||
th.Body1("Bluetooth is Powered Off").Layout(gtx)
|
||||
}),
|
||||
)
|
||||
}
|
||||
scanpage = func() {
|
||||
c1 := f.Rigid(gtx, func() {
|
||||
th.Body1("Heart Rate Monitor").Layout(gtx)
|
||||
})
|
||||
c2 := f.Rigid(gtx, func() {
|
||||
th.Body1(state).Layout(gtx)
|
||||
})
|
||||
c3 := f.Rigid(gtx, func() {
|
||||
lst := &layout.List{Axis: layout.Vertical}
|
||||
lst.Layout(gtx, len(periphs), func(i int) {
|
||||
gtx.Constraints.Width.Min = gtx.Constraints.Width.Max
|
||||
layout.UniformInset(unit.Dp(2)).Layout(gtx, func() {
|
||||
th.Button(periphs[i].Name).Layout(gtx, btns[i])
|
||||
})
|
||||
if btns[i].Clicked(gtx) {
|
||||
b.StopScan()
|
||||
periph = periphs[i]
|
||||
b.Connect(periph)
|
||||
state = "connecting"
|
||||
page = connpage
|
||||
w.Invalidate()
|
||||
}
|
||||
|
||||
appname := func() { th.Body1("Heart Rate Monitor").Layout(gtx) }
|
||||
appstate := func() { th.Body1(state).Layout(gtx) }
|
||||
periphname := func() { th.Body1(periph.Name).Layout(gtx) }
|
||||
|
||||
leftbar := func() {
|
||||
f := &layout.Flex{Axis: layout.Vertical}
|
||||
f.Layout(gtx,
|
||||
f.Rigid(gtx, appname),
|
||||
f.Rigid(gtx, func() { th.Body1("").Layout(gtx) }),
|
||||
f.Rigid(gtx, appstate),
|
||||
)
|
||||
}
|
||||
|
||||
scanlist := func() {
|
||||
lst := &layout.List{Axis: layout.Vertical}
|
||||
lst.Layout(gtx, len(periphs), func(i int) {
|
||||
gtx.Constraints.Width.Min = gtx.Constraints.Width.Max
|
||||
layout.UniformInset(unit.Dp(2)).Layout(gtx, func() {
|
||||
th.Button(periphs[i].Name).Layout(gtx, btns[i])
|
||||
})
|
||||
if btns[i].Clicked(gtx) {
|
||||
b.StopScan()
|
||||
periph = periphs[i]
|
||||
b.Connect(periph)
|
||||
state = "connecting"
|
||||
page = connpage
|
||||
w.Invalidate()
|
||||
}
|
||||
})
|
||||
f.Layout(gtx, c1, c2, c3)
|
||||
}
|
||||
|
||||
scanpage = func() {
|
||||
if wide {
|
||||
f2 := &layout.Flex{Axis: layout.Horizontal}
|
||||
f2.Layout(gtx,
|
||||
f2.Flex(gtx, 0.2, leftbar),
|
||||
f2.Rigid(gtx, scanlist),
|
||||
)
|
||||
} else {
|
||||
f.Layout(gtx,
|
||||
f.Rigid(gtx, appname),
|
||||
f.Rigid(gtx, appstate),
|
||||
f.Rigid(gtx, scanlist),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
connpage = func() {
|
||||
c1 := f.Rigid(gtx, func() {
|
||||
th.Body1("Heart Rate Monitor").Layout(gtx)
|
||||
f.Layout(gtx,
|
||||
f.Rigid(gtx, appname),
|
||||
f.Rigid(gtx, func() {
|
||||
th.Body1("Connecting").Layout(gtx)
|
||||
}),
|
||||
f.Rigid(gtx, periphname),
|
||||
f.Rigid(gtx, func() {
|
||||
th.Button("Cancel").Layout(gtx, backBtn)
|
||||
if backBtn.Clicked(gtx) {
|
||||
ble.CancelConnection(periph)
|
||||
periphs = periphs[:0]
|
||||
Config.Autoconnect = ""
|
||||
saveConfig()
|
||||
b.Scan()
|
||||
state = "scanning"
|
||||
page = scanpage
|
||||
}
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
hrcircle := func() {
|
||||
blue := color.RGBA{0x3f, 0x51, 0xb5, 255}
|
||||
white := color.RGBA{255, 255, 255, 255}
|
||||
w, h1 := float32(gtx.Constraints.Width.Max), float32(gtx.Constraints.Height.Max)
|
||||
if w < h1 {
|
||||
h1 = w
|
||||
}
|
||||
s2 := h1 * 0.9
|
||||
r1 := f32.Rectangle{f32.Point{0, 0}, f32.Point{h1, h1}}
|
||||
p2a := f32.Point{(h1-s2)/2, (h1-s2)/2}
|
||||
p2b := f32.Point{s2 + (h1-s2)/2, s2 + (h1-s2)/2}
|
||||
r2 := f32.Rectangle{p2a, p2b}
|
||||
clip.Rect{ Rect: r1, NE: h1/2, NW: h1/2, SE: h1/2, SW: h1/2}.Op(gtx.Ops).Add(gtx.Ops)
|
||||
paint.ColorOp{Color: blue}.Add(gtx.Ops)
|
||||
paint.PaintOp{Rect: r1}.Add(gtx.Ops)
|
||||
clip.Rect{ Rect: r2, NE: s2/2, NW: s2/2, SE: s2/2, SW: s2/2}.Op(gtx.Ops).Add(gtx.Ops)
|
||||
paint.ColorOp{Color: white}.Add(gtx.Ops)
|
||||
paint.PaintOp{Rect: r2}.Add(gtx.Ops)
|
||||
op.TransformOp{}.Offset(p2a).Add(gtx.Ops)
|
||||
gtx.Constraints.Width.Max = int(s2)
|
||||
gtx.Constraints.Height.Max = int(s2)
|
||||
gtx.Constraints.Width.Min = int(s2)
|
||||
gtx.Constraints.Height.Min = int(s2)
|
||||
l := th.H1(fmt.Sprintf("%d", hr))
|
||||
l.Alignment = text.Middle
|
||||
layout.Align(layout.Center).Layout(gtx, func() {
|
||||
l.Layout(gtx)
|
||||
})
|
||||
c2 := f.Rigid(gtx, func() {
|
||||
th.Body1("Connecting").Layout(gtx)
|
||||
})
|
||||
c3 := f.Rigid(gtx, func() {
|
||||
th.Body1(periph.Name).Layout(gtx)
|
||||
})
|
||||
c4 := f.Rigid(gtx, func() {
|
||||
th.Button("Cancel").Layout(gtx, backBtn)
|
||||
if backBtn.Clicked(gtx) {
|
||||
ble.CancelConnection(periph)
|
||||
periphs = periphs[:0]
|
||||
Config.Autoconnect = ""
|
||||
saveConfig()
|
||||
b.Scan()
|
||||
state = "scanning"
|
||||
page = scanpage
|
||||
}
|
||||
})
|
||||
f.Layout(gtx, c1, c2, c3, c4)
|
||||
gtx.Dimensions.Size = image.Point{int(h1), int(h1)}
|
||||
}
|
||||
|
||||
hrpage = func() {
|
||||
c1 := f.Rigid(gtx, func() {
|
||||
th.Body1("Heart Rate Monitor").Layout(gtx)
|
||||
})
|
||||
c2 := f.Rigid(gtx, func() {
|
||||
th.Body1(periph.Name).Layout(gtx)
|
||||
})
|
||||
c4 := f.Rigid(gtx, func() {
|
||||
layout.UniformInset(unit.Dp(2)).Layout(gtx, func() {
|
||||
th.Button("Stop").Layout(gtx, backBtn)
|
||||
})
|
||||
if backBtn.Clicked(gtx) {
|
||||
ble.Disconnect(periph)
|
||||
periphs = periphs[:0]
|
||||
Config.Autoconnect = ""
|
||||
saveConfig()
|
||||
b.Scan()
|
||||
state = "scanning"
|
||||
page = scanpage
|
||||
}
|
||||
})
|
||||
c3 := f.Rigid(gtx, func() {
|
||||
blue := color.RGBA{0x3f, 0x51, 0xb5, 255}
|
||||
white := color.RGBA{255, 255, 255, 255}
|
||||
w, h1 := float32(gtx.Constraints.Width.Max), float32(gtx.Constraints.Height.Max)
|
||||
if w < h1 {
|
||||
h1 = w
|
||||
}
|
||||
s2 := h1 * 0.9
|
||||
r1 := f32.Rectangle{f32.Point{0, 0}, f32.Point{h1, h1}}
|
||||
p2a := f32.Point{(h1-s2)/2, (h1-s2)/2}
|
||||
p2b := f32.Point{s2 + (h1-s2)/2, s2 + (h1-s2)/2}
|
||||
r2 := f32.Rectangle{p2a, p2b}
|
||||
clip.Rect{ Rect: r1, NE: h1/2, NW: h1/2, SE: h1/2, SW: h1/2}.Op(gtx.Ops).Add(gtx.Ops)
|
||||
paint.ColorOp{Color: blue}.Add(gtx.Ops)
|
||||
paint.PaintOp{Rect: r1}.Add(gtx.Ops)
|
||||
clip.Rect{ Rect: r2, NE: s2/2, NW: s2/2, SE: s2/2, SW: s2/2}.Op(gtx.Ops).Add(gtx.Ops)
|
||||
paint.ColorOp{Color: white}.Add(gtx.Ops)
|
||||
paint.PaintOp{Rect: r2}.Add(gtx.Ops)
|
||||
op.TransformOp{}.Offset(p2a).Add(gtx.Ops)
|
||||
gtx.Constraints.Width.Max = int(s2)
|
||||
gtx.Constraints.Height.Max = int(s2)
|
||||
gtx.Constraints.Width.Min = int(s2)
|
||||
gtx.Constraints.Height.Min = int(s2)
|
||||
l := th.H1(fmt.Sprintf("%d", hr))
|
||||
l.Alignment = text.Middle
|
||||
layout.Align(layout.Center).Layout(gtx, func() {
|
||||
l.Layout(gtx)
|
||||
})
|
||||
gtx.Dimensions.Size = image.Point{int(h1), int(h1)}
|
||||
})
|
||||
f.Layout(gtx, c1, c2, c3, c4)
|
||||
f.Layout(gtx,
|
||||
f.Rigid(gtx, appname),
|
||||
f.Rigid(gtx, periphname),
|
||||
f.Rigid(gtx, func() {
|
||||
layout.UniformInset(unit.Dp(2)).Layout(gtx, func() {
|
||||
th.Button("Stop").Layout(gtx, backBtn)
|
||||
})
|
||||
if backBtn.Clicked(gtx) {
|
||||
ble.Disconnect(periph)
|
||||
periphs = periphs[:0]
|
||||
Config.Autoconnect = ""
|
||||
saveConfig()
|
||||
b.Scan()
|
||||
state = "scanning"
|
||||
page = scanpage
|
||||
}
|
||||
}),
|
||||
f.Rigid(gtx, hrcircle),
|
||||
)
|
||||
}
|
||||
|
||||
page = offpage
|
||||
|
@ -297,6 +316,11 @@ func eventloop() {
|
|||
return
|
||||
case system.FrameEvent:
|
||||
gtx.Reset(e.Config, e.Size)
|
||||
if e.Size.X > e.Size.Y {
|
||||
wide = true
|
||||
} else {
|
||||
wide = false
|
||||
}
|
||||
resetSysinset(e.Insets)
|
||||
sysinset.Layout(gtx, func() {
|
||||
margin.Layout(gtx, page)
|
||||
|
|
Loading…
Reference in New Issue
Block a user