Game Development Reference
In-Depth Information
m_scrollBar.SetSize( math::vector2(m_rectangle.Width() * 0.1f, backRect.Height() ) );
m_scrollBar.SetPosition( math::vector2(m_rectangle.Right() - m_scrollBar.Size().x(), m_rectangle.Top() ) );
}
One important component of a listbox is the scrollbar which we discuss in detail below.
Theimportantthingisthatifthenumberofitemsinalistboxchangessothattherearemore
items in the list than the size of the list, then we need to display the scrollbar. We also need
to configure the position and size of the scrollbar. For this example the scrollbar is fixed at
10% of the width of the listbox control, however in production code this value should be
exposed so that it becomes configurable by users.
Next we will need to handle input on the listbox, most of the input is actually deferred to
eitherthelistboxitemsorthescrollbar,andinfact,theonlyinputwemanagedirectlyinthe
listboxisthatofthemousewheel.Eventhen,ifwedetect anymousewheelmovement, we
forwardittothescrollbarwhichwillthencontroltheactualpositionofthelistbox'svisible
items.
bool listbox::HandleInput(float deltaTime, const input::input_state& inputState)
{
UNREFERENCED(deltaTime);
if ( inputState.GetMouse() != nullptr )
{
auto mouse = inputState.GetMouse();
if ( m_rectangle.Contains(mouse->GetPosition()) )
{
if (mouse->GetMouseWheelValue() != m_lastMouseWheelValue)
{
float delta = static_cast<float>( m_lastMouseWheelValue - mouse->GetMouseWheelValue() );
m_scrollBar.ApplyMovement(delta);
m_lastMouseWheelValue = mouse->GetMouseWheelValue();
return true;
}
}
}
if ( m_scrollBar.HandleInput(deltaTime, inputState) )
{
return true;
}
for ( auto it : m_items )
{
if (it->Visible() && it->HandleInput(deltaTime, inputState))
return true;
}
return false;
Search WWH ::




Custom Search