gui.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. package main
  2. import (
  3. "fmt"
  4. "fyne.io/fyne/v2"
  5. "fyne.io/fyne/v2/app"
  6. "fyne.io/fyne/v2/container"
  7. "fyne.io/fyne/v2/dialog"
  8. "fyne.io/fyne/v2/driver/desktop"
  9. "fyne.io/fyne/v2/widget"
  10. )
  11. var APP fyne.App
  12. var HOME fyne.Window
  13. func SetupApp() {
  14. APP = app.NewWithID("apollox.endless-edit")
  15. HOME = APP.NewWindow("Endless Edit")
  16. HOME.CenterOnScreen()
  17. HOME.Resize(fyne.NewSize(1000, 800))
  18. }
  19. func SetupHome() {
  20. if HOME == nil {
  21. return
  22. }
  23. meta := APP.Metadata()
  24. // Assign short cuts
  25. new_short := &desktop.CustomShortcut{
  26. fyne.KeyN,
  27. fyne.KeyModifierControl,
  28. }
  29. open_short := &desktop.CustomShortcut{
  30. fyne.KeyO,
  31. fyne.KeyModifierControl,
  32. }
  33. save_short := &desktop.CustomShortcut{
  34. fyne.KeyS,
  35. fyne.KeyModifierControl,
  36. }
  37. about_short := &desktop.CustomShortcut{
  38. fyne.KeyH,
  39. fyne.KeyModifierControl,
  40. }
  41. quit_short := &desktop.CustomShortcut{
  42. fyne.KeyQ,
  43. fyne.KeyModifierControl,
  44. }
  45. // For now most stuff just prints out into the terminal/console what we clicked (except about and quit)
  46. file_new := fyne.NewMenuItem("New", func() { // CTRL + N
  47. fmt.Println("File>New")
  48. })
  49. file_new.Shortcut = new_short
  50. file_open := fyne.NewMenuItem("Open", func() { // CTRL + O
  51. fmt.Println("File>Open")
  52. })
  53. file_open.Shortcut = open_short
  54. file_save := fyne.NewMenuItem("Save", func() { // CTRL + S
  55. fmt.Println("File>Save")
  56. })
  57. file_save.Shortcut = save_short
  58. showing_about := false
  59. about := func() {
  60. d := dialog.NewCustom("About - Endless Edit", "Close", container.NewVBox(
  61. container.NewGridWithColumns(2,
  62. widget.NewLabel("Endless Edit"), widget.NewLabel(meta.Version),
  63. widget.NewLabel("Apollo"), widget.NewLabel("© 2022"),
  64. ),
  65. ), HOME)
  66. d.SetOnClosed(func() {
  67. if showing_about {
  68. showing_about = false
  69. }
  70. })
  71. if !showing_about {
  72. showing_about = true
  73. d.Show()
  74. }
  75. }
  76. file_about := fyne.NewMenuItem("About", about) // CTRL + H
  77. file_about.Shortcut = about_short
  78. file_quit := fyne.NewMenuItem("Quit", func() { // CTRL + Q
  79. APP.Quit()
  80. })
  81. file_quit.Shortcut = quit_short
  82. file := fyne.NewMenu("File",
  83. file_new,
  84. file_open,
  85. file_save,
  86. fyne.NewMenuItemSeparator(),
  87. file_about,
  88. file_quit,
  89. )
  90. HOME.Canvas().AddShortcut(new_short, func(shortcut fyne.Shortcut) {
  91. fmt.Println("File>New (Via Shortcut)")
  92. })
  93. HOME.Canvas().AddShortcut(quit_short, func(shortcut fyne.Shortcut) {
  94. APP.Quit()
  95. })
  96. HOME.Canvas().AddShortcut(open_short, func(shortcut fyne.Shortcut) {
  97. fmt.Println("File>Open (Via Shortcut)")
  98. })
  99. HOME.Canvas().AddShortcut(save_short, func(shortcut fyne.Shortcut) {
  100. fmt.Println("File>Save (Via Shortcut)")
  101. })
  102. HOME.Canvas().AddShortcut(about_short, func(shortcut fyne.Shortcut) {
  103. about()
  104. })
  105. HOME.SetMainMenu(fyne.NewMainMenu(
  106. file,
  107. fyne.NewMenu("Edit", // This will most likely become AppTabs instead (as we'll be editing Profile, Account, Conditions and Ships)
  108. fyne.NewMenuItem("Profile", func() {
  109. fmt.Println("Edit>Profile")
  110. }),
  111. fyne.NewMenuItem("Ships", func() {
  112. fmt.Println("Edit>Ships")
  113. }),
  114. fyne.NewMenuItem("Account", func() {
  115. fmt.Println("Edit>Account")
  116. }),
  117. ),
  118. ))
  119. }