diff --git a/main.go b/main.go index b120a85..c4e686f 100644 --- a/main.go +++ b/main.go @@ -5502,12 +5502,6 @@ func (u *ui) header(gtx layout.Context) layout.Dimensions { gtx.Constraints.Min.X = gtx.Constraints.Max.X return u.headerActions(gtx) }), - layout.Rigid(func(gtx layout.Context) layout.Dimensions { - if !u.mainMenuOpen { - return layout.Dimensions{} - } - return layout.Inset{Top: unit.Dp(8)}.Layout(gtx, u.mainMenu) - }), ) } if u.shouldShowDesktopWorkingHeader() { @@ -5542,18 +5536,7 @@ func (u *ui) headerActions(gtx layout.Context) layout.Dimensions { return btn.Layout(gtx) }), layout.Rigid(layout.Spacer{Width: unit.Dp(8)}.Layout), - layout.Rigid(func(gtx layout.Context) layout.Dimensions { - icon := u.menuIcon - if icon == nil { - icon = u.settingsIcon - } - btn := material.IconButton(u.theme, &u.toggleMainMenu, icon, "Menu") - btn.Background = selectedColor - btn.Color = accentColor - btn.Size = unit.Dp(18) - btn.Inset = layout.UniformInset(unit.Dp(8)) - return btn.Layout(gtx) - }), + layout.Rigid(u.mainMenuButtonGroup), ) } if u.mode == "phone" { @@ -6367,24 +6350,7 @@ func (u *ui) detailPanel(gtx layout.Context) layout.Dimensions { return btn.Layout(gtx) }), layout.Rigid(layout.Spacer{Width: unit.Dp(8)}.Layout), - layout.Rigid(func(gtx layout.Context) layout.Dimensions { - icon := u.menuIcon - if icon == nil { - icon = u.settingsIcon - } - btn := material.IconButton(u.theme, &u.toggleMainMenu, icon, "Menu") - btn.Background = selectedColor - btn.Color = accentColor - btn.Size = unit.Dp(18) - btn.Inset = layout.UniformInset(unit.Dp(8)) - return btn.Layout(gtx) - }), - layout.Rigid(func(gtx layout.Context) layout.Dimensions { - if !u.mainMenuOpen { - return layout.Dimensions{} - } - return layout.Inset{Left: unit.Dp(6)}.Layout(gtx, u.mainMenu) - }), + layout.Rigid(u.mainMenuButtonGroup), ) }), layout.Rigid(layout.Spacer{Height: unit.Dp(12)}.Layout), @@ -7207,6 +7173,41 @@ func (u *ui) topRightActionOrder() []string { return []string{"Sync", "Lock", "Menu"} } +func (u *ui) mainMenuButtonGroup(gtx layout.Context) layout.Dimensions { + button := func(gtx layout.Context) layout.Dimensions { + icon := u.menuIcon + if icon == nil { + icon = u.settingsIcon + } + btn := material.IconButton(u.theme, &u.toggleMainMenu, icon, "Menu") + btn.Background = selectedColor + btn.Color = accentColor + btn.Size = unit.Dp(18) + btn.Inset = layout.UniformInset(unit.Dp(8)) + return btn.Layout(gtx) + } + + buttonDims := button(gtx) + if !u.mainMenuOpen { + return buttonDims + } + + menuGTX := gtx + menuGTX.Constraints.Min = image.Point{} + menuOps := op.Record(gtx.Ops) + menuDims := layout.Inset{Top: unit.Dp(6)}.Layout(menuGTX, u.mainMenu) + menuCall := menuOps.Stop() + + menuX := buttonDims.Size.X - menuDims.Size.X + if menuX < 0 { + menuX = 0 + } + stack := op.Offset(image.Pt(menuX, buttonDims.Size.Y)).Push(gtx.Ops) + menuCall.Add(gtx.Ops) + stack.Pop() + return buttonDims +} + func (u *ui) syncMenuDropsBelowTrigger() bool { return true } @@ -7215,6 +7216,14 @@ func (u *ui) syncMenuRightAlignsToTrigger() bool { return true } +func (u *ui) mainMenuDropsBelowTrigger() bool { + return true +} + +func (u *ui) mainMenuRightAlignsToTrigger() bool { + return true +} + func detailLine(th *material.Theme, label, value string) layout.Widget { return func(gtx layout.Context) layout.Dimensions { valueSize := unit.Sp(16) diff --git a/main_test.go b/main_test.go index 064e72f..3aabdac 100644 --- a/main_test.go +++ b/main_test.go @@ -340,6 +340,22 @@ func TestUISyncMenuAnchorsMatchAcrossModes(t *testing.T) { } } +func TestUIMainMenuAnchorsMatchAcrossModes(t *testing.T) { + t.Parallel() + + desktop := newUIWithSession("desktop", summarySession{hasVault: true}) + desktop.state.Section = appstate.SectionEntries + phone := newUIWithSession("phone", summarySession{hasVault: true}) + phone.state.Section = appstate.SectionEntries + + if !desktop.mainMenuDropsBelowTrigger() || !phone.mainMenuDropsBelowTrigger() { + t.Fatal("main menu should drop below trigger across desktop and phone") + } + if !desktop.mainMenuRightAlignsToTrigger() || !phone.mainMenuRightAlignsToTrigger() { + t.Fatal("main menu should right-align to trigger across desktop and phone") + } +} + func TestUICurrentVaultSummary(t *testing.T) { t.Parallel()