Page 1 of 1

MultiColumnList Selection

Posted: Wed Aug 10, 2005 02:52
by EJohnson
Hi,

Is there an easy way, in code, to select an entire row? For example, I want the 3rd row to be selected by default.

I was hoping to see something like:

Code: Select all

list->setRowSelectState(3, true);

Re: MultiColumnList Selection

Posted: Wed Aug 10, 2005 08:34
by CrazyEddie
As long as you're using one of the whole row selection modes, the function:

MultiColumnList::setItemSelectState

Should do what you want.

Re: MultiColumnList Selection

Posted: Wed Aug 10, 2005 21:09
by EJohnson
..and so it does! :D


One more quick one that's related:

Is there a way to automatically scroll the MultiColumnList to the selected row? It looks like the ListBox does this with

Code: Select all

 ListBox::ensureItemIsVisible()


?

Re: MultiColumnList Selection

Posted: Thu Aug 11, 2005 13:33
by CrazyEddie
Hmmmm. Seems we do not have anything like this. It should probably be added though ;)

Posted: Tue Jun 27, 2006 02:31
by Rackle
I've adapted void Listbox::ensureItemIsVisible(size_t item_index) and void Listbox::ensureItemIsVisible(const ListboxItem* item) to a MultiColumnList object (and replaced the i variable with a row). It should be fairly easy to move this code within the MultiColumnList code.

What I'm unsure of (I have not looked enough at v0.5.0 yet) is whether the height is the same for every ListboxItem of a row, in which case the code below should be final, otherwise we'd have to iterate through each item on that row and find the highest.

Code: Select all

void ensureItemIsVisible(const CEGUI::MultiColumnList* multiColumnList, const CEGUI::ListboxItem* listboxItem)
{
   ensureItemIsVisible(multiColumnList, multiColumnList->getItemRowIndex(listboxItem));
}

void ensureItemIsVisible(const CEGUI::MultiColumnList* multiColumnList, const CEGUI::uint& rowID)
{
    using namespace CEGUI;
    Scrollbar* vertScrollbar = multiColumnList->getVertScrollbar();

   // handle simple "scroll to the bottom" case
   if (rowID >= multiColumnList->getRowCount())
   {
      vertScrollbar->setScrollPosition(vertScrollbar->getDocumentSize() - vertScrollbar->getPageSize());
   }
   else
   {
      float bottom;
      float listHeight = multiColumnList->getListRenderArea().getHeight();
      float top = 0;

      // get height to top of item
      CEGUI::uint row;
      for (row = 0; row < rowID; ++row)
      {
         MCLGridRef grid_ref(row, 0);
         top += multiColumnList->getItemAtGridReference(grid_ref)->getPixelSize().d_height;
         //top += d_listItems[i]->getPixelSize().d_height;
      }

      // calculate height to bottom of item
      MCLGridRef grid_ref(row, 0);
      bottom = top + multiColumnList->getItemAtGridReference(grid_ref)->getPixelSize().d_height;
      //bottom = top + d_listItems[i]->getPixelSize().d_height;

      // account for current scrollbar value
      float currPos = vertScrollbar->getScrollPosition();
      top      -= currPos;
      bottom   -= currPos;

      // if top is above the view area, or if item is too big to fit
      if ((top < 0.0f) || ((bottom - top) > listHeight))
      {
         // scroll top of item to top of box.
         vertScrollbar->setScrollPosition(currPos + top);
      }
      // if bottom is below the view area
      else if (bottom >= listHeight)
      {
         // position bottom of item at the bottom of the list
         vertScrollbar->setScrollPosition(currPos + bottom - listHeight);
      }
      
      // Item is already fully visible - nothing more to do.
   }
}