Skip to content

Commit

Permalink
Fixed help dialog panel missplaced issue on HiRes device
Browse files Browse the repository at this point in the history
  • Loading branch information
esimov committed Nov 3, 2023
1 parent 8676483 commit 0ed1d49
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
28 changes: 14 additions & 14 deletions help.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ type command map[string]string
// ShowHelpDialog activates a dialog panel whith a list of the available key shortcuts.
func (h *Hud) ShowHelpDialog(gtx layout.Context, th *material.Theme, isActive bool) {
var (
panelWidth unit.Dp
panelHeight unit.Dp
panelWidth int
panelHeight int
)

// show the help dialog panel only if it's not yet activated.
Expand All @@ -44,28 +44,28 @@ func (h *Hud) ShowHelpDialog(gtx layout.Context, th *material.Theme, isActive bo
},
}, 0).Op(gtx.Ops))

centerX := gtx.Dp(unit.Dp(windowWidth / 2))
centerY := gtx.Dp(unit.Dp(windowHeight / 2))
centerX := int(unit.Dp(windowWidth / 2))
centerY := int(unit.Dp(windowHeight / 2))

fontSize := int(unit.Sp(h.h1FontSize))
lineHeight := int(unit.Dp(h.lineHeight))

switch width := windowWidth; {
case width <= windowSizeX*1.4:
panelWidth = unit.Dp(windowWidth / 2)
panelWidth = int(unit.Dp(windowWidth / 2))
default:
panelWidth = unit.Dp(windowWidth / 3)
panelWidth = int(unit.Dp(windowWidth / 3))
}
ph := len(h.commands) * fontSize * lineHeight
panelHeight = unit.Dp(ph)
panelHeight = ph

px := int(unit.Dp(panelWidth / 2))
py := int(unit.Dp(panelHeight / 2))
dx, dy := centerX-px, centerY-py

// Limit the applicable constraints to the panel size from this point onward.
gtx.Constraints.Min.X = gtx.Dp(panelWidth)
gtx.Constraints.Max.X = gtx.Dp(panelWidth)
gtx.Constraints.Min.X = panelWidth
gtx.Constraints.Max.X = panelWidth

// This offset will apply to the rest of the content laid out in this function.
defer op.Offset(image.Point{X: dx, Y: dy}).Push(gtx.Ops).Pop()
Expand All @@ -77,16 +77,16 @@ func (h *Hud) ShowHelpDialog(gtx layout.Context, th *material.Theme, isActive bo
paint.FillShape(gtx.Ops, color.NRGBA{R: 0xff, G: 0xff, B: 0xff, A: 0xff},
clip.UniformRRect(image.Rectangle{
Max: image.Point{
X: gtx.Dp(panelWidth),
Y: gtx.Dp(panelHeight),
X: panelWidth,
Y: panelHeight,
},
}, gtx.Dp(5)).Op(gtx.Ops))

paint.FillShape(gtx.Ops, color.NRGBA{A: 127},
clip.Stroke{
Path: clip.Rect{Max: image.Point{
X: gtx.Dp(panelWidth),
Y: gtx.Dp(panelHeight),
X: panelWidth,
Y: panelHeight,
}}.Path(),
Width: 0.2,
}.Op(),
Expand All @@ -105,7 +105,7 @@ func (h *Hud) ShowHelpDialog(gtx layout.Context, th *material.Theme, isActive bo
)
})
colOffset := unit.Dp(200)
gtx.Constraints.Min.X = gtx.Dp(panelWidth - layoutOffset - colOffset)
gtx.Constraints.Min.X = panelWidth - int(layoutOffset) - int(colOffset)

defer op.Offset(image.Point{X: 0, Y: 50}).Push(gtx.Ops).Pop()
h.list.Layout(gtx, len(h.commands),
Expand Down
3 changes: 3 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ func loop(w *app.Window) error {
hud.showHelpPanel = !hud.showHelpPanel
}
}
if e.Name == key.NameEscape {
w.Perform(system.ActionClose)
}
}
}

Expand Down

0 comments on commit 0ed1d49

Please sign in to comment.