menu: fix item height calculation

The height of the description was never 0. Switching to std::string
makes handling easier. Locales are secondary because only strings
come out at the end.


Origin commit data
------------------
Commit: 76d5c0c1be
Author: Thilo Graf <dbt@novatux.de>
Date: 2022-04-07 (Thu, 07 Apr 2022)
This commit is contained in:
2022-04-07 21:57:08 +02:00
committed by vanhofen
parent 6feedf69f2
commit d0fa82c005
2 changed files with 19 additions and 23 deletions

View File

@@ -83,7 +83,6 @@ CMenuItem::CMenuItem(bool Active, neutrino_msg_t DirectKey, const char * const I
hint = NONEXISTANT_LOCALE; hint = NONEXISTANT_LOCALE;
name = NONEXISTANT_LOCALE; name = NONEXISTANT_LOCALE;
nameString = ""; nameString = "";
desc = NONEXISTANT_LOCALE;
descString = ""; descString = "";
marked = false; marked = false;
inert = false; inert = false;
@@ -230,7 +229,7 @@ void CMenuItem::paintItemCaption(const bool select_mode, const char * right_text
{ {
int item_height = height; int item_height = height;
const char *left_text = getName(); const char *left_text = getName();
const char *desc_text = getDescription(); std::string desc_text = getDescription();
if (select_mode) if (select_mode)
{ {
@@ -269,7 +268,7 @@ void CMenuItem::paintItemCaption(const bool select_mode, const char * right_text
} }
int desc_height = 0; int desc_height = 0;
if (desc_text && *desc_text) if (!desc_text.empty())
desc_height = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_HINT]->getHeight(); desc_height = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_HINT]->getHeight();
if (*left_text) if (*left_text)
@@ -308,7 +307,7 @@ void CMenuItem::paintItemCaption(const bool select_mode, const char * right_text
has_option_icon = false; has_option_icon = false;
} }
} }
if (desc_text && *desc_text) if (!desc_text.empty())
g_Font[SNeutrinoSettings::FONT_TYPE_MENU_HINT]->RenderString(name_start_x + OFFSET_INNER_MID, y+ item_height, _dx- OFFSET_INNER_MID - (name_start_x - x), desc_text, item_color); g_Font[SNeutrinoSettings::FONT_TYPE_MENU_HINT]->RenderString(name_start_x + OFFSET_INNER_MID, y+ item_height, _dx- OFFSET_INNER_MID - (name_start_x - x), desc_text, item_color);
} }
@@ -533,30 +532,28 @@ const char *CMenuItem::getName(void)
return nameString.c_str(); return nameString.c_str();
} }
void CMenuItem::setDescription(const std::string& t) void CMenuItem::setDescription(const std::string& text)
{ {
desc = NONEXISTANT_LOCALE; descString = text;
descString = t;
getHeight(); getHeight();
} }
void CMenuItem::setDescription(const neutrino_locale_t t) void CMenuItem::setDescription(const neutrino_locale_t locale_text)
{ {
desc = t;
descString = ""; descString = "";
if (locale_text != NONEXISTANT_LOCALE)
descString = g_Locale->getText(locale_text);
getHeight(); getHeight();
} }
const char *CMenuItem::getDescription(void) std::string CMenuItem::getDescription(void)
{ {
if (desc != NONEXISTANT_LOCALE) return descString;
return g_Locale->getText(desc);
return descString.c_str();
} }
int CMenuItem::getDescriptionHeight(void) int CMenuItem::getDescriptionHeight(void)
{ {
if (*getDescription()) if (!getDescription().empty())
return g_Font[SNeutrinoSettings::FONT_TYPE_MENU_HINT]->getHeight(); return g_Font[SNeutrinoSettings::FONT_TYPE_MENU_HINT]->getHeight();
return 0; return 0;
} }
@@ -1941,8 +1938,8 @@ int CMenuOptionNumberChooser::getWidth(void)
width += OFFSET_INNER_MID; /* min 10 pixels between option name and value. enough? */ width += OFFSET_INNER_MID; /* min 10 pixels between option name and value. enough? */
const char *desc_text = getDescription(); std::string desc_text = getDescription();
if (*desc_text) if (!desc_text.empty())
width = std::max(width, OFFSET_INNER_MID + g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth(desc_text)); width = std::max(width, OFFSET_INNER_MID + g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth(desc_text));
return width; return width;
} }
@@ -2228,8 +2225,8 @@ int CMenuOptionChooser::getWidth(void)
} }
width += OFFSET_INNER_MID; /* min 10 pixels between option name and value. enough? */ width += OFFSET_INNER_MID; /* min 10 pixels between option name and value. enough? */
const char *desc_text = getDescription(); std::string desc_text = getDescription();
if (*desc_text) if (!desc_text.empty())
width = std::max(width, OFFSET_INNER_MID + g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth(desc_text)); width = std::max(width, OFFSET_INNER_MID + g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth(desc_text));
return width; return width;
} }
@@ -2435,8 +2432,8 @@ int CMenuForwarder::getWidth(void)
else if (bgcol) else if (bgcol)
tw += OFFSET_INNER_MID + CFrameBuffer::getInstance()->scale2Res(60); tw += OFFSET_INNER_MID + CFrameBuffer::getInstance()->scale2Res(60);
const char *desc_text = getDescription(); std::string desc_text = getDescription();
if (*desc_text) if (!desc_text.empty())
tw = std::max(tw, OFFSET_INNER_MID + g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth(desc_text)); tw = std::max(tw, OFFSET_INNER_MID + g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth(desc_text));
return tw; return tw;
} }

View File

@@ -127,7 +127,6 @@ class CMenuItem : public CComponentsSignals
std::string luaId; std::string luaId;
neutrino_locale_t name; neutrino_locale_t name;
std::string nameString; std::string nameString;
neutrino_locale_t desc;
std::string descString; std::string descString;
CActivateObserver * actObserv; CActivateObserver * actObserv;
@@ -198,9 +197,9 @@ class CMenuItem : public CComponentsSignals
virtual void setName(const std::string& text); virtual void setName(const std::string& text);
virtual void setName(const neutrino_locale_t text); virtual void setName(const neutrino_locale_t text);
sigc::signal<void> OnPaintItem; sigc::signal<void> OnPaintItem;
virtual const char *getDescription(); virtual std::string getDescription();
virtual void setDescription(const std::string& text); virtual void setDescription(const std::string& text);
virtual void setDescription(const neutrino_locale_t text); virtual void setDescription(const neutrino_locale_t locale_text);
virtual int getDescriptionHeight(void); virtual int getDescriptionHeight(void);
void setActivateObserver(CActivateObserver * Observ) { actObserv = Observ; } void setActivateObserver(CActivateObserver * Observ) { actObserv = Observ; }
void activateNotify(void); void activateNotify(void);