BsGUIDropDownContent.h 4.5 KB

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