From e2137b5abb48f2e6e28dbdd456f089abee9cd902 Mon Sep 17 00:00:00 2001 From: esimov Date: Tue, 17 Oct 2023 17:29:55 +0300 Subject: [PATCH] Fixed HUD activation issue & some perf improvements --- hud.go | 18 ++++++++++-------- main.go | 33 ++++++++++++++++----------------- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/hud.go b/hud.go index 13d2c3f..5172120 100644 --- a/hud.go +++ b/hud.go @@ -28,20 +28,21 @@ type ( ) type Hud struct { - activator gesture.Click - reset widget.Clickable - controls gesture.Hover - closer gesture.Click hudTag struct{} + panelInit time.Time + ctrlBtn *Easing sliders map[int]*slider slide *Easing - ctrlBtn *Easing + reset widget.Clickable + debug widget.Bool list layout.List + activator gesture.Click + closer gesture.Click width int height int closeBtn int btnSize int - debug widget.Bool + controls gesture.Hover isActive bool } @@ -243,13 +244,14 @@ func (h *Hud) DrawCtrlBtn(gtx layout.Context, th *material.Theme, m *Mouse, isAc return layout.UniformInset(unit.Dp(10)).Layout(gtx, func(gtx C) D { for _, e := range h.activator.Events(gtx) { if e.Type == gesture.ClickType(pointer.Press) { + h.panelInit = time.Now() h.isActive = true break } } progress := h.ctrlBtn.Update(gtx, isActive || h.activator.Hovered()) - btnWidth := h.ctrlBtn.Animate(progress) * float64(unit.Dp(3)) + btnWidth := h.ctrlBtn.Animate(progress) * 2.5 var path clip.Path @@ -296,7 +298,7 @@ func (h *Hud) DrawCtrlBtn(gtx layout.Context, th *material.Theme, m *Mouse, isAc Path: clip.UniformRRect(image.Rectangle{ Max: image.Pt(h.btnSize, h.btnSize), }, gtx.Dp(10)).Path(gtx.Ops), - Width: 1.5 + float32(btnWidth), + Width: 2.0 + float32(btnWidth), }.Op().Push(gtx.Ops).Pop() pointer.CursorPointer.Add(gtx.Ops) diff --git a/main.go b/main.go index 7f75181..84084dc 100644 --- a/main.go +++ b/main.go @@ -32,8 +32,15 @@ var ( windowWidth = 940 windowHeight = 580 + // Gio Ops related variables + ops op.Ops + initTime time.Time + deltaTime time.Duration + scrollY unit.Dp + + // pprof related variables profile string - f *os.File + file *os.File err error ) @@ -42,7 +49,7 @@ func main() { flag.Parse() if profile != "" { - f, err = os.Create(profile) + file, err = os.Create(profile) if err != nil { log.Fatal(err) } @@ -63,14 +70,6 @@ func main() { } func loop(w *app.Window) error { - var ( - ops op.Ops - initTime time.Time - deltaTime time.Duration - panelInit time.Time - scrollY unit.Dp - ) - if profile != "" { defer pprof.StopCPUProfile() } @@ -107,18 +106,18 @@ func loop(w *app.Window) error { hud.closeBtn = gtx.Dp(unit.Dp(25)) if hud.isActive { - if !panelInit.IsZero() { - dt := time.Since(panelInit).Seconds() + if !hud.panelInit.IsZero() { + dt := time.Since(hud.panelInit).Seconds() if dt > hudTimeout { hud.isActive = false } } } else { - panelInit = time.Time{} + hud.panelInit = time.Time{} } if profile != "" { - pprof.StartCPUProfile(f) + pprof.StartCPUProfile(file) } if !cloth.isInitialized { @@ -268,11 +267,11 @@ func loop(w *app.Window) error { case pointer.Event: switch ev.Type { case pointer.Leave: - if panelInit.IsZero() { - panelInit = time.Now() + if hud.panelInit.IsZero() { + hud.panelInit = time.Now() } case pointer.Move: - panelInit = time.Time{} + hud.panelInit = time.Time{} } } }