Page 1 of 1

Combobox drop list automatic resize

Posted: Wed Nov 19, 2008 10:08
by SalvoFa
Hi all,

I'm dynamically adding items to a combobox drop list...so I need the drop list height to fit perfectly with the items count...I know that there is a method that does this thing...but I'm not able to find it in the documentation anymore...please can you help me?

Thank you

Posted: Wed Nov 19, 2008 11:49
by CrazyEddie
Hi,

I don't think we have such a thing actually. I think the solution at the moment will be to manually set the size, which is complicated by the fact that the client interface to do this also includes the height of the editbox portion of the control.

So basically, what you're looking at is obtain the height from each of the attached items and sum the results to get the required height of the rendering area part (call this items_height). Then you need to obtain the editbox child control and ask it how high it is (call this edit_height). Then you need to discover how much of the height of the drop-list is taken up by imagery - one way to do this would be to query the height of the drop-list, then get the height of the rendering area via the attached looknfeel (taking into account the possibility of a horizontal scrollbar, so either named area "ItemRenderingArea" or "ItemRenderingAreaHScroll"), subtract the latter from the former and you get the height of the list imagery (call this imagery_height). The final size of your Combobox would then be items_height + edit_height + imagery_height. This assumes a traditional layout within the looknfeel - if your list part is offset vertically at all, you'll likely have to factor that in also (which is the difference between the bottom of the editbox and the top of the droplist).

So, yeah. That's a bit of a crappy way to have to do this, but I think it's the only way at the moment :shock:

CE.

Edit: re-reading your post, I'm not sure if you're using the full Combobox or just the DropList. Please clarify, as it makes some of the above a little simpler ;)

Posted: Wed Nov 19, 2008 14:00
by SalvoFa
Hi Eddie!
Thank you for your answer...
Currently I'm using the full combobox item....

Posted: Wed Nov 19, 2008 14:38
by CrazyEddie
Hi,

Ok, for the full Combobox, the procedure is as I described it above. If you need a code example of that, I'll do my best when I get home this evening.

CE.

Posted: Wed Nov 19, 2008 14:53
by SalvoFa
CrazyEddie wrote:Hi,

Ok, for the full Combobox, the procedure is as I described it above. If you need a code example of that, I'll do my best when I get home this evening.

CE.


That would be great...if possible...thank you very much! 8)

Posted: Wed Nov 19, 2008 19:50
by CrazyEddie
Ok, here is function that pretty much does what you need. Note that this does no error checking, so you should really add that if you want to be robust!

The code basically follows what I said earlier:

Code: Select all

void sizeComboList(CEGUI::Combobox* cb)
{
    // get the size of the attached items
    float items_size = 0.0f;
    for (int i = 0; i < cb->getItemCount(); ++i)
        items_size += cb->getListboxItemFromIndex(i)->getPixelSize().d_height;

    // get size of editbox portion
    float edit_size = cb->getEditbox()->getPixelSize().d_height;

    // calculate how much size is taken by frame imagery & scrollbars
    CEGUI::ComboDropList* dl = cb->getDropList();
    CEGUI::String render_area_name(dl->getHorzScrollbar()->isVisible() ?
        "ItemRenderingAreaHScroll" : "ItemRenderingArea" );

    const CEGUI::WidgetLookFeel& wl =
        CEGUI::WidgetLookManager::getSingleton().getWidgetLook(dl->getLookNFeel());

    float images_size = dl->getPixelSize().d_height -
        wl.getNamedArea(render_area_name).getArea().getPixelRect(*dl).getHeight();

    // consider the possibility of an offset list position
    float droplist_offset =
        dl->getYPosition().asAbsolute(cb->getPixelSize().d_height) - edit_size;

    // set final size
    cb->setHeight( CEGUI::UDim( 0.0f,
                   items_size + edit_size + images_size + droplist_offset) );
}


I hope it's useful :)

CE.

Posted: Tue Mar 31, 2009 08:51
by SalvoFa
It has been passed a very long time since your reply Eddie...however I've to thank you because that piece of code worked perfectly!
I would be good to be integrated in the combobox class!
:)

Posted: Tue Mar 31, 2009 18:23
by CrazyEddie
SalvoFa wrote:I would be good to be integrated in the combobox class!
:)

Yeah, we might think about such a thing, though - as always - there are complications that may inhibit this happening ;)

CE.

Posted: Wed Apr 01, 2009 11:11
by SalvoFa
Ops...
I used "I" instead of "it"

This is the right one...
"It would be good to be integrated in the combobox class!" :lol:

Posted: Thu Apr 02, 2009 08:20
by CrazyEddie
Hehe, luckily my reply was to what you meant, rather then what you originally said ;)