CComponentsFooter: simplify implementation of button labels

button_label_l and button_label_s are now
merged to button_label_cc with prepared default values for text and locales.This type contains all possible
button label properties. Values for locales and string
are evaluated in setButtonLabels(), so it's possible to remove some
overloaded methodes.
This commit is contained in:
2017-03-11 00:45:25 +01:00
parent ccb82083e2
commit c766a970dc
4 changed files with 23 additions and 67 deletions

View File

@@ -3,7 +3,7 @@
Copyright (C) 2001 by Steffen Hehn 'McClean' Copyright (C) 2001 by Steffen Hehn 'McClean'
Classes for generic GUI-related components. Classes for generic GUI-related components.
Copyright (C) 2013-2014, Thilo Graf 'dbt' Copyright (C) 2013-2017, Thilo Graf 'dbt'
License: GPL License: GPL
@@ -102,7 +102,7 @@ void CComponentsFooter::initVarFooter( const int& x_pos, const int& y_pos, const
initParent(parent); initParent(parent);
} }
void CComponentsFooter::setButtonLabels(const struct button_label_s * const content, const size_t& label_count, const int& chain_width, const int& label_width) void CComponentsFooter::setButtonLabels(const struct button_label_cc * const content, const size_t& label_count, const int& chain_width, const int& label_width)
{ {
/* clean up before init*/ /* clean up before init*/
if (chain) if (chain)
@@ -178,7 +178,7 @@ void CComponentsFooter::setButtonLabels(const struct button_label_s * const cont
vector<CComponentsItem*> v_btns; vector<CComponentsItem*> v_btns;
int h_btn = /*(ccf_enable_button_bg ? */chain->getHeight()-2*fr_thickness/*-OFFSET_INNER_SMALL*//* : height)*/-ccf_button_shadow_width; int h_btn = /*(ccf_enable_button_bg ? */chain->getHeight()-2*fr_thickness/*-OFFSET_INNER_SMALL*//* : height)*/-ccf_button_shadow_width;
for (size_t i= 0; i< label_count; i++){ for (size_t i= 0; i< label_count; i++){
string txt = content[i].text; string txt = content[i].locale == NONEXISTANT_LOCALE ? content[i].text : g_Locale->getText(content[i].locale);
string icon_name = string(content[i].button); string icon_name = string(content[i].button);
//ignore item, if no text and icon are defined; //ignore item, if no text and icon are defined;
@@ -244,26 +244,10 @@ void CComponentsFooter::setButtonLabels(const struct button_label_s * const cont
} }
} }
void CComponentsFooter::setButtonLabels(const struct button_label_l * const content, const size_t& label_count, const int& chain_width, const int& label_width)
{
button_label_s buttons[label_count];
for (size_t i= 0; i< label_count; i++){
buttons[i].button = content[i].button;
buttons[i].text = content[i].locale != NONEXISTANT_LOCALE ? g_Locale->getText(content[i].locale) : "";
buttons[i].directKey = content[i].directKey;
buttons[i].directKeyAlt = content[i].directKeyAlt;
buttons[i].btn_result = content[i].btn_result;
buttons[i].btn_alias = content[i].btn_alias;
}
setButtonLabels(buttons, label_count, chain_width, label_width);
}
void CComponentsFooter::setButtonLabels(const struct button_label * const content, const size_t& label_count, const int& chain_width, const int& label_width) void CComponentsFooter::setButtonLabels(const struct button_label * const content, const size_t& label_count, const int& chain_width, const int& label_width)
{ {
//conversion for compatibility with older paintButtons() methode, find in /gui/widget/buttons.h //conversion for compatibility with older paintButtons() methode, find in /gui/widget/buttons.h
button_label_l buttons[label_count]; button_label_cc buttons[label_count];
for (size_t i = 0; i< label_count; i++){ for (size_t i = 0; i< label_count; i++){
buttons[i].button = content[i].button; buttons[i].button = content[i].button;
buttons[i].locale = content[i].locale; buttons[i].locale = content[i].locale;
@@ -276,31 +260,15 @@ void CComponentsFooter::setButtonLabels(const struct button_label * const conten
setButtonLabels(buttons, label_count, chain_width, label_width); setButtonLabels(buttons, label_count, chain_width, label_width);
} }
void CComponentsFooter::setButtonLabels(const vector<button_label_l> &v_content, const int& chain_width, const int& label_width) void CComponentsFooter::setButtonLabels(const vector<button_label_cc> &v_content, const int& chain_width, const int& label_width)
{ {
size_t label_count = v_content.size(); size_t label_count = v_content.size();
button_label_l buttons[label_count]; button_label_cc buttons[label_count];
for (size_t i= 0; i< label_count; i++){
buttons[i].button = v_content[i].button;
buttons[i].locale = v_content[i].locale;
buttons[i].directKey = v_content[i].directKey;
buttons[i].directKeyAlt = v_content[i].directKeyAlt;
buttons[i].btn_result = v_content[i].btn_result;
buttons[i].btn_alias = v_content[i].btn_alias;
}
setButtonLabels(buttons, label_count, chain_width, label_width);
}
void CComponentsFooter::setButtonLabels(const vector<button_label_s> &v_content, const int& chain_width, const int& label_width)
{
size_t label_count = v_content.size();
button_label_s buttons[label_count];
for (size_t i= 0; i< label_count; i++){ for (size_t i= 0; i< label_count; i++){
buttons[i].button = v_content[i].button; buttons[i].button = v_content[i].button;
buttons[i].text = v_content[i].text; buttons[i].text = v_content[i].text;
buttons[i].locale = v_content[i].locale;
buttons[i].directKey = v_content[i].directKey; buttons[i].directKey = v_content[i].directKey;
buttons[i].directKeyAlt = v_content[i].directKeyAlt; buttons[i].directKeyAlt = v_content[i].directKeyAlt;
buttons[i].btn_result = v_content[i].btn_result; buttons[i].btn_result = v_content[i].btn_result;
@@ -319,7 +287,7 @@ void CComponentsFooter::setButtonLabel( const char *button_icon,
const int& alias_value, const int& alias_value,
const neutrino_msg_t& directKeyAlt) const neutrino_msg_t& directKeyAlt)
{ {
button_label_s button[1]; button_label_cc button[1];
button[0].button = button_icon; button[0].button = button_icon;
button[0].text = text; button[0].text = text;

View File

@@ -3,7 +3,7 @@
Copyright (C) 2001 by Steffen Hehn 'McClean' Copyright (C) 2001 by Steffen Hehn 'McClean'
Classes for generic GUI-related components. Classes for generic GUI-related components.
Copyright (C) 2012, 2013, 2014, Thilo Graf 'dbt' Copyright (C) 2012-2017, Thilo Graf 'dbt'
License: GPL License: GPL
@@ -30,25 +30,17 @@
#include <gui/widget/buttons.h> //for compatibility with 'button_label' type #include <gui/widget/buttons.h> //for compatibility with 'button_label' type
//for 'button_label' type with string //for 'button_label' type with string
typedef struct button_label_s typedef struct button_label_cc
{ {
const char * button; const char * button;
std::string text; std::string text;
neutrino_locale_t locale;
neutrino_msg_t directKey; neutrino_msg_t directKey;
neutrino_msg_t directKeyAlt; neutrino_msg_t directKeyAlt;
int btn_result; int btn_result;
int btn_alias; int btn_alias;
} button_label_s_struct; button_label_cc(): text(std::string()), locale(NONEXISTANT_LOCALE){}
} button_label_cc_struct;
typedef struct button_label_l
{
const char * button;
neutrino_locale_t locale;
neutrino_msg_t directKey;
neutrino_msg_t directKeyAlt;
int btn_result;
int btn_alias;
} button_label_l_struct;
/*! /*!
CComponentsFooter, sub class of CComponentsHeader provides prepared container for footer CComponentsFooter, sub class of CComponentsHeader provides prepared container for footer
@@ -101,13 +93,9 @@ class CComponentsFooter : public CComponentsHeader
fb_pixel_t color_shadow = COL_SHADOW_PLUS_0); fb_pixel_t color_shadow = COL_SHADOW_PLUS_0);
///add button labels with string label type as content, count as size_t, chain_width as int, label width as int ///add button labels with string label type as content, count as size_t, chain_width as int, label width as int
void setButtonLabels(const struct button_label_s * const content, const size_t& label_count, const int& chain_width = 0, const int& label_width = 0); void setButtonLabels(const struct button_label_cc * const content, const size_t& label_count, const int& chain_width = 0, const int& label_width = 0);
///add button labels with locale label type as content, count as size_t, chain_width as int, label width as int
void setButtonLabels(const struct button_label_l * const content, const size_t& label_count, const int& chain_width = 0, const int& label_width = 0);
///add button labels with locale label type as content, parameter 1 as vector, chain_width as int, label width as int
void setButtonLabels(const std::vector<button_label_l> &v_content, const int& chain_width, const int& label_width);
///add button labels with string label type as content, parameter 1 as vector, chain_width as int, label width as int ///add button labels with string label type as content, parameter 1 as vector, chain_width as int, label width as int
void setButtonLabels(const std::vector<button_label_s> &v_content, const int& chain_width, const int& label_width); void setButtonLabels(const std::vector<button_label_cc> &v_content, const int& chain_width, const int& label_width);
///enable/disable button frame in icon color, predefined for red, green, yellow and blue ///enable/disable button frame in icon color, predefined for red, green, yellow and blue
inline void enableButtonFrameColor(bool enable = true){btn_auto_frame_col = enable;} inline void enableButtonFrameColor(bool enable = true){btn_auto_frame_col = enable;}

View File

@@ -139,27 +139,27 @@ int CLuaInstCCWindow::CCWindowNew(lua_State *L)
else { else {
CComponentsFooter* footer = (*udata)->w->getFooterObject(); CComponentsFooter* footer = (*udata)->w->getFooterObject();
if (footer) { if (footer) {
vector<button_label_s> buttons; vector<button_label_cc> buttons;
if (!btnRed.empty()) { if (!btnRed.empty()) {
button_label_s btnSred; button_label_cc btnSred;
btnSred.button = NEUTRINO_ICON_BUTTON_RED; btnSred.button = NEUTRINO_ICON_BUTTON_RED;
btnSred.text = btnRed; btnSred.text = btnRed;
buttons.push_back(btnSred); buttons.push_back(btnSred);
} }
if (!btnGreen.empty()) { if (!btnGreen.empty()) {
button_label_s btnSgreen; button_label_cc btnSgreen;
btnSgreen.button = NEUTRINO_ICON_BUTTON_GREEN; btnSgreen.button = NEUTRINO_ICON_BUTTON_GREEN;
btnSgreen.text = btnGreen; btnSgreen.text = btnGreen;
buttons.push_back(btnSgreen); buttons.push_back(btnSgreen);
} }
if (!btnYellow.empty()) { if (!btnYellow.empty()) {
button_label_s btnSyellow; button_label_cc btnSyellow;
btnSyellow.button = NEUTRINO_ICON_BUTTON_YELLOW; btnSyellow.button = NEUTRINO_ICON_BUTTON_YELLOW;
btnSyellow.text = btnYellow; btnSyellow.text = btnYellow;
buttons.push_back(btnSyellow); buttons.push_back(btnSyellow);
} }
if (!btnBlue.empty()) { if (!btnBlue.empty()) {
button_label_s btnSblue; button_label_cc btnSblue;
btnSblue.button = NEUTRINO_ICON_BUTTON_BLUE; btnSblue.button = NEUTRINO_ICON_BUTTON_BLUE;
btnSblue.text = btnBlue; btnSblue.text = btnBlue;
buttons.push_back(btnSblue); buttons.push_back(btnSblue);

View File

@@ -7,7 +7,7 @@
Günther@tuxbox.berlios.org Günther@tuxbox.berlios.org
Implementation of CComponent Window class. Implementation of CComponent Window class.
Copyright (C) 2014-2016 Thilo Graf 'dbt' Copyright (C) 2014-2017 Thilo Graf 'dbt'
License: GPL License: GPL
@@ -117,8 +117,8 @@ void CMsgBox::initTimeOut()
void CMsgBox::initButtons() void CMsgBox::initButtons()
{ {
button_label_s btn; button_label_cc btn;
vector<button_label_s> v_buttons; vector<button_label_cc> v_buttons;
//evaluate combinations //evaluate combinations
if (mb_show_button & mbAll) if (mb_show_button & mbAll)