My own code and that of Demo 7 have a "trick" to put the listbox in a state where there are no items selected. Scroll to the bottom of the list and click just below the last entry, at the same height as the down arrow and presto! your listbox no longer has any item selected. I was wondering if this was a feature or bug.
Here's the workaround that I'm using to ensure that there's always one item selected. It's not the best solution but it works. First the listbox subscribe to the Listbox::EventSelectionChanged event:
CEGUI::Listbox* listbox = static_cast<CEGUI::Listbox*>(CEGUI::WindowManager::getSingleton().getWindow(m_widget));
listbox->subscribeEvent(CEGUI::Listbox::EventSelectionChanged, CEGUI::Event::Subscriber(&Listbox::onChanged, this));
And then the event itself selects the first item:
bool Listbox::onChanged(const CEGUI::EventArgs& e)
{
// Ensure that at least one list item is selected
CEGUI::Listbox* listbox = static_cast<CEGUI::Listbox*>(CEGUI::WindowManager::getSingleton().getWindow(m_widget));
if( !listbox->getFirstSelectedItem() )
listbox->setItemSelectState(listListboxItems[0].item, true);
return true;
}
A better solution would be to select the last item.
Listbox without a selected item
Moderators: CEGUI MVP, CEGUI Team
Return to “Offtopic Discussion”
Who is online
Users browsing this forum: No registered users and 7 guests