Skip to content

Commit

Permalink
HUD adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
esimov committed Nov 4, 2023
1 parent 3112c0f commit c3ca002
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 24 deletions.
26 changes: 11 additions & 15 deletions help.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import (

type help struct {
fontType font.Typeface
lineHeight unit.Dp
h1FontSize unit.Sp
h2FontSize unit.Sp
lineHeight int
h1FontSize int
h2FontSize int
}

type command map[string]string
Expand Down Expand Up @@ -47,17 +47,13 @@ func (h *Hud) ShowHelpDialog(gtx layout.Context, th *material.Theme, isActive bo
centerX := windowWidth / 2
centerY := windowHeight / 2

fontSize := h.h1FontSize
lineHeight := h.lineHeight

switch width := windowWidth; {
case width <= windowSizeX*1.4:
panelWidth = windowWidth / 2
switch width := gtx.Dp(unit.Dp(windowWidth)); {
case width <= windowSizeX:
panelWidth = gtx.Dp(unit.Dp(windowWidth / 2))
default:
panelWidth = windowWidth / 3
panelWidth = gtx.Dp(unit.Dp(windowWidth / 3))
}

panelHeight = len(h.commands) * gtx.Sp(fontSize) * gtx.Dp(lineHeight)
panelHeight = gtx.Dp(unit.Dp(300))

px := panelWidth / 2
py := panelHeight / 2
Expand Down Expand Up @@ -95,7 +91,7 @@ func (h *Hud) ShowHelpDialog(gtx layout.Context, th *material.Theme, isActive bo
return layout.UniformInset(20).Layout(gtx, func(gtx C) D {
layout.Center.Layout(gtx, func(gtx C) D {
h1 := material.H2(th, "Quick help")
h1.TextSize = h.h1FontSize
h1.TextSize = unit.Sp(h.h1FontSize)
h1.Font.Typeface = h.fontType
h1.Font.Weight = font.SemiBold

Expand All @@ -115,7 +111,7 @@ func (h *Hud) ShowHelpDialog(gtx layout.Context, th *material.Theme, isActive bo
}
}
h2 := material.H2(th, builder.String())
h2.TextSize = h.h2FontSize
h2.TextSize = unit.Sp(h.h2FontSize)
h2.Font.Typeface = h.fontType
h2.Font.Weight = font.Weight(font.SemiBold)

Expand All @@ -134,7 +130,7 @@ func (h *Hud) ShowHelpDialog(gtx layout.Context, th *material.Theme, isActive bo
}
}
h2 := material.H2(th, builder.String())
h2.TextSize = h.h2FontSize
h2.TextSize = unit.Sp(h.h2FontSize)
h2.Font.Typeface = h.fontType
h2.Font.Weight = font.Weight(font.Regular)

Expand Down
15 changes: 7 additions & 8 deletions hud.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ func NewHud() *Hud {
commands: make(map[int]command),
help: &help{
fontType: "AlbertSans",
lineHeight: unit.Dp(3),
h1FontSize: unit.Sp(18),
h2FontSize: unit.Sp(15),
lineHeight: 3,
h1FontSize: 18,
h2FontSize: 15,
},
}

Expand Down Expand Up @@ -208,14 +208,13 @@ func (h *Hud) ShowControlPanel(gtx layout.Context, th *material.Theme, isActive
pointer.CursorPointer.Add(gtx.Ops)

/* Draw HUD Contents */
sectionWidth := gtx.Dp(unit.Dp(h.panelWidth / 3))
layout.Flex{
Spacing: layout.SpaceEnd,
}.Layout(gtx,
layout.Rigid(func(gtx C) D {
gtx.Constraints.Min.X = sectionWidth
gtx.Constraints.Max.X = sectionWidth
layout := layout.UniformInset(unit.Dp(10)).Layout(gtx, func(gtx C) D {
gtx.Constraints.Min.X = h.panelWidth / 3
gtx.Constraints.Max.X = gtx.Constraints.Min.X
layout := layout.UniformInset(unit.Dp(20)).Layout(gtx, func(gtx C) D {
return h.list.Layout(gtx, len(h.sliders),
func(gtx C, index int) D {
if slider, ok := h.sliders[index]; ok {
Expand Down Expand Up @@ -253,7 +252,7 @@ func (h *Hud) ShowControlPanel(gtx layout.Context, th *material.Theme, isActive
defer op.Offset(image.Point{Y: txtOffs}).Push(gtx.Ops).Pop()
return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
layout.Rigid(func(gtx C) D {
return layout.UniformInset(unit.Dp(10)).Layout(gtx, w.Layout)
return layout.Inset{Bottom: 0, Right: unit.Dp(20)}.Layout(gtx, w.Layout)
}),
)
}),
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func loop(w *app.Window) error {
case system.FrameEvent:
start := hrtime.Now()
gtx := layout.NewContext(&ops, e)
hud.panelWidth = windowWidth
hud.panelWidth = gtx.Dp(unit.Dp(windowSizeX))
hud.btnSize = gtx.Dp(unit.Dp(40))
hud.closeBtn = gtx.Dp(unit.Dp(25))

Expand Down

0 comments on commit c3ca002

Please sign in to comment.