mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-28 16:01:20 +02:00
CComponentsFooter: add functionality to add button labels via struct
This function uses struct label like old button label function see /gui/widget/buttons.cpp, but can also use strings in structs also possible: add single button with text or locale
This commit is contained in:
@@ -63,7 +63,7 @@ void CComponentsFooter::initVarFooter( const int& x_pos, const int& y_pos, const
|
|||||||
|
|
||||||
x = x_pos;
|
x = x_pos;
|
||||||
y = y_pos;
|
y = y_pos;
|
||||||
|
|
||||||
//init footer width
|
//init footer width
|
||||||
width = w == 0 ? frameBuffer->getScreenWidth(true) : w;
|
width = w == 0 ? frameBuffer->getScreenWidth(true) : w;
|
||||||
//init header height
|
//init header height
|
||||||
@@ -72,16 +72,93 @@ void CComponentsFooter::initVarFooter( const int& x_pos, const int& y_pos, const
|
|||||||
height = h;
|
height = h;
|
||||||
else
|
else
|
||||||
height = cch_font->getHeight();
|
height = cch_font->getHeight();
|
||||||
|
|
||||||
shadow = has_shadow;
|
shadow = has_shadow;
|
||||||
col_frame = color_frame;
|
col_frame = color_frame;
|
||||||
col_body = color_body;
|
col_body = color_body;
|
||||||
col_shadow = color_shadow;
|
col_shadow = color_shadow;
|
||||||
|
|
||||||
corner_rad = RADIUS_LARGE;
|
corner_rad = RADIUS_LARGE;
|
||||||
corner_type = CORNER_BOTTOM;
|
corner_type = CORNER_BOTTOM;
|
||||||
|
|
||||||
|
btn_contour = false;
|
||||||
|
|
||||||
addContextButton(buttons);
|
addContextButton(buttons);
|
||||||
initCCItems();
|
initCCItems();
|
||||||
initParent(parent);
|
initParent(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CComponentsFooter::setButtonLabels(const struct button_label_s * const content, const size_t& label_count, const int& total_width, const int& label_width)
|
||||||
|
{
|
||||||
|
//define required total width of button group, minimal width is >0, sensless values are nonsens!
|
||||||
|
int w_total = total_width > 0 ? total_width : width;//TODO: alow and handle only with rational values >0
|
||||||
|
//consider context button group on the right side of footer, if exist then subtract result from total width of button container
|
||||||
|
if (cch_btn_obj)
|
||||||
|
w_total -= cch_btn_obj->getWidth();
|
||||||
|
|
||||||
|
//calculate required position of button container
|
||||||
|
//consider icon (inherited) width, if exist then set evaluated result as x position for button label container and ...
|
||||||
|
int x_btnchain = 0;
|
||||||
|
if (cch_icon_obj)
|
||||||
|
x_btnchain = (cch_icon_obj->getXPos() + cch_offset + cch_icon_obj->getWidth());
|
||||||
|
//... reduce also total width for button label container
|
||||||
|
w_total -= x_btnchain;
|
||||||
|
|
||||||
|
//initialize a sub form (item chain as button label container): this contains all passed (as interleaved) button label items, with this container we can work within
|
||||||
|
//footer as primary container (in this context '=this') and the parent for the button label container and
|
||||||
|
//button label container itself is concurrent the parent object for button objects
|
||||||
|
CComponentsFrmChain *btnchain = new CComponentsFrmChain(x_btnchain, CC_CENTERED, w_total, height, 0, CC_DIR_X, this);
|
||||||
|
btnchain->doPaintBg(false);
|
||||||
|
|
||||||
|
//calculate matching maximal possible width of button lable within button label container
|
||||||
|
int w_btn_max = btnchain->getWidth() / label_count;
|
||||||
|
int w_btn = min(label_width, w_btn_max);
|
||||||
|
|
||||||
|
//unused size, usable for offset calculation
|
||||||
|
int w_btn_unused = w_total - w_btn * label_count;
|
||||||
|
|
||||||
|
//consider offset of button labels
|
||||||
|
int w_btn_offset = w_btn_unused / (label_count+1);
|
||||||
|
btnchain->setAppendOffset(w_btn_offset, 0);
|
||||||
|
|
||||||
|
//finally generate button objects passed from button label content.
|
||||||
|
for (size_t i= 0; i< label_count; i++){
|
||||||
|
CComponentsButton *btn = new CComponentsButton(CC_APPEND, CC_CENTERED, w_btn, height-height/4, content[i].text, content[i].button);
|
||||||
|
btn->doPaintBg(btn_contour);
|
||||||
|
btnchain->addCCItem(btn);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CComponentsFooter::setButtonLabels(const struct button_label_l * const content, const size_t& label_count, const int& total_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 = g_Locale->getText(content[i].locale);
|
||||||
|
}
|
||||||
|
|
||||||
|
setButtonLabels(buttons, label_count, total_width, label_width);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CComponentsFooter::setButtonLabels(const struct button_label * const content, const size_t& label_count, const int& total_width, const int& label_width)
|
||||||
|
{
|
||||||
|
setButtonLabels((button_label_l*)content, label_count, total_width, label_width);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CComponentsFooter::setButtonLabel(const char *button_icon, const std::string& text, const int& total_width, const int& label_width)
|
||||||
|
{
|
||||||
|
button_label_s button[1];
|
||||||
|
|
||||||
|
button[0].button = button_icon;
|
||||||
|
button[0].text = text;
|
||||||
|
|
||||||
|
setButtonLabels(button, 1, total_width, label_width);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CComponentsFooter::setButtonLabel(const char *button_icon, const neutrino_locale_t& locale, const int& total_width, const int& label_width)
|
||||||
|
{
|
||||||
|
string txt = g_Locale->getText(locale);
|
||||||
|
|
||||||
|
setButtonLabel(button_icon, txt, total_width, label_width);
|
||||||
|
}
|
||||||
|
@@ -26,6 +26,21 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "cc_frm_header.h"
|
#include "cc_frm_header.h"
|
||||||
|
#include "cc_frm_button.h"
|
||||||
|
#include <gui/widget/buttons.h> //for compatibility with 'button_label' type
|
||||||
|
|
||||||
|
//for 'button_label' type with string
|
||||||
|
typedef struct button_label_s
|
||||||
|
{
|
||||||
|
const char * button;
|
||||||
|
std::string text;
|
||||||
|
} button_label_s_struct;
|
||||||
|
|
||||||
|
typedef struct button_label_l
|
||||||
|
{
|
||||||
|
const char * button;
|
||||||
|
neutrino_locale_t locale;
|
||||||
|
} button_label_l_struct;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
CComponentsFooter, sub class of CComponentsHeader provides prepared container for footer
|
CComponentsFooter, sub class of CComponentsHeader provides prepared container for footer
|
||||||
@@ -33,7 +48,7 @@ Is mostly usable like a header but without caption, and context button icons.
|
|||||||
*/
|
*/
|
||||||
class CComponentsFooter : public CComponentsHeader
|
class CComponentsFooter : public CComponentsHeader
|
||||||
{
|
{
|
||||||
protected:
|
private:
|
||||||
void initVarFooter( const int& x_pos, const int& y_pos, const int& w, const int& h = 0,
|
void initVarFooter( const int& x_pos, const int& y_pos, const int& w, const int& h = 0,
|
||||||
const int& buttons = 0,
|
const int& buttons = 0,
|
||||||
CComponentsForm *parent = NULL,
|
CComponentsForm *parent = NULL,
|
||||||
@@ -41,7 +56,12 @@ class CComponentsFooter : public CComponentsHeader
|
|||||||
fb_pixel_t color_frame = COL_MENUCONTENT_PLUS_6,
|
fb_pixel_t color_frame = COL_MENUCONTENT_PLUS_6,
|
||||||
fb_pixel_t color_body = COL_INFOBAR_SHADOW_PLUS_1,
|
fb_pixel_t color_body = COL_INFOBAR_SHADOW_PLUS_1,
|
||||||
fb_pixel_t color_shadow = COL_MENUCONTENTDARK_PLUS_0);
|
fb_pixel_t color_shadow = COL_MENUCONTENTDARK_PLUS_0);
|
||||||
|
|
||||||
|
///show button frame and background, default false
|
||||||
|
bool btn_contour;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
CComponentsFooter(CComponentsForm *parent = NULL);
|
CComponentsFooter(CComponentsForm *parent = NULL);
|
||||||
CComponentsFooter( const int& x_pos, const int& y_pos, const int& w, const int& h = 0,
|
CComponentsFooter( const int& x_pos, const int& y_pos, const int& w, const int& h = 0,
|
||||||
const int& buttons = 0,
|
const int& buttons = 0,
|
||||||
@@ -50,6 +70,23 @@ class CComponentsFooter : public CComponentsHeader
|
|||||||
fb_pixel_t color_frame = COL_MENUCONTENT_PLUS_6,
|
fb_pixel_t color_frame = COL_MENUCONTENT_PLUS_6,
|
||||||
fb_pixel_t color_body = COL_INFOBAR_SHADOW_PLUS_1,
|
fb_pixel_t color_body = COL_INFOBAR_SHADOW_PLUS_1,
|
||||||
fb_pixel_t color_shadow = COL_MENUCONTENTDARK_PLUS_0);
|
fb_pixel_t color_shadow = COL_MENUCONTENTDARK_PLUS_0);
|
||||||
|
|
||||||
|
///add button labels with string label type as content, count as size_t, total_width as int, label width as int
|
||||||
|
void setButtonLabels(const struct button_label_s * const content, const size_t& label_count, const int& total_width = 0, const int& label_width = 0);
|
||||||
|
///add button labels with locale label type as content, count as size_t, total_width as int, label width as int
|
||||||
|
void setButtonLabels(const struct button_label_l * const content, const size_t& label_count, const int& total_width = 0, const int& label_width = 0);
|
||||||
|
|
||||||
|
///add button labels with old label type, count as size_t, total_width as int, label width as int
|
||||||
|
///NOTE: for compatibility with older button handler find in gui/widget/buttons.h
|
||||||
|
void setButtonLabels(const struct button_label * const content, const size_t& label_count, const int& total_width = 0, const int& label_width = 0);
|
||||||
|
|
||||||
|
///add single button label with string label type as content, total_width as int, label width as int
|
||||||
|
void setButtonLabel(const char *button_icon, const std::string& text, const int& total_width = 0, const int& label_width = 0);
|
||||||
|
///add single button label with locale label type as content, total_width as int, label width as int
|
||||||
|
void setButtonLabel(const char *button_icon, const neutrino_locale_t& locale, const int& total_width = 0, const int& label_width = 0);
|
||||||
|
|
||||||
|
///causes show/hide countour of button frame and background, parameter bool show, default= true
|
||||||
|
void showButtonContour(bool show = true){btn_contour = show;};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user