TGUI  v0.6.10
ListBox.hpp
1 //
3 // TGUI - Texus's Graphical User Interface
4 // Copyright (C) 2012-2015 Bruno Van de Velde (vdv_b@tgui.eu)
5 //
6 // This software is provided 'as-is', without any express or implied warranty.
7 // In no event will the authors be held liable for any damages arising from the use of this software.
8 //
9 // Permission is granted to anyone to use this software for any purpose,
10 // including commercial applications, and to alter it and redistribute it freely,
11 // subject to the following restrictions:
12 //
13 // 1. The origin of this software must not be misrepresented;
14 // you must not claim that you wrote the original software.
15 // If you use this software in a product, an acknowledgment
16 // in the product documentation would be appreciated but is not required.
17 //
18 // 2. Altered source versions must be plainly marked as such,
19 // and must not be misrepresented as being the original software.
20 //
21 // 3. This notice may not be removed or altered from any source distribution.
22 //
24 
25 
26 #ifndef TGUI_LIST_BOX_HPP
27 #define TGUI_LIST_BOX_HPP
28 
29 
30 #include <TGUI/Widget.hpp>
31 
33 
34 namespace tgui
35 {
36  class Scrollbar;
37 
39 
40  class TGUI_API ListBox : public Widget, public WidgetBorders
41  {
42  public:
43 
45 
46 
51  ListBox();
52 
53 
60  ListBox(const ListBox& copy);
61 
62 
67  virtual ~ListBox();
68 
69 
78  ListBox& operator= (const ListBox& right);
79 
80 
82  // Makes a copy of the widget by calling the copy constructor.
83  // This function calls new and if you use this function then you are responsible for calling delete.
85  virtual ListBox* clone();
86 
87 
97  bool load(const std::string& configFileFilename, const std::string& sectionName = "ListBox");
98 
99 
107  const std::string& getLoadedConfigFile() const;
108 
109 
117  void setSize(float width, float height);
118 
119 
128  virtual sf::Vector2f getSize() const;
129 
130 
139  virtual sf::Vector2f getFullSize() const;
140 
141 
152  void changeColors(const sf::Color& backgroundColor = sf::Color::White,
153  const sf::Color& textColor = sf::Color::Black,
154  const sf::Color& selectedBackgroundColor = sf::Color(50, 100, 200),
155  const sf::Color& selectedTextColor = sf::Color::White,
156  const sf::Color& borderColor = sf::Color::Black);
157 
158 
165  void setBackgroundColor(const sf::Color& backgroundColor);
166 
167 
174  void setTextColor(const sf::Color& textColor);
175 
176 
183  void setSelectedBackgroundColor(const sf::Color& selectedBackgroundColor);
184 
185 
192  void setSelectedTextColor(const sf::Color& selectedTextColor);
193 
194 
201  void setBorderColor(const sf::Color& borderColor);
202 
203 
210  const sf::Color& getBackgroundColor() const;
211 
212 
219  const sf::Color& getTextColor() const;
220 
221 
228  const sf::Color& getSelectedBackgroundColor() const;
229 
230 
237  const sf::Color& getSelectedTextColor() const;
238 
239 
246  const sf::Color& getBorderColor() const;
247 
248 
258  void setTextFont(const sf::Font& font);
259 
260 
267  const sf::Font* getTextFont() const;
268 
269 
287  int addItem(const sf::String& itemName, int id = 0);
288 
289 
306  bool setSelectedItem(const sf::String& itemName);
307 
308 
325  bool setSelectedItem(int index);
326 
327 
332  void deselectItem();
333 
334 
345  bool removeItem(unsigned int index);
346 
347 
358  bool removeItem(const sf::String& itemName);
359 
360 
369  unsigned int removeItemsById(int id);
370 
371 
376  void removeAllItems();
377 
378 
390  sf::String getItem(unsigned int index) const;
391 
392 
406  int getItemIndex(const sf::String& itemName) const;
407 
408 
415  std::vector<sf::String>& getItems();
416 
417 
427  sf::String getSelectedItem() const;
428 
429 
441  int getSelectedItemIndex() const;
442 
443 
451  int getSelectedItemId() const;
452 
453 
463  bool changeItem(unsigned int index, const sf::String& newValue);
464 
465 
475  unsigned int changeItems(const sf::String& originalValue, const sf::String& newValue);
476 
477 
487  unsigned int changeItemsById(int id, const sf::String& newValue);
488 
489 
501  bool setScrollbar(const std::string& scrollbarConfigFileFilename);
502 
503 
510  void removeScrollbar();
511 
512 
523  void setItemHeight(unsigned int itemHeight);
524 
525 
532  unsigned int getItemHeight() const;
533 
534 
544  void setMaximumItems(unsigned int maximumItems = 0);
545 
546 
554  unsigned int getMaximumItems() const;
555 
556 
566  virtual void setBorders(unsigned int leftBorder = 0,
567  unsigned int topBorder = 0,
568  unsigned int rightBorder = 0,
569  unsigned int bottomBorder = 0);
570 
571 
582  virtual void setTransparency(unsigned char transparency);
583 
584 
588  virtual bool mouseOnWidget(float x, float y);
589 
593  virtual void leftMousePressed(float x, float y);
594 
598  virtual void leftMouseReleased(float x, float y);
599 
603  virtual void mouseMoved(float x, float y);
604 
608  virtual void mouseWheelMoved(int delta, int x, int y);
609 
613  virtual void mouseNotOnWidget();
614 
618  virtual void mouseNoLongerDown();
619 
620 
623  // This function is a (slow) way to set properties on the widget, no matter what type it is.
624  // When the requested property doesn't exist in the widget then the functions will return false.
626  virtual bool setProperty(std::string property, const std::string& value);
627 
630  // This function is a (slow) way to get properties of the widget, no matter what type it is.
631  // When the requested property doesn't exist in the widget then the functions will return false.
633  virtual bool getProperty(std::string property, std::string& value) const;
634 
635 
638  // Returns a list of all properties that can be used in setProperty and getProperty.
639  // The second value in the pair is the type of the property (e.g. int, uint, string, ...).
641  virtual std::list< std::pair<std::string, std::string> > getPropertyList() const;
642 
643 
645  protected:
646 
648  // This function is called when the widget is added to a container.
650  virtual void initialize(Container *const container);
651 
652 
654  // Draws the widget on the render target.
656  virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
657 
658 
660  public:
661 
666  {
667  ItemSelected = WidgetCallbacksCount * 1,
668  AllListBoxCallbacks = WidgetCallbacksCount * 2 - 1,
669  ListBoxCallbacksCount = WidgetCallbacksCount * 2
670  };
671 
672 
674  protected:
675 
676  std::string m_LoadedConfigFile;
677 
678  // This contains the different items in the list box
679  std::vector<sf::String> m_Items;
680  std::vector<int> m_ItemIds;
681 
682  // What is the index of the selected item?
683  int m_SelectedItem;
684 
685  // The size must be stored
686  sf::Vector2u m_Size;
687  unsigned int m_ItemHeight;
688  unsigned int m_TextSize;
689 
690  // This will store the maximum number of items in the list box (zero by default, meaning that there is no limit)
691  unsigned int m_MaxItems;
692 
693  // When there are too many items a scrollbar will be shown
694  Scrollbar* m_Scroll;
695 
696  // These colors are used to draw the list box
697  sf::Color m_BackgroundColor;
698  sf::Color m_TextColor;
699  sf::Color m_SelectedBackgroundColor;
700  sf::Color m_SelectedTextColor;
701  sf::Color m_BorderColor;
702 
703  // The font used to draw the text
704  const sf::Font* m_TextFont;
705 
706  // ComboBox contains a list box internally and it should be able to adjust it.
707  friend class ComboBox;
708 
710  };
711 
713 }
714 
716 
717 #endif // TGUI_LIST_BOX_HPP
Namespace that contains all TGUI functions and classes.
Definition: AnimatedPicture.hpp:33
The parent class for every widget.
Definition: Widget.hpp:45
Definition: ComboBox.hpp:38
Parent class for every widget that has borders.
Definition: Widget.hpp:480
Parent class for widgets that store multiple widgets.
Definition: Container.hpp:43
Definition: ListBox.hpp:40
ListBoxCallbacks
Defines specific triggers to ListBox.
Definition: ListBox.hpp:665
Definition: Scrollbar.hpp:38