Layout improvements: do not draw the stopwatch if there is not

enough room for it.
This commit is contained in:
Greg 2019-12-06 12:58:40 -05:00
parent 31fa374c7f
commit 6e020858d9

27
main.go
View File

@ -300,10 +300,8 @@ func eventloop() {
} }
swidth := new(int) swidth := new(int)
*swidth = 900
hrpage = func() { hrpage = func() {
stopbtn := func() { stopbtn := func() {
gtx.Constraints.Width.Min = *swidth
gtx.Constraints.Height.Min = 100 gtx.Constraints.Height.Min = 100
layout.UniformInset(unit.Dp(2)).Layout(gtx, func() { layout.UniformInset(unit.Dp(2)).Layout(gtx, func() {
th.Button("Disconnect").Layout(gtx, backBtn) th.Button("Disconnect").Layout(gtx, backBtn)
@ -325,7 +323,10 @@ func eventloop() {
*swidth = s2 *swidth = s2
} }
}) })
c3 := f3.Rigid(gtx, stopwatch) var c3 layout.FlexChild
if gtx.Constraints.Width.Max > 370 {
c3 = f3.Rigid(gtx, stopwatch)
}
c4 := f3.Rigid(gtx, stopbtn) c4 := f3.Rigid(gtx, stopbtn)
f3.Layout(gtx, f3.Layout(gtx,
c1, c1,
@ -346,9 +347,26 @@ func eventloop() {
stopwatch() stopwatch()
}) })
}) })
swheight := gtx.Dimensions.Size.Y
c2 := f.Rigid(gtx, func() { c2 := f.Rigid(gtx, func() {
layout.Align(layout.Center).Layout(gtx, stopbtn) layout.Align(layout.Center).Layout(gtx, func() {
gtx.Constraints.Width.Min = *swidth
gtx.Constraints.Width.Max = *swidth
stopbtn()
}) })
})
if gtx.Constraints.Height.Max < 775 {
gtx.Constraints.Height.Max += swheight
f.Layout(gtx,
f.Rigid(gtx, appname),
f.Rigid(gtx, appstate),
f.Rigid(gtx, periphname),
f.Flex(gtx, 1.0, func() {
*swidth = hrcircle()
}),
c2,
)
} else {
f.Layout(gtx, f.Layout(gtx,
f.Rigid(gtx, appname), f.Rigid(gtx, appname),
f.Rigid(gtx, appstate), f.Rigid(gtx, appstate),
@ -360,6 +378,7 @@ func eventloop() {
c2, c2,
) )
} }
}
if backBtn.Clicked(gtx) { if backBtn.Clicked(gtx) {
ble.Disconnect(periph) ble.Disconnect(periph)
periphs = periphs[:0] periphs = periphs[:0]