BsGUIListBoxField.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsEditorPrerequisites.h"
  5. #include "GUI/BsGUIElementContainer.h"
  6. namespace bs
  7. {
  8. /** @addtogroup GUI-Editor
  9. * @{
  10. */
  11. /**
  12. * A composite GUI object representing an editor field. Editor fields are a combination of a label and an input field.
  13. * Label is optional. This specific implementation displays a list box field.
  14. */
  15. class BS_ED_EXPORT GUIListBoxField : public GUIElementContainer
  16. {
  17. struct PrivatelyConstruct {};
  18. public:
  19. /** Returns type name of the GUI element used for finding GUI element styles. */
  20. static const String& getGUITypeName();
  21. /** Returns style type name of the internal GUILabel element. */
  22. static const String& getLabelStyleType();
  23. /** Style type name for the internal list box. */
  24. static const String& getListBoxStyleType();
  25. /**
  26. * Creates a new GUI list box field with a label.
  27. *
  28. * @param[in] elements Elements to display in the list box.
  29. * @param[in] multiselect Determines should the listbox allow multiple elements to be selected or just one.
  30. * @param[in] labelContent Content to display in the editor field label.
  31. * @param[in] labelWidth Width of the label in pixels.
  32. * @param[in] options Options that allow you to control how is the element positioned and sized.
  33. * This will override any similar options set by style.
  34. * @param[in] style Optional style to use for the element. Style will be retrieved from GUISkin of the
  35. * GUIWidget the element is used on. If not specified default style is used.
  36. */
  37. static GUIListBoxField* create(const Vector<HString>& elements, bool multiselect, const GUIContent& labelContent,
  38. UINT32 labelWidth, const GUIOptions& options, const String& style = StringUtil::BLANK);
  39. /**
  40. * Creates a new GUI list box field with a label.
  41. *
  42. * @param[in] elements Elements to display in the list box.
  43. * @param[in] multiselect Determines should the listbox allow multiple elements to be selected or just one.
  44. * @param[in] labelContent Content to display in the editor field label.
  45. * @param[in] options Options that allow you to control how is the element positioned and sized.
  46. * This will override any similar options set by style.
  47. * @param[in] style Optional style to use for the element. Style will be retrieved from GUISkin of the
  48. * GUIWidget the element is used on. If not specified default style is used.
  49. */
  50. static GUIListBoxField* create(const Vector<HString>& elements, bool multiselect, const GUIContent& labelContent,
  51. const GUIOptions& options, const String& style = StringUtil::BLANK);
  52. /**
  53. * Creates a new GUI list box field with a label.
  54. *
  55. * @param[in] elements Elements to display in the list box.
  56. * @param[in] multiselect Determines should the listbox allow multiple elements to be selected or just one.
  57. * @param[in] labelText String to display in the editor field label.
  58. * @param[in] labelWidth Width of the label in pixels.
  59. * @param[in] options Options that allow you to control how is the element positioned and sized.
  60. * This will override any similar options set by style.
  61. * @param[in] style Optional style to use for the element. Style will be retrieved from GUISkin of the
  62. * GUIWidget the element is used on. If not specified default style is used.
  63. */
  64. static GUIListBoxField* create(const Vector<HString>& elements, bool multiselect, const HString& labelText,
  65. UINT32 labelWidth, const GUIOptions& options, const String& style = StringUtil::BLANK);
  66. /**
  67. * Creates a new GUI list box field with a label.
  68. *
  69. * @param[in] elements Elements to display in the list box.
  70. * @param[in] multiselect Determines should the listbox allow multiple elements to be selected or just one.
  71. * @param[in] labelText String to display in the editor field label.
  72. * @param[in] options Options that allow you to control how is the element positioned and sized.
  73. * This will override any similar options set by style.
  74. * @param[in] style Optional style to use for the element. Style will be retrieved from GUISkin of the
  75. * GUIWidget the element is used on. If not specified default style is used.
  76. */
  77. static GUIListBoxField* create(const Vector<HString>& elements, bool multiselect, const HString& labelText,
  78. const GUIOptions& options, const String& style = StringUtil::BLANK);
  79. /**
  80. * Creates a new GUI list box field without a label.
  81. *
  82. * @param[in] elements Elements to display in the list box.
  83. * @param[in] multiselect Determines should the listbox allow multiple elements to be selected or just one.
  84. * @param[in] options Options that allow you to control how is the element positioned and sized.
  85. * This will override any similar options set by style.
  86. * @param[in] style Optional style to use for the element. Style will be retrieved from GUISkin of the
  87. * GUIWidget the element is used on. If not specified default style is used.
  88. */
  89. static GUIListBoxField* create(const Vector<HString>& elements, bool multiselect, const GUIOptions& options,
  90. const String& style = StringUtil::BLANK);
  91. /**
  92. * Creates a new GUI list box field with a label.
  93. *
  94. * @param[in] elements Elements to display in the list box.
  95. * @param[in] multiselect Determines should the listbox allow multiple elements to be selected or just one.
  96. * @param[in] labelContent Content to display in the editor field label.
  97. * @param[in] labelWidth Width of the label in pixels.
  98. * @param[in] style Optional style to use for the element. Style will be retrieved from GUISkin of the
  99. * GUIWidget the element is used on. If not specified default style is used.
  100. */
  101. static GUIListBoxField* create(const Vector<HString>& elements, bool multiselect, const GUIContent& labelContent,
  102. UINT32 labelWidth, const String& style = StringUtil::BLANK);
  103. /**
  104. * Creates a new GUI list box field with a label.
  105. *
  106. * @param[in] elements Elements to display in the list box.
  107. * @param[in] multiselect Determines should the listbox allow multiple elements to be selected or just one.
  108. * @param[in] labelContent Content to display in the editor field label.
  109. * @param[in] style Optional style to use for the element. Style will be retrieved from GUISkin of the
  110. * GUIWidget the element is used on. If not specified default style is used.
  111. */
  112. static GUIListBoxField* create(const Vector<HString>& elements, bool multiselect, const GUIContent& labelContent,
  113. const String& style = StringUtil::BLANK);
  114. /**
  115. * Creates a new GUI list box field with a label.
  116. *
  117. * @param[in] elements Elements to display in the list box.
  118. * @param[in] multiselect Determines should the listbox allow multiple elements to be selected or just one.
  119. * @param[in] labelText String to display in the editor field label.
  120. * @param[in] labelWidth Width of the label in pixels.
  121. * @param[in] style Optional style to use for the element. Style will be retrieved from GUISkin of the
  122. * GUIWidget the element is used on. If not specified default style is used.
  123. */
  124. static GUIListBoxField* create(const Vector<HString>& elements, bool multiselect, const HString& labelText,
  125. UINT32 labelWidth, const String& style = StringUtil::BLANK);
  126. /**
  127. * Creates a new GUI list box field with a label.
  128. *
  129. * @param[in] elements Elements to display in the list box.
  130. * @param[in] multiselect Determines should the listbox allow multiple elements to be selected or just one.
  131. * @param[in] labelText String to display in the editor field label.
  132. * @param[in] style Optional style to use for the element. Style will be retrieved from GUISkin of the
  133. * GUIWidget the element is used on. If not specified default style is used.
  134. */
  135. static GUIListBoxField* create(const Vector<HString>& elements, bool multiselect, const HString& labelText,
  136. const String& style = StringUtil::BLANK);
  137. /**
  138. * Creates a new GUI list box field without a label.
  139. *
  140. * @param[in] elements Elements to display in the list box.
  141. * @param[in] multiselect Determines should the listbox allow multiple elements to be selected or just one.
  142. * @param[in] style Optional style to use for the element. Style will be retrieved from GUISkin of the
  143. * GUIWidget the element is used on. If not specified default style is used.
  144. */
  145. static GUIListBoxField* create(const Vector<HString>& elements, bool multiselect,
  146. const String& style = StringUtil::BLANK);
  147. GUIListBoxField(const PrivatelyConstruct& dummy, const Vector<HString>& elements, bool multiselect,
  148. const GUIContent& labelContent, UINT32 labelWidth, const String& style, const GUIDimensions& dimensions, bool withLabel);
  149. /** Checks whether the listbox supports multiple selected elements at once. */
  150. bool isMultiselect() const;
  151. /** Changes the list box elements. */
  152. void setElements(const Vector<HString>& elements);
  153. /** Selects an element with the specified index. */
  154. void selectElement(UINT32 value);
  155. /** Deselect element the element with the specified index. Only relevant for multi-select list boxes. */
  156. void deselectElement(UINT32 idx);
  157. /** Returns states of all element in the list box (enabled or disabled). */
  158. const Vector<bool>& getElementStates() const;
  159. /**
  160. * Sets states for all list box elements. Only valid for multi-select list boxes. Number of states must match number
  161. * of list box elements.
  162. */
  163. void setElementStates(const Vector<bool>& states);
  164. /** @copydoc GUIElement::setTint */
  165. void setTint(const Color& color) override;
  166. /** Triggers when a new element is selected. Provides index to the element. */
  167. Event<void(UINT32, bool)> onSelectionChanged;
  168. protected:
  169. static const UINT32 DEFAULT_LABEL_WIDTH;
  170. virtual ~GUIListBoxField();
  171. /** @copydoc GUIElement::_updateLayoutInternal */
  172. void _updateLayoutInternal(const GUILayoutData& data) override;
  173. /** @copydoc GUIElement::_getOptimalSize */
  174. Vector2I _getOptimalSize() const override;
  175. /** @copydoc GUIElement::styleUpdated */
  176. void styleUpdated() override;
  177. /** Triggered when the selected list box element changes. */
  178. void selectionChanged(UINT32 newIndex, bool enabled);
  179. GUIListBox* mListBox;
  180. GUILayout* mLayout;
  181. GUILabel* mLabel;
  182. };
  183. /** @} */
  184. }