automatic size of combobox

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

djphilipe
Quite a regular
Quite a regular
Posts: 48
Joined: Thu Aug 23, 2007 10:15
Location: Slovakia
Contact:

automatic size of combobox

Postby djphilipe » Tue Sep 25, 2007 14:13

I again :)
How I set automatic size of combobox (comboDropList) by count text rows and text extent... without scrollbar.

I made method(down), but it is very complicated...
Exist something like in CEGUI?


void GUIScreen::setAutomaticSizeOfCombobox(const CEGUI::String& sComboBoxName, const char* sfontName)
{
CEGUI::Combobox* pCombo = static_cast<Combobox*> (getChildByName(sComboBoxName));
pCombo->getDropList()->setClippedByParent(false);
pCombo->getDropList()->setFont(sfontName);
CEGUI::Font* font = pCombo->getDropList()->getFont();

int resolutionHeight = (int)System::getSingleton().getRenderer()->getRect().d_bottom;

int maxWidth = (int)pCombo->getPixelRect().d_right -5;//-5 correction
int minWidth = (int)pCombo->getPixelSize().d_width;
int maxHeight = (int)(resolutionHeight - pCombo->getPixelRect().d_top-5);//-5 correction

//set height of combobox
int totalItemHeight = (int)pCombo->getDropList()->getTotalItemsHeight();
int editboxHeight = (int)pCombo->getEditbox()->getPixelSize().d_height;

//set corrections
int topBorderHeight = pCombo->getDropList()->getListRenderArea().d_top;
int correctionHor = pCombo->getDropList()->getListRenderArea().d_left*2; //this is correction because of DropList's borders (left,right)
int correctionVer = 0; //this is correction because of DropList's borders (top,bottom)

switch(resolutionHeight)
{
case 600:correctionVer = topBorderHeight*3;break;
case 768:correctionVer = topBorderHeight*2;break;
default: correctionVer = topBorderHeight*1.5;break;
}
int correctionScrollbar =0;

int newComboBoxHeight = totalItemHeight+correctionVer+editboxHeight;

//set height of combobox
if (newComboBoxHeight > maxHeight)
{
pCombo->setHeight(UDim(0, maxHeight));
correctionScrollbar = correctionVer*3;
}
else
{
pCombo->setHeight(UDim(0, newComboBoxHeight));
}

//set width of comboDropList
if (pCombo->getItemCount()>0)
{
int longestTextPix = (int)font->getTextExtent(pCombo->getDropList()->getListboxItemFromIndex(0)->getText());
for (int i=0; i< (int)pCombo->getItemCount(); i++)
{
int actualTextPix = (int)font->getTextExtent(pCombo->getDropList()->getListboxItemFromIndex(i)->getText());
if (actualTextPix > longestTextPix)
longestTextPix = actualTextPix;
}
longestTextPix += correctionHor + correctionScrollbar;
char buff[10];
if (longestTextPix > maxWidth)
{
itoa(maxWidth, buff, 10);
pCombo->setProperty("DropListWidth",buff);

//and set height because of Horz. scrollbar
int actuallHeight = (int)pCombo->getPixelSize().d_height;
correctionScrollbar = correctionVer*3;
pCombo->setHeight(UDim(0,actuallHeight + correctionScrollbar));
}
else if (longestTextPix > minWidth)
{
itoa(longestTextPix, buff, 10);
pCombo->setProperty("DropListWidth",buff);
}
else
{
itoa(minWidth, buff, 10);
pCombo->setProperty("DropListWidth",buff);
}
}
pCombo->setShowHorzScrollbar(false);
pCombo->setShowVertScrollbar(false);
pCombo->setAlwaysOnTop(true);
}

Return to “Help”

Who is online

Users browsing this forum: No registered users and 30 guests