Hasty Badger
Small UI library (a branch of Turbo Badger)
 All Classes Namespaces Functions Variables Enumerations Enumerator Friends Groups Pages
tb_select.h
1 // ================================================================================
2 // == This file is a part of Turbo Badger. (C) 2011-2014, Emil SegerÃ¥s ==
3 // == See tb_core.h for more information. ==
4 // ================================================================================
5 
6 #ifndef TB_SELECT_H
7 #define TB_SELECT_H
8 
9 #include "tb_window.h"
10 #include "tb_scroll_container.h"
11 #include "tb_select_item.h"
12 
13 namespace tb {
14 
15 class TBMenuWindow;
16 
20 {
21 public:
22  // For safe typecasting
23  TBOBJECT_SUBCLASS(TBSelectList, TBWidget);
24 
25  TBSelectList();
26  ~TBSelectList();
27 
35  TBGenericStringItemSource *GetDefaultSource() { return &m_default_source; }
36 
39  void SetFilter(const TBStr & filter);
40  const TBStr & GetFilter() const { return m_filter; }
41 
44  void SetHeaderString(const TBID& id);
45 
49  void InvalidateList();
50 
52  void ValidateList();
53 
56  virtual void SetValue(long value);
57  virtual long GetValue() const { return m_value; }
58 
61 
69  bool ChangeValue(SPECIAL_KEY key);
70 
73  void SelectItem(int index, bool selected);
74  TBWidget *GetItemWidget(int index);
75 
78  void ScrollToSelectedItem();
79 
81  TBScrollContainer *GetScrollContainer() { return &m_container; }
82 
83  virtual void OnInflate(const INFLATE_INFO &info);
84  virtual void OnSkinChanged();
85  virtual void OnProcess();
86  virtual void OnProcessAfterChildren();
87  virtual bool OnEvent(const TBWidgetEvent &ev);
88 
89  // == TBSelectItemViewer ==================================================
90  virtual void OnSourceChanged();
91  virtual void OnItemChanged(int index);
92  virtual void OnItemAdded(int index);
93  virtual void OnItemRemoved(int index);
94  virtual void OnAllItemsRemoved();
95 protected:
96  TBScrollContainer m_container;
97  TBLayout m_layout;
98  TBGenericStringItemSource m_default_source;
99  int m_value;
100  TBStr m_filter;
101  bool m_list_is_invalid;
102  bool m_scroll_to_current;
103  TBID m_header_lng_string_id;
104 private:
105  TBWidget *CreateAndAddItemAfter(int index, TBWidget *reference);
106 };
107 
112 {
113 public:
114  // For safe typecasting
115  TBOBJECT_SUBCLASS(TBSelectDropdown, TBButton);
116 
118  ~TBSelectDropdown();
119 
127  TBGenericStringItemSource *GetDefaultSource() { return &m_default_source; }
128 
130  virtual void SetValue(long value);
131  virtual long GetValue() const { return m_value; }
132 
135 
137  void OpenWindow();
138 
140  void CloseWindow();
141 
143  TBMenuWindow *GetMenuIfOpen() const;
144 
145  virtual void OnInflate(const INFLATE_INFO &info);
146  virtual bool OnEvent(const TBWidgetEvent &ev);
147 
148  // == TBSelectItemViewer ==================================================
149  virtual void OnSourceChanged();
150  virtual void OnItemChanged(int index);
151  virtual void OnItemAdded(int /*index*/) {}
152  virtual void OnItemRemoved(int /*index*/) {}
153  virtual void OnAllItemsRemoved() {}
154 protected:
155  TBGenericStringItemSource m_default_source;
156  TBSkinImage m_arrow;
157  int m_value;
159 };
160 
161 } // namespace tb
162 
163 #endif // TB_SELECT_H
TBSelectDropdown shows a button that opens a popup with a TBSelectList with items provided by a TBSel...
Definition: tb_select.h:111
virtual void OnItemRemoved(int index)
Called when the item at the given index has been removed.
Definition: tb_select.cpp:91
virtual void SetValue(long value)
The value is the selected item.
Definition: tb_select.cpp:202
The base TBWidget class.
Definition: tb_widgets.h:418
TBWidgetSafePointer keeps a pointer to a widget that will be set to nullptr if the widget is removed...
Definition: tb_widgets_listener.h:74
TBGenericStringItemSource * GetDefaultSource()
Get the default item source for this widget.
Definition: tb_select.h:35
Definition: tb_widgets.h:112
void SetHeaderString(const TBID &id)
Set the language string id for the header.
Definition: tb_select.cpp:115
void SetFilter(const TBStr &filter)
Set filter string so only matching items will be showed.
Definition: tb_select.cpp:107
virtual void OnItemChanged(int index)
Called when the item at the given index has changed in a way that should update the viewer...
Definition: tb_select.cpp:383
virtual void OnAllItemsRemoved()
Called when all items have been removed.
Definition: tb_select.cpp:101
void SelectItem(int index, bool selected)
Set the selected state of the item at the given index.
Definition: tb_select.cpp:225
virtual void SetValue(long value)
Set the selected item.
Definition: tb_select.cpp:387
TBMenuWindow * GetMenuIfOpen() const
Return the menu window if it's open, or nullptr.
Definition: tb_select.cpp:428
TBSkinImage is a widget showing a skin element, constrained in size to its skin.
Definition: tb_widgets_common.h:217
TBGenericStringItemSource is a item source list providing items of type TBGenericStringItem.
Definition: tb_select_item.h:236
virtual void OnSourceChanged()
Called when the source has changed or been unset by calling SetSource.
Definition: tb_select.cpp:57
TBGenericStringItemSource * GetDefaultSource()
Get the default item source for this widget.
Definition: tb_select.h:127
TBMenuWindow is a popup window that shows a list of items (TBSelectList).
Definition: tb_menu_window.h:21
void ValidateList()
Make sure the list is reflecting the current items in the source.
Definition: tb_select.cpp:131
virtual void OnSourceChanged()
Called when the source has changed or been unset by calling SetSource.
Definition: tb_select.cpp:376
virtual void OnInflate(const INFLATE_INFO &info)
Called when this widget is inflated from resources, before any children have been inflated...
Definition: tb_widgets_reader.cpp:700
bool ChangeValue(SPECIAL_KEY key)
Change the value to a non disabled item that is visible with the current filter.
Definition: tb_select.cpp:320
TBID is a wrapper for a uint32_t to be used as ID.
Definition: tb_id.h:18
virtual void OnItemChanged(int index)
Called when the item at the given index has changed in a way that should update the viewer...
Definition: tb_select.cpp:62
virtual void OnProcessAfterChildren()
Callback for doing anything that might be needed before paint.
Definition: tb_select.cpp:265
TBButton is a regular button widget with auto repeat, toggle and group capabilities.
Definition: tb_widgets_common.h:111
virtual void OnProcess()
Callback for doing anything that might be needed before paint.
Definition: tb_select.cpp:260
virtual void OnItemAdded(int)
Called when the item at the given index has been added.
Definition: tb_select.h:151
void OpenWindow()
Open the window if the model has items.
Definition: tb_select.cpp:409
TBSelectItemViewer is the viewer for items provided by TBSelectItemSource.
Definition: tb_select_item.h:27
TBSelectList shows a scrollable list of items provided by a TBSelectItemSource.
Definition: tb_select.h:19
void ScrollToSelectedItem()
Scroll to the current selected item.
Definition: tb_select.cpp:241
TBScrollContainer - A container with scrollbars that can scroll its children.
Definition: tb_scroll_container.h:52
TBWidgetSafePointer m_window_pointer
Points to the dropdown window if opened.
Definition: tb_select.h:158
virtual bool OnEvent(const TBWidgetEvent &ev)
Callback for handling events.
Definition: tb_select.cpp:433
TBScrollContainer * GetScrollContainer()
Return the scrollcontainer used in this list.
Definition: tb_select.h:81
INFLATE_INFO contains info passed to TBWidget::OnInflate during resource loading. ...
Definition: tb_widgets_reader.h:21
virtual void OnInflate(const INFLATE_INFO &info)
Called when this widget is inflated from resources, before any children have been inflated...
Definition: tb_widgets_reader.cpp:692
TBID GetSelectedItemID()
Get the ID of the selected item, or 0 if there is no item selected.
Definition: tb_select.cpp:402
virtual void OnItemAdded(int index)
Called when the item at the given index has been added.
Definition: tb_select.cpp:81
TBStr is a simple string class.
Definition: tb_str.h:62
virtual long GetValue() const
See TBWidget::SetValue.
Definition: tb_select.h:131
TBID GetSelectedItemID()
Get the ID of the selected item, or 0 if there is no item selected.
Definition: tb_select.cpp:218
virtual void OnSkinChanged()
Called when the background skin changes by calling SetSkinBg(), or when the skin has changed indirect...
Definition: tb_select.cpp:255
void CloseWindow()
Close the window if it is open.
Definition: tb_select.cpp:422
virtual bool OnEvent(const TBWidgetEvent &ev)
Callback for handling events.
Definition: tb_select.cpp:271
virtual void OnAllItemsRemoved()
Called when all items have been removed.
Definition: tb_select.h:153
virtual void OnItemRemoved(int)
Called when the item at the given index has been removed.
Definition: tb_select.h:152
TBLayout layouts its children along the given axis.
Definition: tb_layout.h:96
void InvalidateList()
Make the list update its items to reflect the items from the in the current source.
Definition: tb_select.cpp:123
virtual long GetValue() const
See TBWidget::SetValue.
Definition: tb_select.h:57