menu.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // Copyright 2016 The G3N Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package gui
  5. import (
  6. "github.com/g3n/engine/math32"
  7. )
  8. type MenuBar struct {
  9. }
  10. type Menu struct {
  11. Panel // embedded panel
  12. items []*MenuItem // menu items
  13. }
  14. // Menu style
  15. type MenuStyle struct {
  16. Border BorderSizes
  17. Paddings BorderSizes
  18. BorderColor math32.Color4
  19. BgColor math32.Color4
  20. FgColor math32.Color4
  21. }
  22. type MenuItem struct {
  23. Panel // embedded panel
  24. label *Label // optional internal label (nil for separators)
  25. image *Image // optional left internal image
  26. licon *Label // optional left internal icon label
  27. ricon *Label // optional right internal icon label for submenu
  28. icode int // icon code (if icon is set)
  29. subm *MenuItem // optional pointer to sub menu
  30. shorcut int32 // shortcut code
  31. enabled bool // enabled state
  32. }
  33. // NewMenu creates and returns a pointer to a new empty menu
  34. func NewMenu() *Menu {
  35. m := new(Menu)
  36. // Initializes the panel
  37. m.Panel.Initialize(0, 0)
  38. m.items = make([]*MenuItem, 0)
  39. return m
  40. }
  41. // AddItem creates and adds a new menu item to this menu and returns the pointer
  42. // to the created item.
  43. func (m *Menu) AddItem(text string) *MenuItem {
  44. mi := new(MenuItem)
  45. mi.label = NewLabel(text)
  46. mi.Panel.Add(mi.label)
  47. m.items = append(m.items, mi)
  48. return mi
  49. }
  50. // AddSeparator creates and adds a new separator to the menu
  51. func (m *Menu) AddSeparator() *MenuItem {
  52. mi := new(MenuItem)
  53. return mi
  54. }
  55. // RemoveItem removes the specified menu item from this menu
  56. func (m *Menu) RemoveItem(mi *MenuItem) {
  57. }
  58. // recalc recalculates the positions of this menu internal items
  59. func (m *Menu) recalc() {
  60. }
  61. // SetIcon sets the left icon of this menu item
  62. // If an image was previously set it is replaced by this icon
  63. func (mi *MenuItem) SetIcon(icode int) *MenuItem {
  64. return mi
  65. }
  66. // SetImage sets the left image of this menu item
  67. // If an icon was previously set it is replaced by this image
  68. func (mi *MenuItem) SetImage(img *Image) *MenuItem {
  69. return mi
  70. }
  71. // SetText sets the text of this menu item
  72. func (mi *MenuItem) SetText(text string) *MenuItem {
  73. return mi
  74. }
  75. // SetShortcut sets the keyboard shortcut of this menu item
  76. func (mi *MenuItem) SetShortcut(text string) *MenuItem {
  77. return mi
  78. }
  79. // SetSubmenu sets an associated sub menu item for this menu item
  80. func (mi *MenuItem) SetSubmenu(smi *MenuItem) *MenuItem {
  81. return mi
  82. }
  83. // SetEnabled sets the enabled state of this menu item
  84. func (mi *MenuItem) SetEnabled(enabled bool) *MenuItem {
  85. return mi
  86. }
  87. // recalc recalculates the positions of this menu item internal panels
  88. func (mi *MenuItem) recalc() {
  89. }