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
Combobox drop list automatic resize
Moderators: CEGUI MVP, CEGUI Team
- CrazyEddie
- CEGUI Project Lead
- Posts: 6760
- Joined: Wed Jan 12, 2005 12:06
- Location: England
- Contact:
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
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
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
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
- CrazyEddie
- CEGUI Project Lead
- Posts: 6760
- Joined: Wed Jan 12, 2005 12:06
- Location: England
- Contact:
- CrazyEddie
- CEGUI Project Lead
- Posts: 6760
- Joined: Wed Jan 12, 2005 12:06
- Location: England
- Contact:
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:
I hope it's useful
CE.
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.
- CrazyEddie
- CEGUI Project Lead
- Posts: 6760
- Joined: Wed Jan 12, 2005 12:06
- Location: England
- Contact:
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.
Useful Links: Forum Guidelines | Documentation | Tutorials | HOWTO | Videos | Donate to CEGUI | CEGUI Twitter
- CrazyEddie
- CEGUI Project Lead
- Posts: 6760
- Joined: Wed Jan 12, 2005 12:06
- Location: England
- Contact:
Hehe, luckily my reply was to what you meant, rather then what you originally said
Useful Links: Forum Guidelines | Documentation | Tutorials | HOWTO | Videos | Donate to CEGUI | CEGUI Twitter
Who is online
Users browsing this forum: No registered users and 15 guests