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
1 changed files with 33 additions and 14 deletions

47
main.go
View File

@ -300,10 +300,8 @@ func eventloop() {
}
swidth := new(int)
*swidth = 900
hrpage = func() {
stopbtn := func() {
gtx.Constraints.Width.Min = *swidth
gtx.Constraints.Height.Min = 100
layout.UniformInset(unit.Dp(2)).Layout(gtx, func() {
th.Button("Disconnect").Layout(gtx, backBtn)
@ -325,7 +323,10 @@ func eventloop() {
*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)
f3.Layout(gtx,
c1,
@ -346,19 +347,37 @@ func eventloop() {
stopwatch()
})
})
swheight := gtx.Dimensions.Size.Y
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()
})
})
f.Layout(gtx,
f.Rigid(gtx, appname),
f.Rigid(gtx, appstate),
f.Rigid(gtx, periphname),
f.Flex(gtx, 1.0, func() {
*swidth = hrcircle()
}),
c1,
c2,
)
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.Rigid(gtx, appname),
f.Rigid(gtx, appstate),
f.Rigid(gtx, periphname),
f.Flex(gtx, 1.0, func() {
*swidth = hrcircle()
}),
c1,
c2,
)
}
}
if backBtn.Clicked(gtx) {
ble.Disconnect(periph)