Spinning Topp Logo BlackTopp Studios
inc
listbox.h
1 // © Copyright 2010 - 2016 BlackTopp Studios Inc.
2 /* This file is part of The Mezzanine Engine.
3 
4  The Mezzanine Engine is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  The Mezzanine Engine is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>.
16 */
17 /* The original authors have included a copy of the license specified above in the
18  'Docs' folder. See 'gpl.txt'
19 */
20 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
21  Build professional software and charge for their product.
22 
23  However there are some practical restrictions, so if your project involves
24  any of the following you should contact us and we will try to work something
25  out:
26  - DRM or Copy Protection of any kind(except Copyrights)
27  - Software Patents You Do Not Wish to Freely License
28  - Any Kind of Linking to Non-GPL licensed Works
29  - Are Currently In Violation of Another Copyright Holder's GPL License
30  - If You want to change our code and not add a few hundred MB of stuff to
31  your distribution
32 
33  These and other limitations could cause serious legal problems if you ignore
34  them, so it is best to simply contact us or the Free Software Foundation, if
35  you have any questions.
36 
37  Joseph Toppi - toppij@gmail.com
38  John Blackwood - makoenergy02@gmail.com
39 */
40 #ifndef _uilistbox_h
41 #define _uilistbox_h
42 
43 #include "colourvalue.h"
44 #include "UI/uienumerations.h"
45 #include "UI/widget.h"
46 #include "UI/textlayer.h"
47 
48 namespace Mezzanine
49 {
50  namespace UI
51  {
52  class FontData;
53  class VerticalScrollbar;
54  class VerticalContainer;
55 
56  ///////////////////////////////////////////////////////////////////////////////
57  /// @brief This is a widget for displaying a list of captions in a box.
58  /// @details This class uses the base LayoutStrategy.
59  /// @remarks ListItems owned by a ListBox are not direct children of the ListBox. Instead they are direct children of
60  /// the VerticalContainer that is the child of the ListBox. There are convenience methods that allow light management
61  /// of ListItems, but they are really just wrappers around similiar methods on the VerticalContainer.
62  ///////////////////////////////////////
63  class MEZZ_LIB ListBox : public Widget
64  {
65  public:
66  /// @brief Convenience typedef for objects that will be used to represent list items in this ListBox.
67  typedef Widget ListItem;
68 
69  /// @brief This enum is used to describe how new ListItems are inserted into the list.
71  {
72  LIO_TopInsert = 1, ///< New entries will be inserted at the top of the list.
73  LIO_BottomInsert = 2 ///< New entries will be inserted at the bottom of the list.
74  };
75 
76  /// @brief String containing the type name for this class: "ListBox".
77  static const String TypeName;
78  protected:
79  /// @internal
80  /// @brief Stores the default font that will be used by all ListItems generated by this ListBox.
82  /// @internal
83  /// @brief A pointer to the vertical scrollbar responsible for the visible list items.
85  /// @internal
86  /// @brief A pointer to the vertical container storing all the list items.
88  /// @internal
89  /// @brief The amount of auto-scaling to be applied to all created list items.
91  /// @internal
92  /// @brief The auto-scaling mode that is to be applied to all created list items.
94  /// @internal
95  /// @brief Stores how new entries will be inserted with other elements in this ListBox.
97 
98  /// @copydoc Widget::HandleInputImpl(const Input::MetaCode&)
99  virtual Boole HandleInputImpl(const Input::MetaCode& Code);
100  /// @internal
101  /// @brief Convenience method for the construction of a ListBox.
102  /// @param Style An enum value representing how the scrollbar child of thie ListBox will be constructed. See @ref UI::ScrollbarStyle enum for more info.
103  virtual void ConstructListBox(const UI::ScrollbarStyle& Style);
104  /// @internal
105  /// @brief Helper method that creates a basic ListItem with no TextLayers.
106  /// @param ItemName The name to be given to the new ListItem.
107  /// @return Returns a pointer to the newly created ListItem.
108  virtual ListItem* CreateListItem(const String& ItemName);
109  public:
110  /// @brief Blank constructor.
111  /// @param Parent The parent Screen that created this widget.
112  ListBox(Screen* Parent);
113  /// @brief Standard initialization constructor.
114  /// @param RendName The name to be given to this renderable.
115  /// @param Style An enum value representing how the scrollbar child of thie ListBox will be constructed. See @ref UI::ScrollbarStyle enum for more info.
116  /// @param Parent The parent Screen that created this widget.
117  ListBox(const String& RendName, const UI::ScrollbarStyle& Style, Screen* Parent);
118  /// @brief Rect constructor.
119  /// @param RendName The name to be given to this renderable.
120  /// @param RendRect The rect describing this widget's transform relative to it's parent.
121  /// @param Style An enum value representing how the scrollbar child of thie ListBox will be constructed. See @ref UI::ScrollbarStyle enum for more info.
122  /// @param Parent The parent screen that created this renderable.
123  ListBox(const String& RendName, const UnifiedRect& RendRect, const UI::ScrollbarStyle& Style, Screen* Parent);
124  /// @brief XML constructor.
125  /// @param XMLNode The node of the xml document to construct from.
126  /// @param Parent The screen the created ListBox will belong to.
127  ListBox(const XML::Node& XMLNode, Screen* Parent);
128  /// @brief Class destructor.
129  virtual ~ListBox();
130  //public:
131  ///////////////////////////////////////////////////////////////////////////////
132  // Utility Methods
133 
134  /// @brief Sets both the size and enforcement rules for forced list item sizing in this container.
135  /// @note The sizing provided here works just like any other normal list item sizing does, with the relative parts being based on the the parent container (this).
136  /// @param ForcedSize A SizingInfo describing how all children should size themselves on dimension updates.
137  /// @param Enforcement A bitmask containing when the list item sizing will be enforced by this container. See SizeEnforcement enum for more details.
138  virtual void SetListItemSizing(const SizingInfo& ForcedSize, const Whole Enforcement);
139  /// @brief Sets the size to be given to children processed by this container if forced sizing is enabled.
140  /// @note The sizing provided here works just like any other normal list item sizing does, with the relative parts being based on the the parent container (this).
141  /// @param ForcedSize A SizingInfo describing how all children should size themselves on dimension updates.
142  virtual void SetListItemSize(const SizingInfo& ForcedSize);
143  /// @brief Gets the size to be given to children processed by this container if forced sizing is enabled.
144  /// @return Returns a const SizeInfo reference to the sizing given to children processed by this container if forced sizing is enabled.
145  virtual const SizingInfo& GetListItemSize() const;
146  /// @brief Sets when the set list item sizing will be applied to any given list item.
147  /// @param Enforcement A bitmask containing when the list item sizing will be enforced by this container. See SizeEnforcement enum for more details.
148  virtual void SetListItemSizeEnforcement(const Whole Enforcement);
149  /// @brief Gets when the set list item sizing will be applied to any given list item.
150  /// @return Returns a bitmask describing when the list item sizing will be enforced by this container. See SizeEnforcement enum for more details.
151  virtual Whole GetListItemSizeEnforcement() const;
152 
153  /// @brief Sets the Unified width of the child scrollbar in this ListBox.
154  /// @note This defaults to UnifiedDim(0.08,0.0).
155  /// @param ScrollWidth The relative (to this) and absolute components of the width to be given the child scrollbar.
156  virtual void SetScrollbarWidth(const UnifiedDim& ScrollWidth);
157  /// @brief Gets the Unified width of the child scrollbar in this ListBox.
158  /// @return Returns a const reference to the Unified dimension containing the width of the child scrollbar.
159  virtual const UnifiedDim& GetScrollbarWidth() const;
160 
161  /// @copydoc QuadRenderable::UpdateDimensions(const Rect&, const Rect&)
162  virtual void UpdateDimensions(const Rect& OldSelfRect, const Rect& NewSelfRect);
163 
164  /// @copydoc Widget::GetTypeName() const
165  virtual const String& GetTypeName() const;
166 
167  ///////////////////////////////////////////////////////////////////////////////
168  // ListBox Properties
169 
170  /// @brief Sets the font that will be used by ListItems in this ListBox.
171  /// @note This method is not retroactive. ListItems that have been already created won't be altered, but new
172  /// ListItems will have the specified font as their default font (which can be overridden via Markup).
173  /// @param Font A pointer to the font that will be used by ListItems in this ListBox.
174  virtual void SetListItemFont(FontData* Font);
175  /// @brief Sets the font that will be used by ListItems in this ListBox.
176  /// @note This method is not retroactive. ListItems that have been already created won't be altered, but new
177  /// ListItems will have the specified font as their default font (which can be overridden via Markup).
178  /// @param FontName The name of the Font to use when creating ListItems in this ListBox.
179  virtual void SetListItemFont(const String& FontName);
180  /// @brief Gets the font that will be used by ListItems in this ListBox.
181  /// @return Returns a pointer to the Font being used by all ListItems generated by this ListBox.
182  virtual FontData* GetListItemFont() const;
183 
184  /// @brief Sets the mode and scaler of auto-scaling applied to ListItems created by this ListBox.
185  /// @remarks There are a lot of considerations to be made with auto-scaling. Auto-scaling will adjust the size of the provided font
186  /// automatically based on the scaling mode that is set, which really decides what the relative scalar provided for auto-scaling is
187  /// relative to. If auto-scaling is relative to the screen, then the text will only change in size when the screen does. Parent and
188  /// layer relative scaling are very similiar since layers get their dimensions from the parent widget they belong to. The difference
189  /// comes from scaling applied to the layer itself. Parent relative scaling ignores the layer scaling, while layer relative factors
190  /// it in. @n @n
191  /// In addition to the relative component to the scaling, manual scaling will also be applied after the auto-scaling is. Auto-scaling
192  /// will be completely ignored if the custom size on a character is set.
193  /// @param Mode A ScalingMode enum value describing what the provided scaler will be relative to.
194  /// @param Scalar The relative value that will be used to determine the needed scaling to be applied to text in this layer.
195  virtual void SetListItemTextScale(const TextLayer::ScalingMode Mode, const Real Scalar);
196  /// @brief Gets the automatic scaling mode being used by ListItems created by this ListBox.
197  /// @return Returns a ScalingMode enum value describing what the relative scaler is relative to, if auto-scaling is enabled at all.
198  virtual TextLayer::ScalingMode GetListItemTextScalingMode() const;
199  /// @brief Gets the relative scalar being used to automatically scale text in ListItems created by this ListBox.
200  /// @return Returns a Real representing the relative Y size to use when detmining how to uniformly scale text in ListItems.
201  virtual Real GetListItemTextScalar() const;
202 
203  /// @brief Sets how new entries will be inserted into the list.
204  /// @param Order A ListItemOrdering enum value expressing how this ListBox is to insert new entries.
205  virtual void SetListItemOrdering(ListBox::ListItemOrdering Order);
206  /// @brief Gets how new entries will be inserted into the list.
207  /// @return Returns a ListItemOrdering enum value representing how new ListItems are being inserted into this ListBox.
208  virtual ListBox::ListItemOrdering GetListItemOrdering() const;
209 
210  ///////////////////////////////////////////////////////////////////////////////
211  // ListBox Configuration
212 
213  /// @brief Convenience method that will create and add a ListItem with a single line text layer to this ListBox.
214  /// @note The auto-created text layers ZOrder is 5. TextLine(s) in the ListItem are set to a centered vertical
215  /// alignment. ListItems by default are sized to automatically fill the full X axis of it's container, and X+2 pixels in
216  /// height, where the height is the space needed for all it's text lines. New ListItems are also automatically added as
217  /// a child of this ListBox, so you don't need to add them to the ListBox yourself.
218  /// @param ItemName The name to be given to the new ListItem.
219  /// @param Text The text that is to be created and assigned to the new list item.
220  /// @return Returns a pointer to the newly created ListItem.
221  virtual ListItem* CreateSingleLineListItem(const String& ItemName, const String& Text);
222  /// @brief Convenience method that will create and add a ListItem with a multi-line text layer to this ListBox.
223  /// @note The auto-created text layers ZOrder is 5. TextLine(s) in the ListItem are set to a centered vertical
224  /// alignment. ListItems by default are sized to automatically fill the full X axis of it's container, and X+2 pixels in
225  /// height, where the height is the space needed for all it's text lines. New ListItems are also automatically added as
226  /// a child of this ListBox, so you don't need to add them to the ListBox yourself.
227  /// @param ItemName The name to be given to the new ListItem.
228  /// @param Text The text that is to be created and assigned to the new list item.
229  /// @return Returns a pointer to the newly created ListItem.
230  virtual ListItem* CreateMultiLineListItem(const String& ItemName, const String& Text);
231  /// @brief Gets a ListItem in this ListBox by name.
232  /// @param Name The name of the ListItem to retrieve.
233  /// @return Returns a pointer to the specified ListItem.
234  virtual ListItem* GetListItem(const String& Name) const;
235  /// @brief Gets the number of ListItems in this ListBox.
236  /// @return Returns a Whole representing the number of ListItems owned by this ListBox.
237  virtual Whole GetNumListItems() const;
238  /// @brief Destroys a ListItem owned by this ListBox.
239  /// @param ToBeDestroyed A pointer to the ListItem to be destroyed.
240  virtual void DestroyListItem(ListItem* ToBeDestroyed);
241  /// @brief Destroys all the ListItems currently owned by this ListBox.
242  virtual void DestroyAllListItems();
243 
244  /// @brief Gets the Scrollbar within this widget.
245  /// @return Returns a pointer to the VerticalScrollbar used to scroll through the ListItems of this widget.
246  virtual VerticalScrollbar* GetListScroll() const;
247  /// @brief Gets the ListItem container within this widget.
248  /// @return Returns a pointer to the VerticalContainer used to store the ListItems of this widget.
249  virtual VerticalContainer* GetListContainer() const;
250  /// @brief Gets the last ListItem that was selected/focused.
251  /// @return Returns a pointer to the last ListItem that was selected/focused.
252  virtual ListItem* GetLastSelectedListItem() const;
253 
254  ///////////////////////////////////////////////////////////////////////////////
255  // Serialization
256 
257  /// @copydoc Renderable::ProtoSerializeProperties(XML::Node&) const
258  virtual void ProtoSerializeProperties(XML::Node& SelfRoot) const;
259  /// @copydoc QuadRenderable::ProtoSerializeChildQuads(XML::Node&) const
260  virtual void ProtoSerializeChildQuads(XML::Node& SelfRoot) const;
261 
262  /// @copydoc Renderable::ProtoDeSerializeProperties(const XML::Node&)
263  virtual void ProtoDeSerializeProperties(const XML::Node& SelfRoot);
264  /// @copydoc QuadRenderable::ProtoDeSerializeChildQuads(const XML::Node&)
265  virtual void ProtoDeSerializeChildQuads(const XML::Node& SelfRoot);
266 
267  /// @copydoc Renderable::GetSerializableName()
268  static String GetSerializableName();
269 
270  ///////////////////////////////////////////////////////////////////////////////
271  // Internal Event Methods
272 
273  ///////////////////////////////////////////////////////////////////////////////
274  // Internal Methods
275 
276  };//ListBox
277 
278  ///////////////////////////////////////////////////////////////////////////////
279  /// @brief This is the factory implementation for ListBox widgets.
280  /// @details
281  ///////////////////////////////////////
283  {
284  public:
285  /// @brief Class constructor.
287  /// @brief Class destructor.
288  virtual ~ListBoxFactory() { }
289 
290  /// @copydoc WidgetFactory::GetWidgetTypeName() const
291  virtual String GetWidgetTypeName() const;
292 
293  /// @brief Creates a new ListBox.
294  /// @param RendName The name to be given to the created ListBox.
295  /// @param Style An enum value representing how the scrollbar child of thie ListBox will be constructed. See @ref UI::ScrollbarStyle enum for more info.
296  /// @param Parent The screen the created ListBox will belong to.
297  /// @return Returns a pointer to the created ListBox.
298  virtual ListBox* CreateListBox(const String& RendName, const UI::ScrollbarStyle& Style, Screen* Parent);
299  /// @brief Creates a new ListBox.
300  /// @param RendName The name to be given to the created ListBox.
301  /// @param RendRect The dimensions that will be assigned to the created ListBox.
302  /// @param Style An enum value representing how the scrollbar child of thie ListBox will be constructed. See @ref UI::ScrollbarStyle enum for more info.
303  /// @param Parent The screen the created ListBox will belong to.
304  /// @return Returns a pointer to the created ListBox.
305  virtual ListBox* CreateListBox(const String& RendName, const UnifiedRect& RendRect, const UI::ScrollbarStyle& Style, Screen* Parent);
306  /// @brief Creates a new ListBox.
307  /// @param XMLNode The node of the xml document to construct from.
308  /// @param Parent The screen the created ListBox will belong to.
309  /// @return Returns a pointer to the created ListBox.
310  virtual ListBox* CreateListBox(const XML::Node& XMLNode, Screen* Parent);
311 
312  /// @copydoc WidgetFactory::CreateWidget(Screen*)
313  virtual Widget* CreateWidget(Screen* Parent);
314  /// @copydoc WidgetFactory::CreateWidget(const String&, const NameValuePairMap&, Screen*)
315  virtual Widget* CreateWidget(const String& RendName, const NameValuePairMap& Params, Screen* Parent);
316  /// @copydoc WidgetFactory::CreateWidget(const String&, const UnifiedRect&, const NameValuePairMap&, Screen*)
317  virtual Widget* CreateWidget(const String& RendName, const UnifiedRect& RendRect, const NameValuePairMap& Params, Screen* Parent);
318  /// @copydoc WidgetFactory::CreateWidget(const XML::Node&, Screen*)
319  virtual Widget* CreateWidget(const XML::Node& XMLNode, Screen* Parent);
320  /// @copydoc WidgetFactory::DestroyWidget(Widget*)
321  virtual void DestroyWidget(Widget* ToBeDestroyed);
322  };//ListBoxFactory
323  }//UI
324 }//Mezzanine
325 
326 #endif
ListItemOrdering
This enum is used to describe how new ListItems are inserted into the list.
Definition: listbox.h:70
This class represents a collection of Glyphs in a common visual style.
Definition: font.h:55
virtual ~ListBoxFactory()
Class destructor.
Definition: listbox.h:288
FontData * ListItemFont
Stores the default font that will be used by all ListItems generated by this ListBox.
Definition: listbox.h:81
bool Boole
Generally acts a single bit, true or false.
Definition: datatypes.h:173
This is the factory implementation for ListBox widgets.
Definition: listbox.h:282
static const String TypeName
String containing the type name for this class: "ListBox".
Definition: listbox.h:77
Real ListItemCharScaling
The amount of auto-scaling to be applied to all created list items.
Definition: listbox.h:90
This is a helper class designed to describe the behaviors of a quad when it needs to be resized...
Definition: sizinginfo.h:56
This class represents a box shaped area on the screen.
Definition: rect.h:55
ScrollbarStyle
Used by the scrollbar class to determine what styling should be used for the scrollbar.
float Real
A Datatype used to represent a real floating point number.
Definition: datatypes.h:141
This class represents a 2D rect which can express the size and position of a renderable on screen...
Definition: unifieddim.h:661
VerticalContainer * ListContainer
A pointer to the vertical container storing all the list items.
Definition: listbox.h:87
ScalingMode
An enum used to describe how the text generated by this layer will be automatically scaled...
Definition: textlayer.h:91
ListItemOrdering Ordering
Stores how new entries will be inserted with other elements in this ListBox.
Definition: listbox.h:96
A light-weight handle for manipulating nodes in DOM tree.
Definition: node.h:89
This is the base class for all widgets.
Definition: widget.h:126
A layout container that aligns it's children along a common Y axis.
This Determines the kind of user input.
Definition: metacode.h:93
This class represents both the relative and absolute values that can be expressed for the values on o...
Definition: unifieddim.h:56
TextLayer::ScalingMode ListItemCharScalingMode
The auto-scaling mode that is to be applied to all created list items.
Definition: listbox.h:93
#define MEZZ_LIB
Some platforms require special decorations to denote what is exported/imported in a share library...
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
unsigned long Whole
Whole is an unsigned integer, it will be at least 32bits in size.
Definition: datatypes.h:151
This is a scrollbar class aligned on the Y axis.
VerticalScrollbar * ListScroll
A pointer to the vertical scrollbar responsible for the visible list items.
Definition: listbox.h:84
std::map< String, String > NameValuePairMap
This is a datatype mostly used for describing settings or parameters that can't be declared in advanc...
Definition: datatypes.h:209
This class is a helper class for creating UI's. It is responsible for storing and keeping track of al...
Definition: screen.h:142
std::string String
A datatype used to a series of characters.
Definition: datatypes.h:159
This is a base class for factories that construct the widgets available to the UI subsystem...
Definition: widgetfactory.h:61
ListBoxFactory()
Class constructor.
Definition: listbox.h:286
This is a widget for displaying a list of captions in a box.
Definition: listbox.h:63
Widget ListItem
Convenience typedef for objects that will be used to represent list items in this ListBox...
Definition: listbox.h:67