Game Development Reference
In-Depth Information
private:
int m_value;
};
m_listbox->Add(L"Item 1", std::shared_ptr<sampledata>( new sampledata(0) ) );
m_listbox->Add(L"Item 2", std::shared_ptr<sampledata>( new sampledata(1) ) );
m_listbox->Add(L"Item 3", std::shared_ptr<sampledata>( new sampledata(2) ) );
If you have worked with C# WinForms or WPF this is conceptually similar to the Tag ob-
ject that is used to store custom information about the listbox's item.
At some point we will want to query the listbox for its selected items. We provided a list
of selected items that users can retrieve. This listbox was designed using a std::list as the
item container, while this simplifies the listbox's code, it is not the most optimal container
to use. It becomes obvious when we want to query and search for a given item. Using a
vector, we could maintain a list of selected indices and then use the indices to look into the
items vector and fetch those selected items, using a list we have no choice but to iterate the
list and compare against the item we are interested in.
Earlier when we implemented the listbox's functionality we used a scrollbar, a scroll bar is
a useful control that can be reused by different controls so we will now see how to imple-
ment it as a standalone control.
4.3.9 Scroll Bar
A scroll bar is a control that is useful in conjunction with other controls, namely with con-
trols that have so many options that cannot be visible within the designated space. The
scroll bar controls the visible elements or area of some other control.
Thebehaviorofascrollbarcanbeabstracted toworkasastandalone entity thatothercon-
trols use. The scroll bar will be constructed with some knowledge ofthe control it is linked
to, its size, how many options and the size of each option. The scroll bar can be manipu-
lated by users, scrolling between a minimum point and a maximum point. To the control
thatownsthescrollbar,itistheratio,thevaluethatrepresentstherelativepositionbetween
the minimum and maximum points that will be useful.
Search WWH ::




Custom Search