Hasty Badger
Small UI library (a branch of Turbo Badger)
 All Classes Namespaces Functions Variables Enumerations Enumerator Friends Groups Pages
tb::TBSelectItemSource Class Referenceabstract

TBSelectItemSource is a item provider interface for list widgets (TBSelectList and TBSelectDropdown). More...

#include <tb_select_item.h>

Inheritance diagram for tb::TBSelectItemSource:
tb::TBTypedObject tb::TBSelectItemSourceList< T > tb::TBSelectItemSourceList< TBGenericStringItem > tb::TBGenericStringItemSource

Public Member Functions

 TBOBJECT_SUBCLASS (TBSelectItemSource, TBTypedObject)
 
virtual bool Filter (int index, const TBStr &filter)
 Return true if an item matches the given filter text. More...
 
virtual const TBStrGetItemString (int index) const =0
 Get the string of a item. More...
 
virtual TBSelectItemSourceGetItemSubSource (int)
 Get the source to be used if this item should open a sub menu. More...
 
virtual TBID GetItemImage (int) const
 Get the skin image to be painted before the text for this item. More...
 
virtual TBID GetItemID (int) const
 Get the id of the item. More...
 
virtual TBWidgetCreateItemWidget (int index, TBSelectItemViewer *viewer)
 Create the item representation widget(s). More...
 
virtual int GetNumItems () const =0
 Get the number of items.
 
virtual int FindIDIndex (TBID id) const
 Get the index of the first item having this id or -1 if not found.
 
void SetSort (TB_SORT sort)
 Set sort type. More...
 
TB_SORT GetSort () const
 
void InvokeItemChanged (int index, TBSelectItemViewer *exclude_viewer=nullptr)
 Invoke OnItemChanged on all open viewers for this source. More...
 
void InvokeItemAdded (int index)
 
void InvokeItemRemoved (int index)
 
void InvokeAllItemsRemoved ()
 
- Public Member Functions inherited from tb::TBTypedObject
virtual bool IsOfTypeId (const TB_TYPE_ID type_id) const
 Returns true if the class or the base class matches the type id.
 
template<class T >
T * SafeCastTo () const
 Returns this object as the given type or nullptr if it's not that type. More...
 
template<class T >
bool IsOfType () const
 Return true if this object can safely be casted to the given type. More...
 
virtual const char * GetClassName () const
 Get the classname of the object. More...
 

Friends

class TBSelectItemViewer
 

Additional Inherited Members

- Static Public Member Functions inherited from tb::TBTypedObject
template<class T >
static TB_TYPE_ID GetTypeId ()
 A static template method that returns a unique id for each type. More...
 

Detailed Description

TBSelectItemSource is a item provider interface for list widgets (TBSelectList and TBSelectDropdown).

Instead of feeding all list widgets with all items all the time, the list widgets will ask TBSelectItemSource when it needs it. The list widgets may also apply filtering so only a subset of all the items are shown.

CreateItemWidget can be overridden to create any set of widget content for each item.

This class has no storage of items. If you want an array storage of items, use the subclass TBSelectItemSourceList. If you implement your own storage, remember to call InvokeItem[Added/...] to notify viewers that they need to update.

Member Function Documentation

TBWidget * tb::TBSelectItemSource::CreateItemWidget ( int  index,
TBSelectItemViewer viewer 
)
virtual

Create the item representation widget(s).

By default, it will create a TBTextField for string-only items, and other types for items that also has image or submenu.

Reimplemented in tb::TBSelectItemSourceList< T >, and tb::TBSelectItemSourceList< TBGenericStringItem >.

bool tb::TBSelectItemSource::Filter ( int  index,
const TBStr filter 
)
virtual

Return true if an item matches the given filter text.

By default, it returns true if GetItemString contains filter.

virtual TBID tb::TBSelectItemSource::GetItemID ( int  ) const
inlinevirtual
virtual TBID tb::TBSelectItemSource::GetItemImage ( int  ) const
inlinevirtual

Get the skin image to be painted before the text for this item.

Reimplemented in tb::TBSelectItemSourceList< T >, and tb::TBSelectItemSourceList< TBGenericStringItem >.

virtual const TBStr& tb::TBSelectItemSource::GetItemString ( int  index) const
pure virtual

Get the string of a item.

If a item has more than one string, return the one that should be used for inline-find (pressing keys in the list will scroll to the item starting with the same letters), and for sorting the list.

Implemented in tb::TBSelectItemSourceList< T >, and tb::TBSelectItemSourceList< TBGenericStringItem >.

virtual TBSelectItemSource* tb::TBSelectItemSource::GetItemSubSource ( int  )
inlinevirtual

Get the source to be used if this item should open a sub menu.

Reimplemented in tb::TBSelectItemSourceList< T >, and tb::TBSelectItemSourceList< TBGenericStringItem >.

void tb::TBSelectItemSource::InvokeItemChanged ( int  index,
TBSelectItemViewer exclude_viewer = nullptr 
)

Invoke OnItemChanged on all open viewers for this source.

void tb::TBSelectItemSource::SetSort ( TB_SORT  sort)
inline

Set sort type.

Default is TB_SORT_NONE.


The documentation for this class was generated from the following files: