Label.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /************************************************************************
  2. * Label.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 Lagel} class represents an UIObject that holds and HTML label.
  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 Label extends UIObject
  32. {
  33. /**
  34. * Initializes and empty Label with the specified parameters.
  35. *
  36. * @param {String} name name for the Label GameObject.
  37. * @param {String} text inner HTML text of the label.
  38. *
  39. * @constructor
  40. */
  41. constructor(name, text = "Label")
  42. {
  43. super(name);
  44. this.text = text; // This Label's inner HTML text.
  45. this.P5Element = createDiv(text); // This Label's HTML label.
  46. this.setPosition(0, 0); // Set the position of the Label on the secondary buffer.
  47. this.setSize(200, 50); // Set the size of the Label on the secondary buffer.
  48. this.setStyle(STYLE.DEFAULT_STYLE); // Set the default style of the UIObject.
  49. this.connectCallbacks(); // Connect events of the p5.Element.
  50. }
  51. /**
  52. * Sets the text inside this Label's HTML label.
  53. *
  54. * @param {String} t new text for the label.
  55. */
  56. setText(t)
  57. {
  58. this.P5Element.html(t);
  59. this.text = t;
  60. }
  61. /**
  62. * Returns this Label's HTML label's text.
  63. *
  64. * @returns {String} HTML label's text.
  65. */
  66. getText()
  67. {
  68. return this.text;
  69. }
  70. }