refactor(tracker): remove Contents from PopupStyle; pass it to Layout instead

This commit is contained in:
vsariola 2021-02-03 16:34:22 +02:00
parent 21b620c824
commit 29b289d2fb
2 changed files with 5 additions and 7 deletions

View File

@ -14,7 +14,6 @@ import (
type PopupStyle struct {
Visible *bool
Contents layout.Widget
SurfaceColor color.NRGBA
ShadowColor color.NRGBA
ShadowN unit.Value
@ -24,10 +23,9 @@ type PopupStyle struct {
SE, SW, NW, NE unit.Value
}
func Popup(visible *bool, contents layout.Widget) PopupStyle {
func Popup(visible *bool) PopupStyle {
return PopupStyle{
Visible: visible,
Contents: contents,
SurfaceColor: popupSurfaceColor,
ShadowColor: popupShadowColor,
ShadowN: unit.Dp(2),
@ -41,7 +39,7 @@ func Popup(visible *bool, contents layout.Widget) PopupStyle {
}
}
func (s PopupStyle) Layout(gtx C) D {
func (s PopupStyle) Layout(gtx C, contents layout.Widget) D {
if !*s.Visible {
return D{}
}
@ -78,7 +76,7 @@ func (s PopupStyle) Layout(gtx C) D {
macro := op.Record(gtx.Ops)
dims := layout.Stack{}.Layout(gtx,
layout.Expanded(bg),
layout.Stacked(s.Contents),
layout.Stacked(contents),
)
callop := macro.Stop()
op.Defer(gtx.Ops, callop)

View File

@ -58,7 +58,7 @@ func (t *Tracker) layoutSongButtons(gtx C) D {
)
}
fileMenu := Popup(&t.FileMenuVisible, menuContents)
fileMenu := Popup(&t.FileMenuVisible)
fileMenu.NE = unit.Dp(0)
fileMenu.ShadowN = unit.Dp(0)
fileMenu.NW = unit.Dp(0)
@ -83,7 +83,7 @@ func (t *Tracker) layoutSongButtons(gtx C) D {
op.Offset(f32.Pt(0, float32(dims.Size.Y))).Add(gtx.Ops)
gtx.Constraints.Max.X = 160
gtx.Constraints.Max.Y = 300
fileMenu.Layout(gtx)
fileMenu.Layout(gtx, menuContents)
return dims
}