Skip to content

Commit

Permalink
Fixed HUD activation issue & some perf improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
esimov committed Oct 17, 2023
1 parent 31b3710 commit e2137b5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 25 deletions.
18 changes: 10 additions & 8 deletions hud.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
33 changes: 16 additions & 17 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand All @@ -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)
}
Expand All @@ -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()
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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{}
}
}
}
Expand Down

0 comments on commit e2137b5

Please sign in to comment.