BsGUIListBoxField.h 11 KB

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