From 7f73f451be9577484bb74466826c30d1d9b8bc70 Mon Sep 17 00:00:00 2001 From: esimov Date: Mon, 6 Nov 2023 11:22:47 +0200 Subject: [PATCH] Use gtx.Dp all around --- hud.go | 14 +++++++------- main.go | 3 ++- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/hud.go b/hud.go index 4237362..438adbb 100644 --- a/hud.go +++ b/hud.go @@ -142,7 +142,7 @@ func (h *Hud) ShowControlPanel(gtx layout.Context, th *material.Theme, isActive }.Op()) paint.FillShape(gtx.Ops, color.NRGBA{A: 20}, clip.Rect{ - Max: image.Point{gtx.Constraints.Max.X, gtx.Dp(1)}, + Max: image.Point{gtx.Constraints.Max.X, gtx.Dp(unit.Dp(1))}, }.Op()) } @@ -164,7 +164,7 @@ func (h *Hud) ShowControlPanel(gtx layout.Context, th *material.Theme, isActive paint.FillShape(gtx.Ops, color.NRGBA{A: 0xff}, clip.Stroke{ Path: path.End(), - Width: float32(unit.Dp(3)), + Width: float32(gtx.Dp(unit.Dp(3))), }.Op()) } @@ -173,7 +173,7 @@ func (h *Hud) ShowControlPanel(gtx layout.Context, th *material.Theme, isActive ) paint.FillShape(gtx.Ops, th.ContrastBg, clip.Stroke{ Path: buttonArea.Path(gtx.Ops), - Width: 0.3, + Width: float32(gtx.Dp(unit.Dp(0.2))), }.Op()) buttonStack := buttonArea.Push(gtx.Ops) @@ -278,7 +278,7 @@ func (h *Hud) DrawCtrlBtn(gtx layout.Context, th *material.Theme, isActive bool) } progress := h.ctrlBtn.Update(gtx, isActive || h.activator.Hovered()) - btnWidth := h.ctrlBtn.Animate(progress) * 2.5 + btnWidth := h.ctrlBtn.Animate(progress) * 1.5 var path clip.Path @@ -298,7 +298,7 @@ func (h *Hud) DrawCtrlBtn(gtx layout.Context, th *material.Theme, isActive bool) paint.FillShape(gtx.Ops, color.NRGBA{A: 0xff}, clip.Stroke{ Path: path.End(), - Width: float32(unit.Dp(4)), + Width: float32(gtx.Dp(unit.Dp(2.5))), }.Op()) }(startX+(spacing*i), offset) } @@ -317,7 +317,7 @@ func (h *Hud) DrawCtrlBtn(gtx layout.Context, th *material.Theme, isActive bool) defer clip.Outline{Path: path.End()}.Op().Push(gtx.Ops).Pop() paint.ColorOp{Color: color.NRGBA{A: 0xff}}.Add(gtx.Ops) paint.PaintOp{}.Add(gtx.Ops) - }(startX+(spacing*i), offset+(spacing*i), float32(unit.Dp(6))) + }(startX+(spacing*i), offset+(spacing*i), float32(gtx.Dp(unit.Dp(4.5)))) } } @@ -325,7 +325,7 @@ func (h *Hud) DrawCtrlBtn(gtx layout.Context, th *material.Theme, isActive bool) Path: clip.UniformRRect(image.Rectangle{ Max: image.Pt(h.btnSize, h.btnSize), }, gtx.Dp(10)).Path(gtx.Ops), - Width: 2.0 + float32(btnWidth), + Width: 2.0 + float32(gtx.Dp(unit.Dp(btnWidth))), }.Op().Push(gtx.Ops).Pop() pointer.CursorPointer.Add(gtx.Ops) diff --git a/main.go b/main.go index 649912f..8aee6d4 100644 --- a/main.go +++ b/main.go @@ -167,10 +167,11 @@ func loop(w *app.Window) error { cloth.Reset(startX, startY, hud) case key.NameF1: hud.showHelpPanel = !hud.showHelpPanel + hud.isActive = false } } if e.Name == key.NameEscape { - w.Perform(system.ActionClose) + hud.showHelpPanel = false } } }