Gorgon Game Engine
ListboxBase< T_, W_, TRF_, STR_, SELTR_, useisvisible, TW_ > Class Template Reference

This is the base class for all listbox like widgets. More...

Inheritance diagram for ListboxBase< T_, W_, TRF_, STR_, SELTR_, useisvisible, TW_ >:
[legend]

Public Types

using SelectionType = SELTR_
 
using StorageType = STR_
 
using TypeTraits = TRF_
 

Public Member Functions

virtual long GetCount () const override
 Returns the number of elements in the list. More...
 
virtual const T_ & operator[] (long index) const override
 Returns the item at the given point. More...
 
virtual T_ & operator[] (long index) override
 Returns the item at the given point. More...
 
- Public Member Functions inherited from ListBase< T_, W_ >
virtual ~ListBase ()
 
virtual long getindex (const W_ &widget)=0
 For internal use. More...
 
virtual void Refresh ()=0
 This function should refresh the contents of the listbox. More...
 

Protected Member Functions

 ListboxBase ()
 
- Protected Member Functions inherited from ListBase< T_, W_ >
virtual W_ * getrepresentation ()=0
 For internal use. More...
 
virtual W_ * getrepresentation (long index)=0
 For internal use. More...
 

Detailed Description

template<class T_, class W_, class TRF_, class STR_, class SELTR_, bool useisvisible, void(*)(const T_ &, W_ &) TW_>
class Gorgon::Widgets::ListboxBase< T_, W_, TRF_, STR_, SELTR_, useisvisible, TW_ >

This is the base class for all listbox like widgets.

It is not intended to be used directly but you may use it to create your own listboxes. The solid listboxes should be derived from this object and should make desired functionality public.

Listbox will maintain the necessary number widgets to fill its area. It does not create widgets for elements falling outside the range. If traits can return different tags, the widgets to cover its area will be created separately for these tags.

Listbox has multi-column functionality. However, this is not to be used for tables. Table systems should insert rows as listbox items, which then should have cells.

Template parameters

T_ is the stored data type.

W_ is the widget that will be used to represent items.

TR_ is widget traits class that allows additional properties for each element. They should contain minimal number of data members. There should be a function Apply taking W_ &, const T_ &, Point index, Size total as parameters applying traits to W_. Additionally, TR_ should have Tag function that has const T_ &, Point index, Size total as parameters and should return UI::ComponentTemplate::Tag to determine the template for the widget. The tags should match with the listbox template. If the given tag is not found, ItemTag will be used.

TRF_ is the trait functions that will return/set the traits of items. TRF_ should contain access function that should take the index of an item to return TR_ associated with it. It should contain insert(before, count) to add count elements before the given index. These elements must be default initialized to a normal state. move(index, before) should move the indexed item before the given index. remove(index, count) should remove count number of items starting from the given index. prepare(W_ &) function should prepare the given widget for the first usage. This is only called once on a newly created widget. destroy(W_ &) function is called when a widget is about to be destroyed. Index parameters should be long int. These functions should be protected as ListboxBase will be derived from TRF_. Finally, TRF_ should have a protected constructor/destructor.

STR_ is the storage traits for T_. This class should contain typedef Storage which is the storage. It should have functions that allows it to handle Add/Remove/Insert/Move/getsize/getelm functions. Only getsize and getelm functions are mandatory. getelm should take a long index and should return the stored value. GetSize should return long. Additionally, this function should have a protected storage member named storage. After every modifying operation, this function should call Refresh. Ideally, this class should contain

useisvisible controls if elements can be hidden. If this is true, TR_ should have IsVisible function returning bool. This parameter will slowdown listbox considerably when many items are stored as each item will be checked whether they are visible until to the point of display. This will not affect the performance on short lists.

SELTR_ is the class that will control selection traits of the Listbox. Defult traits allow single select. It is possible to construct list of particular widgets that has no concept of selection if selection traits is set to internal::LBSELTR_None. This class should support sel_click and sel_toggle functions both taking long index, const T_ & value, W_ &widget. Click function will be called when the user uses arrow keys to select an item. It is this classes responsibility to handle actual click and toggle functions. apply function should apply selection related traits to the widget taking long index, W_ &widget, const T_ & value. Any item that is benched will be applied to as well with an index of -1. This class should contain insert(before, count) to add count elements before the given index. These elements must be default initialized to a non-selected normal state. sel_move(index, before) should move the indexed item before the given index. sel_remove(index, count) should remove count number of items starting from the given index. sel_prepare(W_ &) function should prepare the given widget for the first usage. This is only called once on a newly created widget. sel_destroy(W_ &) function is called when a widget is about to be destroyed. Index parameters should be long int. These functions should be protected as ListboxBase will be derived from SELTR_. Finally, SELTR_ should have a protected constructor/destructor. reapplyfocus function should apply the focus to the focused element. This function is called after listbox receives focus. GetFocusIndex and SetFocusIndex functions should exist to handle focus changes through keyboard keys.

TW_ function should take a T_ and set this to its W_ representation.

Member Typedef Documentation

◆ SelectionType

using SelectionType = SELTR_

◆ StorageType

using StorageType = STR_

◆ TypeTraits

using TypeTraits = TRF_

Constructor & Destructor Documentation

◆ ListboxBase()

ListboxBase ( )
protected

Member Function Documentation

◆ GetCount()

virtual long GetCount ( ) const
overridevirtual

Returns the number of elements in the list.

Implements ListBase< T_, W_ >.

◆ operator[]() [1/2]

virtual const T_& operator[] ( long  index) const
overridevirtual

Returns the item at the given point.

This operator will not perform bounds checking.

Implements ListBase< T_, W_ >.

◆ operator[]() [2/2]

virtual T_& operator[] ( long  index)
overridevirtual

Returns the item at the given point.

This operator will not perform bounds checking. Changing the returned value will not automatically refresh the contents.

Implements ListBase< T_, W_ >.


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