BsGUIDropDownContent.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #pragma once
  2. #include "BsPrerequisites.h"
  3. #include "BsGUIElementContainer.h"
  4. #include "BsGUIDropDownMenu.h"
  5. namespace BansheeEngine
  6. {
  7. /**
  8. * @brief GUI element that is used for representing entries in a drop down menu.
  9. */
  10. class BS_EXPORT GUIDropDownContent : public GUIElementContainer
  11. {
  12. /**
  13. * @brief Contains various GUI elements used for displaying a single menu entry.
  14. */
  15. struct VisibleElement
  16. {
  17. UINT32 idx = 0;
  18. GUIButton* button = nullptr;
  19. GUITexture* separator = nullptr;
  20. GUILabel* shortcutLabel = nullptr;
  21. };
  22. public:
  23. /**
  24. * Returns type name of the GUI element used for finding GUI element styles.
  25. */
  26. static const String& getGUITypeName();
  27. /**
  28. * @brief Creates a new drop down contents element.
  29. *
  30. * @param parent Parent sub-menu that owns the drop down contents.
  31. * @param dropDownData Data that will be used for initializing the child entries.
  32. * @param styleName Optional style to use for the element. Style will be retrieved
  33. * from GUISkin of the GUIWidget the element is used on. If not specified
  34. * default button style is used.
  35. */
  36. static GUIDropDownContent* create(GUIDropDownMenu::DropDownSubMenu* parent, const GUIDropDownData& dropDownData,
  37. const String& style = StringUtil::BLANK);
  38. /**
  39. * @brief Creates a new drop down contents element.
  40. *
  41. * @param parent Parent sub-menu that owns the drop down contents.
  42. * @param dropDownData Data that will be used for initializing the child entries.
  43. * @param options Options that allow you to control how is the element positioned and sized.
  44. * This will override any similar options set by style.
  45. * @param styleName Optional style to use for the element. Style will be retrieved
  46. * from GUISkin of the GUIWidget the element is used on. If not specified
  47. * default button style is used.
  48. */
  49. static GUIDropDownContent* create(GUIDropDownMenu::DropDownSubMenu* parent, const GUIDropDownData& dropDownData,
  50. const GUIOptions& options, const String& style = StringUtil::BLANK);
  51. /**
  52. * @brief Changes the range of the displayed elements.
  53. *
  54. * @note This must be called at least once after creation.
  55. */
  56. void setRange(UINT32 start, UINT32 end);
  57. /**
  58. * @brief Returns height of a menu element at the specified index, in pixels.
  59. */
  60. UINT32 getElementHeight(UINT32 idx) const;
  61. /**
  62. * @brief Enables or disables keyboard focus. When keyboard focus is enabled the contents
  63. * will respond to keyboard events.
  64. */
  65. void setKeyboardFocus(bool focus);
  66. static const String ENTRY_STYLE_TYPE;
  67. static const String ENTRY_EXP_STYLE_TYPE;
  68. static const String SEPARATOR_STYLE_TYPE;
  69. protected:
  70. GUIDropDownContent(GUIDropDownMenu::DropDownSubMenu* parent, const GUIDropDownData& dropDownData,
  71. const String& style, const GUIDimensions& dimensions);
  72. ~GUIDropDownContent() override;
  73. /**
  74. * @brief Get localized name of a menu item element with the specified index.
  75. */
  76. HString getElementLocalizedName(UINT32 idx) const;
  77. /**
  78. * @copydoc GUIElementContainer::_getOptimalSize
  79. */
  80. Vector2I _getOptimalSize() const override;
  81. /**
  82. * @copydoc GUIElementContainer::updateClippedBounds
  83. */
  84. void updateClippedBounds() override;
  85. /**
  86. * @copydoc GUIElementContainer::_updateLayoutInternal
  87. */
  88. void _updateLayoutInternal(const GUILayoutData& data) override;
  89. /**
  90. * @copydoc GUIElementContainer::styleUpdated
  91. */
  92. void styleUpdated() override;
  93. /**
  94. * @copydoc GUIElementContainer::_commandEvent
  95. */
  96. bool _commandEvent(const GUICommandEvent& ev) override;
  97. /**
  98. * @brief Marks the element with the specified index as selected.
  99. */
  100. void setSelected(UINT32 idx);
  101. /**
  102. * @brief Selects the next available non-separator entry.
  103. */
  104. void selectNext(UINT32 startIdx);
  105. /**
  106. * @brief Selects the previous available non-separator entry.
  107. */
  108. void selectPrevious(UINT32 startIdx);
  109. GUIDropDownData mDropDownData;
  110. Vector<VisibleElement> mVisibleElements;
  111. UINT32 mSelectedIdx;
  112. UINT32 mRangeStart, mRangeEnd;
  113. GUIDropDownMenu::DropDownSubMenu* mParent;
  114. bool mKeyboardFocus;
  115. };
  116. }