From 88c56ba2b0070c20784c6e232f61f8fd0c353636 Mon Sep 17 00:00:00 2001 From: Stefan Seyfried Date: Mon, 8 Feb 2010 20:47:37 +0000 Subject: [PATCH] neutrino: improve menu width calculation calculate menu width in paint() instead of addItem() this allows to cahnge the width of a menu later on dynamically git-svn-id: file:///home/bas/coolstream_public_svn/THIRDPARTY/applications/neutrino-experimental@308 e54a6e83-5905-42d5-8d5c-058d10e6a962 Origin commit data ------------------ Branch: ni/coolstream Commit: https://github.com/neutrino-images/ni-neutrino/commit/292891db1f070a21226d6fe49566ab73d5c4fdb2 Author: Stefan Seyfried Date: 2010-02-08 (Mon, 08 Feb 2010) ------------------ This commit was generated by Migit --- src/gui/widget/menue.cpp | 19 ++++++++++--------- src/gui/widget/menue.h | 2 +- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/gui/widget/menue.cpp b/src/gui/widget/menue.cpp index 5d54a560b..e0a4693a1 100644 --- a/src/gui/widget/menue.cpp +++ b/src/gui/widget/menue.cpp @@ -105,13 +105,13 @@ void CMenuWidget::Init(const std::string & Icon, const int mwidth, const int /*m frameBuffer = CFrameBuffer::getInstance(); iconfile = Icon; selected = -1; - needed_width = 0; /* is set in addItem() */ + min_width = 0; width = 0; /* is set in paint() */ if (mwidth > 100) /* warn about abuse until we found all offenders... */ fprintf(stderr, "CMenuWidget::Init (%s) (%s) mwidth over 100%%: %d\n", nameString.c_str(), Icon.c_str(), mwidth); else - needed_width = frameBuffer->getScreenWidth() * mwidth / 100; + min_width = frameBuffer->getScreenWidth() * mwidth / 100; /* set the max height to 9/10 of usable screen height debatable, if the callers need a possibility to set this */ @@ -144,11 +144,6 @@ void CMenuWidget::addItem(CMenuItem* menuItem, const bool defaultselected) { if (defaultselected) 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); } @@ -449,8 +444,14 @@ void CMenuWidget::paint() CVFD::getInstance()->setMode(CVFD::MODE_MENU_UTF8 /*, l_name*/); //FIXME menu name - height=wanted_height; - width = needed_width; + height = wanted_height; + width = min_width; + + for (unsigned int i= 0; i< items.size(); i++) { + int tmpw = items[i]->getWidth() + 10 + 10; /* 10 pixels to the left and right of the text */ + if (tmpw > width) + width = tmpw; + } if(height > ((int)frameBuffer->getScreenHeight() - 10)) height = frameBuffer->getScreenHeight() - 10; diff --git a/src/gui/widget/menue.h b/src/gui/widget/menue.h index 466da1126..6c7e0dc02 100644 --- a/src/gui/widget/menue.h +++ b/src/gui/widget/menue.h @@ -331,7 +331,7 @@ class CMenuWidget : public CMenuTarget std::vector page_start; std::string iconfile; - int needed_width; + int min_width; int width; int height; int wanted_height;