Button.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /************************************************************************
  2. * Button.js
  3. ************************************************************************
  4. * Copyright (c) 2021 Pedro Tonini Rosenberg Schneider.
  5. *
  6. * This file is part of Pandora.
  7. *
  8. * Pandora is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * Pandora is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with Pandora. If not, see <https://www.gnu.org/licenses/>.
  20. *************************************************************************/
  21. /**
  22. * The {@code Button} class represents an UIObject that holds and HTML button.
  23. *
  24. * ! All GameObjects need to be inside the tree to do anything (can be added as a child
  25. * ! of another GameObject on the tree or as a root).
  26. *
  27. * @author Pedro Schneider
  28. *
  29. * @class
  30. */
  31. class Button extends UIObject
  32. {
  33. /**
  34. * @constructor
  35. * Initializes an empty Button GameObject.
  36. *
  37. * @param {String} name
  38. * @param {String} label
  39. */
  40. constructor(name, label = "Button")
  41. {
  42. super(name);
  43. this.P5Element = createButton(); // This Button's HTML button.
  44. this.label = label; // This Button's label
  45. this.P5Element.html(label); // Set the label to the inner HTML of the button.
  46. this.setPosition(0, 0); // Set the position of the Button on the secondary buffer.
  47. this.setStyle(STYLE.DEFAULT_STYLE); // Set the default style of the UIObject.
  48. this.connectCallbacks(); // Connect the events of the p5.Element.
  49. }
  50. /**
  51. * Sets the label on this UIObject's button.
  52. *
  53. * @param {String} label new label for the button.
  54. */
  55. setLabel(label)
  56. {
  57. this.label = label;
  58. this.P5Element.html(label);
  59. }
  60. }