Skip to content

Commit

Permalink
add the main menu and the quit action
Browse files Browse the repository at this point in the history
  • Loading branch information
ftl committed Nov 30, 2024
1 parent 33f09d8 commit 843917a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
4 changes: 4 additions & 0 deletions fyneui/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type application struct {

app fyne.App
mainWindow *mainWindow
mainMenu *mainMenu

controller *app.Controller
}
Expand All @@ -43,8 +44,11 @@ func (a *application) activate() {
log.Fatal(err)
}
a.controller = app.NewController(a.version, clock.New(), a.app, a.runAsync, configuration, a.sponsors)
a.controller.Startup()

a.mainWindow = setupMainWindow(a.app.NewWindow("Hello Contest"))
a.mainMenu = setupMainMenu(a.mainWindow.window, a.controller)

a.mainWindow.UseDefaultWindowGeometry() // TODO: store/restore the window geometry
a.mainWindow.Show()
}
Expand Down
32 changes: 32 additions & 0 deletions fyneui/mainMenu.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package fyneui

import "fyne.io/fyne/v2"

type MainMenuController interface {
Quit()
}

type mainMenu struct {
controller MainMenuController

fileQuit *fyne.MenuItem
}

func setupMainMenu(mainWindow fyne.Window, controller MainMenuController) *mainMenu {
result := &mainMenu{
controller: controller,
}

result.fileQuit = fyne.NewMenuItem("Quit", result.onFileQuit)
result.fileQuit.IsQuit = true

fileMenu := fyne.NewMenu("File", result.fileQuit)
mainMenu := fyne.NewMainMenu(fileMenu)
mainWindow.SetMainMenu(mainMenu)

return result
}

func (m *mainMenu) onFileQuit() {
m.controller.Quit()
}

0 comments on commit 843917a

Please sign in to comment.