💿🐜 Antkeeper source code https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

127 lines
2.3 KiB

  1. /*
  2. * Copyright (C) 2017-2019 Christopher J. Howard
  3. *
  4. * This file is part of Antkeeper Source Code.
  5. *
  6. * Antkeeper Source Code is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Antkeeper Source Code is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Antkeeper Source Code. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef MENU_HPP
  20. #define MENU_HPP
  21. #include <emergent/emergent.hpp>
  22. using namespace Emergent;
  23. #include "ui/ui.hpp"
  24. #include <functional>
  25. class Menu;
  26. class MenuItem
  27. {
  28. public:
  29. MenuItem();
  30. ~MenuItem();
  31. void setFont(Font* font);
  32. void setName(const std::string& name);
  33. void setValue(const std::string& value);
  34. void setActivatedCallback(std::function<void()> callback);
  35. void activate();
  36. UIContainer* getContainer() const;
  37. UILabel* getNameLabel() const;
  38. UILabel* getValueLabel() const;
  39. private:
  40. friend class Menu;
  41. UIContainer* container;
  42. UILabel* nameLabel;
  43. UILabel* valueLabel;
  44. std::function<void()> activatedCallback;
  45. };
  46. inline UIContainer* MenuItem::getContainer() const
  47. {
  48. return container;
  49. }
  50. inline UILabel* MenuItem::getNameLabel() const
  51. {
  52. return nameLabel;
  53. }
  54. inline UILabel* MenuItem::getValueLabel() const
  55. {
  56. return valueLabel;
  57. }
  58. class Menu
  59. {
  60. public:
  61. /// Creates a menu.
  62. Menu();
  63. /// Destroys a menu.
  64. ~Menu();
  65. /**
  66. * Adds a new item to the menu.
  67. */
  68. MenuItem* addItem();
  69. /**
  70. * Removes an item from the menu.
  71. */
  72. void removeItem(MenuItem* item);
  73. /**
  74. * Removes all items from the menu.
  75. */
  76. void removeItems();
  77. /**
  78. * Sets the font for all menu items in the menu.
  79. */
  80. void setFonts(Font* font);
  81. const std::vector<MenuItem*>* getItems() const;
  82. UIContainer* getContainer() const;
  83. void resize(int w, int h);
  84. private:
  85. UIContainer* container;
  86. std::vector<MenuItem*> items;
  87. };
  88. inline const std::vector<MenuItem*>* Menu::getItems() const
  89. {
  90. return &items;
  91. }
  92. inline UIContainer* Menu::getContainer() const
  93. {
  94. return container;
  95. }
  96. #endif // MENU_HPP