button.adoc 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. = button
  2. :revnumber: 2.0
  3. :revdate: 2020/07/25
  4. == Button Class
  5. * Buttons have a default state, a hover state and a pressed state.
  6. * They implement the tonegodGUI MouseButtonListener & MouseFocusListener interfaces
  7. * They provide an optional stillPressed event
  8. * Can either consist of text label or icon
  9. * They can be set to Toggle mode.
  10. * They have default effects set for Hover, Pressed & LoseFocus
  11. * Buttons are an abstract class providing methods for handling user input
  12. Again, the same three options for constructor are available as show in the xref:gui/tonegodgui/quickstart.adoc[Quick Start Guide].
  13. *Constructor 1:*
  14. [source,java]
  15. ----
  16. /** Parameters:
  17. * Screen screen,
  18. * String UID,
  19. * Vector2f position
  20. */
  21. Button button = new Button(screen, "button", new Vector2f(15, 15));
  22. ----
  23. *Constructor 2:*
  24. [source,java]
  25. ----
  26. /** Additional Parameter:
  27. * Vector2f dimensions */
  28. Button button = new Button(screen, "button", new Vector2f(15, 15),
  29. new Vector2f(100, 25)
  30. );
  31. ----
  32. *Constructor 3:*
  33. [source,java]
  34. ----
  35. /** Additional Parameters:
  36. * Vector4f resizeBorders,
  37. * String defaultImg
  38. */
  39. Button button = new Button(screen, "button", new Vector2f(15, 15), new Vector2f(100, 25),
  40. new Vector4f(5,5,5,5),
  41. "tonegod/gui/style/def/Button/button_u_x.png"
  42. );
  43. ----
  44. === Hover State
  45. You can override the default hover state using the following method:
  46. [source,java]
  47. ----
  48. // Override the information used by the hover effect
  49. button.setButtonHoverInfo(String imagePath, ColorRGBA textHoverColor);
  50. ----
  51. === Pressed State
  52. You can override the default pressed state using the following method:
  53. [source,java]
  54. ----
  55. // Override the information used by the pressed effect
  56. button.setButtonPressedInfo(String imagePath, ColorRGBA textPressedColor);
  57. ----
  58. === Abstract Event Methods:
  59. [source,java]
  60. ----
  61. public void onButtonMouseLeftDown(MouseButtonEvent evt, boolean toggled);
  62. public void onButtonMouseRightDown(MouseButtonEvent evt, boolean toggled);
  63. public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled);
  64. public void onButtonMouseRightUp(MouseButtonEvent evt, boolean toggled);
  65. public void onButtonFocus(MouseMotionEvent evt);
  66. public void onButtonLostFocus(MouseMotionEvent evt);
  67. public void onButtonStillPressedInterval();
  68. ----
  69. === Adding an Icon
  70. In place of text, you can use an image icon by calling the following method:
  71. [source,java]
  72. ----
  73. button.setButtonIcon(float width, float height, String texturePath);
  74. ----
  75. === Methods specific to the Button class
  76. [source,java]
  77. ----
  78. //Toggle info
  79. button.setIsToggleButton(boolean isToggleButton); // Also provides a getter
  80. button.getIsToggleButton();
  81. button.getIsToggled();
  82. // Additional state info
  83. button.clearAltImages();
  84. // Enabling/disabling interval calls (StillPressed event)
  85. button.setInterval(float intervalsPerSecond); // 0 deactivates
  86. ----
  87. [NOTE]
  88. ====
  89. When not otherwise specified, use the primitive Element method for setting the text of a control. For instance, to set the text of the Button instance, you simply call:
  90. [source,java]
  91. ----
  92. button.setText(String text);
  93. ----
  94. ====
  95. == ButtonAdapter Class
  96. Tips for using the Button class:
  97. . Create a button
  98. . Implement all abstract methods
  99. . Write your code for the event handlers you wish to use
  100. . Change the Button to a ButtonAdapter
  101. . Remove all unused event handler methods