mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-27 15:32:59 +02:00
neutrino: let menus resize to the needed dimension
Instead of letting the caller of the menuewidget specify the dimensions, determine them based on the text that is to be displayed. git-svn-id: file:///home/bas/coolstream_public_svn/THIRDPARTY/applications/neutrino-experimental@226 e54a6e83-5905-42d5-8d5c-058d10e6a962
This commit is contained in:
@@ -100,16 +100,18 @@ CMenuWidget::CMenuWidget(const char* Name, const std::string & Icon, const int m
|
|||||||
Init(Icon, mwidth, mheight);
|
Init(Icon, mwidth, mheight);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMenuWidget::Init(const std::string & Icon, const int mwidth, const int mheight)
|
void CMenuWidget::Init(const std::string & Icon, const int /*mwidth*/, const int /*mheight*/)
|
||||||
{
|
{
|
||||||
frameBuffer = CFrameBuffer::getInstance();
|
frameBuffer = CFrameBuffer::getInstance();
|
||||||
iconfile = Icon;
|
iconfile = Icon;
|
||||||
selected = -1;
|
selected = -1;
|
||||||
width = mwidth;
|
needed_width = 0; /* is set in addItem() */
|
||||||
if(width > (int) frameBuffer->getScreenWidth())
|
width = 0; /* is set in paint() */
|
||||||
width = frameBuffer->getScreenWidth();
|
|
||||||
height = mheight;
|
/* set the max height to 9/10 of usable screen height
|
||||||
wanted_height=mheight;
|
debatable, if the callers need a possibility to set this */
|
||||||
|
height = frameBuffer->getScreenHeight() / 20 * 18; /* make sure its a multiple of 2 */
|
||||||
|
wanted_height = height;
|
||||||
current_page=0;
|
current_page=0;
|
||||||
offx = offy = 0;
|
offx = offy = 0;
|
||||||
}
|
}
|
||||||
@@ -137,6 +139,11 @@ void CMenuWidget::addItem(CMenuItem* menuItem, const bool defaultselected)
|
|||||||
{
|
{
|
||||||
if (defaultselected)
|
if (defaultselected)
|
||||||
selected = items.size();
|
selected = items.size();
|
||||||
|
int tmpw = menuItem->getWidth() + 10 + 10; /* 10 pixels to the left and right of the text */
|
||||||
|
if (tmpw > needed_width) {
|
||||||
|
//fprintf(stderr, "CMenuWidget::addItem: increase width from %d to %d '%s' offx: %d\n", needed_width, tmpw, menuItem->iconName.c_str(), offx);
|
||||||
|
needed_width = tmpw;
|
||||||
|
}
|
||||||
items.push_back(menuItem);
|
items.push_back(menuItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -439,6 +446,7 @@ void CMenuWidget::paint()
|
|||||||
CVFD::getInstance()->setMode(CVFD::MODE_MENU_UTF8 /*, l_name*/); //FIXME menu name
|
CVFD::getInstance()->setMode(CVFD::MODE_MENU_UTF8 /*, l_name*/); //FIXME menu name
|
||||||
|
|
||||||
height=wanted_height;
|
height=wanted_height;
|
||||||
|
width = needed_width;
|
||||||
|
|
||||||
if(height > ((int)frameBuffer->getScreenHeight() - 10))
|
if(height > ((int)frameBuffer->getScreenHeight() - 10))
|
||||||
height = frameBuffer->getScreenHeight() - 10;
|
height = frameBuffer->getScreenHeight() - 10;
|
||||||
@@ -446,8 +454,6 @@ void CMenuWidget::paint()
|
|||||||
int neededWidth = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE]->getRenderWidth(l_name, true); // UTF-8
|
int neededWidth = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE]->getRenderWidth(l_name, true); // UTF-8
|
||||||
if (neededWidth > width-48) {
|
if (neededWidth > width-48) {
|
||||||
width= neededWidth+ 49;
|
width= neededWidth+ 49;
|
||||||
if(width > (int)frameBuffer->getScreenWidth())
|
|
||||||
width = frameBuffer->getScreenWidth();
|
|
||||||
}
|
}
|
||||||
int hheight = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE]->getHeight();
|
int hheight = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE]->getHeight();
|
||||||
int itemHeightTotal=0;
|
int itemHeightTotal=0;
|
||||||
@@ -475,6 +481,9 @@ void CMenuWidget::paint()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
width += iconOffset;
|
||||||
|
if (width > (int)frameBuffer->getScreenWidth())
|
||||||
|
width = frameBuffer->getScreenWidth();
|
||||||
|
|
||||||
// shrink menu if less items
|
// shrink menu if less items
|
||||||
if(hheight+itemHeightTotal < height)
|
if(hheight+itemHeightTotal < height)
|
||||||
@@ -877,6 +886,27 @@ int CMenuOptionChooser::paint( bool selected , bool last)
|
|||||||
return y+height;
|
return y+height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int CMenuOptionChooser::getWidth(void) const
|
||||||
|
{
|
||||||
|
int ow = 0;
|
||||||
|
int tw = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth(optionNameString, true);
|
||||||
|
int width = tw;
|
||||||
|
|
||||||
|
for(unsigned int count = 0; count < options.size(); count++) {
|
||||||
|
ow = 0;
|
||||||
|
if (options[count].valname)
|
||||||
|
ow = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]
|
||||||
|
->getRenderWidth(options[count].valname, true);
|
||||||
|
else
|
||||||
|
ow = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]
|
||||||
|
->getRenderWidth(g_Locale->getText(options[count].value), true);
|
||||||
|
|
||||||
|
if (tw + ow > width)
|
||||||
|
width = tw + ow;
|
||||||
|
}
|
||||||
|
|
||||||
|
return width + 10; /* min 10 pixels between option name and value. enough? */
|
||||||
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@@ -264,6 +264,7 @@ class CMenuOptionChooser : public CAbstractMenuOptionChooser
|
|||||||
|
|
||||||
void setOptionValue(const int newvalue);
|
void setOptionValue(const int newvalue);
|
||||||
int getOptionValue(void) const;
|
int getOptionValue(void) const;
|
||||||
|
int getWidth(void) const;
|
||||||
|
|
||||||
int paint(bool selected, bool last = 0);
|
int paint(bool selected, bool last = 0);
|
||||||
|
|
||||||
@@ -332,6 +333,7 @@ class CMenuWidget : public CMenuTarget
|
|||||||
std::vector<unsigned int> page_start;
|
std::vector<unsigned int> page_start;
|
||||||
std::string iconfile;
|
std::string iconfile;
|
||||||
|
|
||||||
|
int needed_width;
|
||||||
int width;
|
int width;
|
||||||
int height;
|
int height;
|
||||||
int wanted_height;
|
int wanted_height;
|
||||||
@@ -349,6 +351,7 @@ class CMenuWidget : public CMenuTarget
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
CMenuWidget();
|
CMenuWidget();
|
||||||
|
/* TODO: mwidth and mheight are not used anymore. remove if nobody misses them */
|
||||||
CMenuWidget(const char* Name, const std::string & Icon = "", const int mwidth = 400, const int mheight = 576);
|
CMenuWidget(const char* Name, const std::string & Icon = "", const int mwidth = 400, const int mheight = 576);
|
||||||
CMenuWidget(const neutrino_locale_t Name, const std::string & Icon = "", const int mwidth = 400, const int mheight = 576);
|
CMenuWidget(const neutrino_locale_t Name, const std::string & Icon = "", const int mwidth = 400, const int mheight = 576);
|
||||||
~CMenuWidget();
|
~CMenuWidget();
|
||||||
|
Reference in New Issue
Block a user