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 := 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,19 +347,37 @@ 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()
})
}) })
f.Layout(gtx, if gtx.Constraints.Height.Max < 775 {
f.Rigid(gtx, appname), gtx.Constraints.Height.Max += swheight
f.Rigid(gtx, appstate), f.Layout(gtx,
f.Rigid(gtx, periphname), f.Rigid(gtx, appname),
f.Flex(gtx, 1.0, func() { f.Rigid(gtx, appstate),
*swidth = hrcircle() f.Rigid(gtx, periphname),
}), f.Flex(gtx, 1.0, func() {
c1, *swidth = hrcircle()
c2, }),
) 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) { if backBtn.Clicked(gtx) {
ble.Disconnect(periph) ble.Disconnect(periph)