BsGUIListBoxField.h 10 KB

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