Listbox without a selected item

Forum for general chit-chat or off-topic discussion.

Moderators: CEGUI MVP, CEGUI Team

Rackle
CEGUI Team (Retired)
Posts: 534
Joined: Mon Jan 16, 2006 11:59
Location: Montréal

Listbox without a selected item

Postby Rackle » Tue Apr 25, 2006 01:23

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.

Return to “Offtopic Discussion”

Who is online

Users browsing this forum: No registered users and 13 guests