From 6e020858d96691d51fb54cc3fd95d11a14d8a1fb Mon Sep 17 00:00:00 2001 From: Greg Date: Fri, 6 Dec 2019 12:58:40 -0500 Subject: [PATCH] Layout improvements: do not draw the stopwatch if there is not enough room for it. --- main.go | 47 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/main.go b/main.go index c47d371..b26791b 100644 --- a/main.go +++ b/main.go @@ -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)