Combobox drop list automatic resize

For help with general CEGUI usage:
- Questions about the usage of CEGUI and its features, if not explained in the documentation.
- Problems with the CMAKE configuration or problems occuring during the build process/compilation.
- Errors or unexpected behaviour.

Moderators: CEGUI MVP, CEGUI Team

SalvoFa
Not too shy to talk
Not too shy to talk
Posts: 29
Joined: Mon Feb 25, 2008 15:25
Location: Italy

Combobox drop list automatic resize

Postby SalvoFa » Wed Nov 19, 2008 10:08

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

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Postby CrazyEddie » Wed Nov 19, 2008 11:49

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 ;)

SalvoFa
Not too shy to talk
Not too shy to talk
Posts: 29
Joined: Mon Feb 25, 2008 15:25
Location: Italy

Postby SalvoFa » Wed Nov 19, 2008 14:00

Hi Eddie!
Thank you for your answer...
Currently I'm using the full combobox item....

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Postby CrazyEddie » Wed Nov 19, 2008 14:38

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.

SalvoFa
Not too shy to talk
Not too shy to talk
Posts: 29
Joined: Mon Feb 25, 2008 15:25
Location: Italy

Postby SalvoFa » Wed Nov 19, 2008 14:53

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)

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Postby CrazyEddie » Wed Nov 19, 2008 19:50

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.

SalvoFa
Not too shy to talk
Not too shy to talk
Posts: 29
Joined: Mon Feb 25, 2008 15:25
Location: Italy

Postby SalvoFa » Tue Mar 31, 2009 08:51

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!
:)

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Postby CrazyEddie » Tue Mar 31, 2009 18:23

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.

SalvoFa
Not too shy to talk
Not too shy to talk
Posts: 29
Joined: Mon Feb 25, 2008 15:25
Location: Italy

Postby SalvoFa » Wed Apr 01, 2009 11:11

Ops...
I used "I" instead of "it"

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

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Postby CrazyEddie » Thu Apr 02, 2009 08:20

Hehe, luckily my reply was to what you meant, rather then what you originally said ;)


Return to “Help”

Who is online

Users browsing this forum: No registered users and 15 guests