CComponentsFooter: expand button label structs

Allows assigning of result, msg and alias values with label struct.

NOTE: Old button label struct are compatible but limited only and
not recommended for usage!
Old parameters 'struct button_label' doesn't provide newer parameters.
Missing parameters are filled with default values and must be assigned
afterward, if required.


Origin commit data
------------------
Branch: ni/coolstream
Commit: 5ae495716e
Author: Thilo Graf <dbt@novatux.de>
Date: 2014-08-26 (Tue, 26 Aug 2014)



------------------
This commit was generated by Migit
This commit is contained in:
2014-08-26 23:05:49 +02:00
committed by [CST] Focus
parent e957c94172
commit 7ee49b7798
2 changed files with 55 additions and 11 deletions

View File

@@ -141,6 +141,9 @@ void CComponentsFooter::setButtonLabels(const struct button_label_s * const cont
CComponentsButton *btn = new CComponentsButton(0, CC_CENTERED, w_btn_min, height-height/4, txt, btn_name); CComponentsButton *btn = new CComponentsButton(0, CC_CENTERED, w_btn_min, height-height/4, txt, btn_name);
btn->setButtonFont(ccf_btn_font); btn->setButtonFont(ccf_btn_font);
btn->doPaintBg(btn_contour); btn->doPaintBg(btn_contour);
btn->setButtonEventMsg(content[i].btn_msg);
btn->setButtonResult(content[i].btn_result);
btn->setButtonAlias(content[i].btn_alias);
if (btn_name == NEUTRINO_ICON_BUTTON_RED) if (btn_name == NEUTRINO_ICON_BUTTON_RED)
btn->setColorFrame(COL_DARK_RED); btn->setColorFrame(COL_DARK_RED);
@@ -187,6 +190,9 @@ void CComponentsFooter::setButtonLabels(const struct button_label_l * const cont
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].text = content[i].locale != NONEXISTANT_LOCALE ? g_Locale->getText(content[i].locale) : ""; buttons[i].text = content[i].locale != NONEXISTANT_LOCALE ? g_Locale->getText(content[i].locale) : "";
buttons[i].btn_msg = content[i].btn_msg;
buttons[i].btn_result = content[i].btn_result;
buttons[i].btn_alias = content[i].btn_alias;
} }
setButtonLabels(buttons, label_count, chain_width, label_width); setButtonLabels(buttons, label_count, chain_width, label_width);
@@ -194,7 +200,18 @@ void CComponentsFooter::setButtonLabels(const struct button_label_l * const cont
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)
{ {
setButtonLabels((button_label_l*)content, label_count, chain_width, label_width); //conversion for compatibility with older paintButtons() methode, find in /gui/widget/buttons.h
button_label_l buttons[label_count];
for (size_t i = 0; i< label_count; i++){
buttons[i].button = content[i].button;
buttons[i].locale = content[i].locale;
//NOTE: here are used default values, because old button label struct don't know about this,
//if it possible, don't use this methode!
buttons[i].btn_msg = CRCInput::RC_nokey;
buttons[i].btn_result = -1;
buttons[i].btn_alias = -1;
}
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_l>v_content, const int& chain_width, const int& label_width)
@@ -205,6 +222,9 @@ void CComponentsFooter::setButtonLabels(const vector<button_label_l>v_content, c
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].locale = v_content[i].locale; buttons[i].locale = v_content[i].locale;
buttons[i].btn_msg = v_content[i].btn_msg;
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); setButtonLabels(buttons, label_count, chain_width, label_width);
@@ -218,26 +238,32 @@ void CComponentsFooter::setButtonLabels(const vector<button_label_s>v_content, c
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].btn_msg = v_content[i].btn_msg;
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); setButtonLabels(buttons, label_count, chain_width, label_width);
} }
void CComponentsFooter::setButtonLabel(const char *button_icon, const std::string& text, const int& chain_width, const int& label_width) void CComponentsFooter::setButtonLabel(const char *button_icon, const std::string& text, const int& chain_width, const int& label_width, const neutrino_msg_t& msg, const int& result_value, const int& alias_value)
{ {
button_label_s button[1]; button_label_s button[1];
button[0].button = button_icon; button[0].button = button_icon;
button[0].text = text; button[0].text = text;
button[0].btn_msg = msg;
button[0].btn_result = result_value;
button[0].btn_alias = alias_value;
setButtonLabels(button, 1, chain_width, label_width); setButtonLabels(button, 1, chain_width, label_width);
} }
void CComponentsFooter::setButtonLabel(const char *button_icon, const neutrino_locale_t& locale, const int& chain_width, const int& label_width) void CComponentsFooter::setButtonLabel(const char *button_icon, const neutrino_locale_t& locale, const int& chain_width, const int& label_width, const neutrino_msg_t& msg, const int& result_value, const int& alias_value)
{ {
string txt = locale != NONEXISTANT_LOCALE ? g_Locale->getText(locale) : ""; string txt = locale != NONEXISTANT_LOCALE ? g_Locale->getText(locale) : "";
setButtonLabel(button_icon, txt, chain_width, label_width); setButtonLabel(button_icon, txt, chain_width, label_width, msg, result_value, alias_value);
} }
void CComponentsFooter::showButtonContour(bool show) void CComponentsFooter::showButtonContour(bool show)
@@ -264,6 +290,12 @@ int CComponentsFooter::getSelectedButton()
return ret; return ret;
} }
CComponentsButton* CComponentsFooter::getSelectedButtonObject()
{
CComponentsButton* ret = static_cast<CComponentsButton*>(chain->getSelectedItemObject());
return ret;
}
void CComponentsFooter::paintButtons(const int& x_pos, void CComponentsFooter::paintButtons(const int& x_pos,
const int& y_pos, const int& y_pos,

View File

@@ -24,7 +24,6 @@
#ifndef __CC_FORM_FOOTER_H__ #ifndef __CC_FORM_FOOTER_H__
#define __CC_FORM_FOOTER_H__ #define __CC_FORM_FOOTER_H__
#include "cc_frm_header.h" #include "cc_frm_header.h"
#include "cc_frm_button.h" #include "cc_frm_button.h"
#include <gui/widget/buttons.h> //for compatibility with 'button_label' type #include <gui/widget/buttons.h> //for compatibility with 'button_label' type
@@ -34,17 +33,28 @@ typedef struct button_label_s
{ {
const char * button; const char * button;
std::string text; std::string text;
neutrino_msg_t btn_msg;
int btn_result;
int btn_alias;
} button_label_s_struct; } button_label_s_struct;
typedef struct button_label_l typedef struct button_label_l
{ {
const char * button; const char * button;
neutrino_locale_t locale; neutrino_locale_t locale;
neutrino_msg_t btn_msg;
int btn_result;
int btn_alias;
} button_label_l_struct; } button_label_l_struct;
/*! /*!
CComponentsFooter, sub class of CComponentsHeader provides prepared container for footer CComponentsFooter, sub class of CComponentsHeader provides prepared container for footer
Is mostly usable like a header but without caption, and context button icons. It's usable like a header but without caption, and context button icons as default.
Additional implemented is a button container (chain) and some methods which can add
buttons via struct, vector or text and icon parameters. Also a compatible but limited methode
to add button labels known by older button handler, to find in gui/widget/buttons.h/cpp.
functionality. Why limited ?: old parameter 'struct button_label' doesn't provide newer parameters.
Missing parameters are filled with default values and must be assigned afterward, if required.
*/ */
class CComponentsFooter : public CComponentsHeader class CComponentsFooter : public CComponentsHeader
{ {
@@ -86,13 +96,13 @@ class CComponentsFooter : public CComponentsHeader
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_s>v_content, const int& chain_width, const int& label_width);
///add button labels with old label type, count as size_t, chain_width as int, label width as int ///add button labels with old label type, count as size_t, chain_width as int, label width as int
///NOTE: for compatibility with older button handler find in gui/widget/buttons.h ///NOTE: for compatibility with older button handler find in gui/widget/buttons.h, if possible, don't use this
void setButtonLabels(const struct button_label * const content, const size_t& label_count, const int& chain_width = 0, const int& label_width = 0); void setButtonLabels(const struct button_label * const content, const size_t& label_count, const int& chain_width = 0, const int& label_width = 0);
///add single button label with string label type as content, chain_width as int, label width as int ///add single button label with string label type as content, chain_width as int, label width as int
void setButtonLabel(const char *button_icon, const std::string& text, const int& chain_width = 0, const int& label_width = 0); void setButtonLabel(const char *button_icon, const std::string& text, const int& chain_width = 0, const int& label_width = 0, const neutrino_msg_t& msg = CRCInput::RC_nokey, const int& result_value = -1, const int& alias_value = -1);
///add single button label with locale label type as content, chain_width as int, label width as int ///add single button label with locale label type as content, chain_width as int, label width as int
void setButtonLabel(const char *button_icon, const neutrino_locale_t& locale, const int& chain_width = 0, const int& label_width = 0); void setButtonLabel(const char *button_icon, const neutrino_locale_t& locale, const int& chain_width = 0, const int& label_width = 0, const neutrino_msg_t& msg = CRCInput::RC_nokey, const int& result_value = -1, const int& alias_value = -1);
///causes show/hide countour of button frame and background, parameter bool show, default= true ///causes show/hide countour of button frame and background, parameter bool show, default= true
void showButtonContour(bool show = true); void showButtonContour(bool show = true);
@@ -101,6 +111,8 @@ class CComponentsFooter : public CComponentsHeader
void setSelectedButton(size_t item_id); void setSelectedButton(size_t item_id);
///returns id of select button, return value as int, -1 = nothing is selected ///returns id of select button, return value as int, -1 = nothing is selected
int getSelectedButton(); int getSelectedButton();
///returns selected button object, return value as pointer to object, NULL means nothing is selected
CComponentsButton* getSelectedButtonObject();
///property: set font for label caption, parameter as font object, value NULL causes usage of dynamic font ///property: set font for label caption, parameter as font object, value NULL causes usage of dynamic font
void setButtonFont(Font* font){ccf_btn_font = font;}; void setButtonFont(Font* font){ccf_btn_font = font;};