menu.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. type MenuBar struct {
  6. }
  7. type Menu struct {
  8. Panel // embedded panel
  9. items []*MenuItem // menu items
  10. }
  11. type MenuItem struct {
  12. Panel // embedded panel
  13. label *Label // optional internal label (nil for separators)
  14. image *Image // optional left internal image
  15. licon *Label // optional left internal icon label
  16. ricon *Label // optional right internal icon label for submenu
  17. icode int // icon code (if icon is set)
  18. subm *MenuItem // optional pointer to sub menu
  19. shorcut int32 // shortcut code
  20. enabled bool // enabled state
  21. }
  22. // NewMenu creates and returns a pointer to a new empty menu
  23. func NewMenu() *Menu {
  24. m := new(Menu)
  25. m.items = make([]*MenuItem, 0)
  26. return m
  27. }
  28. // AddItem creates and adds a new menu item to this menu and returns the pointer
  29. // to the created item.
  30. func (m *Menu) AddItem(text string) *MenuItem {
  31. mi := new(MenuItem)
  32. mi.label = NewLabel(text)
  33. mi.Panel.Add(mi.label)
  34. m.items = append(m.items, mi)
  35. return mi
  36. }
  37. // AddSeparator creates and adds a new separator to the menu
  38. func (m *Menu) AddSeparator() *MenuItem {
  39. mi := new(MenuItem)
  40. return mi
  41. }
  42. // RemoveItem removes the specified menu item from this menu
  43. func (m *Menu) RemoveItem(mi *MenuItem) {
  44. }
  45. // recalc recalculates the positions of this menu internal items
  46. func (m *Menu) recalc() {
  47. }
  48. // SetIcon sets the left icon of this menu item
  49. // If an image was previously set it is replaced by this icon
  50. func (mi *MenuItem) SetIcon(icode int) *MenuItem {
  51. return mi
  52. }
  53. // SetImage sets the left image of this menu item
  54. // If an icon was previously set it is replaced by this image
  55. func (mi *MenuItem) SetImage(img *Image) *MenuItem {
  56. return mi
  57. }
  58. // SetText sets the text of this menu item
  59. func (mi *MenuItem) SetText(text string) *MenuItem {
  60. return mi
  61. }
  62. // SetShortcut sets the keyboard shortcut of this menu item
  63. func (mi *MenuItem) SetShortcut(text string) *MenuItem {
  64. return mi
  65. }
  66. // SetSubmenu sets an associated sub menu item for this menu item
  67. func (mi *MenuItem) SetSubmenu(smi *MenuItem) *MenuItem {
  68. return mi
  69. }
  70. // SetEnabled sets the enabled state of this menu item
  71. func (mi *MenuItem) SetEnabled(enabled bool) *MenuItem {
  72. return mi
  73. }
  74. // recalc recalculates the positions of this menu item internal panels
  75. func (mi *MenuItem) recalc() {
  76. }