menu.adoc 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. = menu
  2. :author:
  3. :revnumber:
  4. :revdate: 2016/03/17 20:48
  5. :relfileprefix: ../../../
  6. :imagesdir: ../../..
  7. ifdef::env-github,env-browser[:outfilesuffix: .adoc]
  8. == Menu Class
  9. The Menu class extends ScrollArea as Menu’s can be resizable and scrollable if the behaviors are enabled.
  10. Menus contain a list of MenuItems, which provide mapping for sub-menus. This implementation of menu’s negates the need for any form of Menu Manager as the Screen, by default, handles delegating Mouse Events and therefore is (in a sense) a Menu Manager. Menus utilize a single text element with separate highlight element, to keep the rendered meshes to count of 3 for any length menu.
  11. Features:
  12. * Unlimited menu item list
  13. * Unlimited sub-menu mapping
  14. * MenuItem toggle states (semi-work-in-progress here)
  15. Menu utilizes the standard 3 constructors as shown in the <<jme3/contributions/tonegodgui/quickstart#,Quick Start Guide>> with the addition of a single boolean:
  16. * isScrollable – appended to the end of the parameter list in each constructor
  17. === Abstract Event Methods:
  18. [source,java]
  19. ----
  20. public void onMenuItemClicked(int index, Object value);
  21. ----
  22. === Methods specific to the Menu Class:
  23. [source,java]
  24. ----
  25. // Menu manipulation
  26. menu.addMenuItem(String caption, Object value, Menu subMenu); // null if no sub-menu
  27. menu.addMenuItem(String caption, Object value, Menu subMenu, boolean isToggleItem);
  28. menu.addMenuItem(String caption, Object value, Menu subMenu, boolean isToggleItem, boolean isToggled);
  29. menu.insertMenuItem(int index, String caption, Object value, Menu subMenu); // null if no sub-menu
  30. menu.insertMenuItem(int index, String caption, Object value, Menu subMenu, boolean isToggleItem)
  31. menu.insertMenuItem(int index, String caption, Object value, Menu subMenu, boolean isToggleItem, boolean isToggled)
  32. menu.removeMenuItem(int index);
  33. menu.removeMenuItem(String caption);
  34. menu.removeMenuItem(Object value);
  35. menu.removeFirstMenuItem();
  36. menu.removeLastMenuItem();
  37. // Configuration related methods
  38. menu.setMenuOverhang(float menuOverhang);
  39. menu.getMenuOverhang();
  40. menu.getMenuItemHeight();
  41. menu.getMenuPadding();
  42. menu.setPreferredSize(Vector2f preferredSize)
  43. //Menu item related methods
  44. menu.getMenuItems(); // point to menu item list
  45. menu.getMenuItem(int index);
  46. // Hide/show methods
  47. menu.showMenu(Menu caller, float x, float y); // Caller is null if not show by another menu
  48. menu.hideMenu();
  49. // Setting & retrieving an external caller element
  50. menu.setCallerElement(Element el);
  51. menu.getCallerElement();
  52. ----
  53. === Hooks
  54. [source,java]
  55. ----
  56. public void controlHideHook() { }
  57. ----
  58. == Menu Examples:
  59. Cut &amp; Paste the code below into the simpleInitApp() method of a new JME project to try it out.
  60. [source,java]
  61. ----
  62. flyCam.setDragToRotate(true);
  63. inputManager.setCursorVisible(true);
  64. screen = new Screen(this);
  65. guiNode.addControl(screen);
  66. Menu subMenu = new Menu(
  67. screen,
  68. new Vector2f(0,0),
  69. false
  70. ) {
  71. @Override
  72. public void onMenuItemClicked(int index, Object value, boolean isToggled) { }
  73. };
  74. // Add a menu item
  75. subMenu.addMenuItem("Some string caption 1", null, null);
  76. // Add a toggle-able menu item (checkbox)
  77. subMenu.addMenuItem("Some string caption 2", null, null, true);
  78. // Add a toggle-able menu item and set the default state of the checkbox to checked
  79. subMenu.addMenuItem("Some string caption 3", null, null, true, true);
  80. screen.addElement(subMenu);
  81. final Menu menu = new Menu(
  82. screen,
  83. new Vector2f(0,0),
  84. false
  85. ) {
  86. @Override
  87. public void onMenuItemClicked(int index, Object value, boolean isToggled) { }
  88. };
  89. // Add subMenu as a sub-menu to this menu item
  90. menu.addMenuItem("Some caption", null, subMenu);
  91. screen.addElement(menu);
  92. ButtonAdapter b = new ButtonAdapter(screen, new Vector2f(50,50)) {
  93. @Override
  94. public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean isToggled) {
  95. menu.showMenu(null, getAbsoluteX(), getAbsoluteY()-menu.getHeight());
  96. }
  97. };
  98. b.setText("Show Menu");
  99. screen.addElement(b);
  100. ----