From 3ba2c24cadd95f9c738259e0e705530f5979c47a Mon Sep 17 00:00:00 2001 From: Thilo Graf Date: Sun, 27 Apr 2014 14:19:32 +0200 Subject: [PATCH] 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 Origin commit data ------------------ Commit: https://github.com/neutrino-images/ni-neutrino/commit/8797872d47afe0cafcba9ef56bfd4603f591c174 Author: Thilo Graf Date: 2014-04-27 (Sun, 27 Apr 2014) --- src/gui/components/cc_frm_footer.cpp | 83 +++++++++++++++++++++++++++- src/gui/components/cc_frm_footer.h | 39 ++++++++++++- 2 files changed, 118 insertions(+), 4 deletions(-) diff --git a/src/gui/components/cc_frm_footer.cpp b/src/gui/components/cc_frm_footer.cpp index 2fa63df8e..9bde8c8d3 100644 --- a/src/gui/components/cc_frm_footer.cpp +++ b/src/gui/components/cc_frm_footer.cpp @@ -63,7 +63,7 @@ void CComponentsFooter::initVarFooter( const int& x_pos, const int& y_pos, const x = x_pos; y = y_pos; - + //init footer width width = w == 0 ? frameBuffer->getScreenWidth(true) : w; //init header height @@ -72,16 +72,93 @@ void CComponentsFooter::initVarFooter( const int& x_pos, const int& y_pos, const height = h; else height = cch_font->getHeight(); - + shadow = has_shadow; col_frame = color_frame; col_body = color_body; col_shadow = color_shadow; - + corner_rad = RADIUS_LARGE; corner_type = CORNER_BOTTOM; + btn_contour = false; + addContextButton(buttons); initCCItems(); 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); +} diff --git a/src/gui/components/cc_frm_footer.h b/src/gui/components/cc_frm_footer.h index f0fad0646..db478637c 100644 --- a/src/gui/components/cc_frm_footer.h +++ b/src/gui/components/cc_frm_footer.h @@ -26,6 +26,21 @@ #include "cc_frm_header.h" +#include "cc_frm_button.h" +#include //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 @@ -33,7 +48,7 @@ Is mostly usable like a header but without caption, and context button icons. */ class CComponentsFooter : public CComponentsHeader { - protected: + private: void initVarFooter( const int& x_pos, const int& y_pos, const int& w, const int& h = 0, const int& buttons = 0, CComponentsForm *parent = NULL, @@ -41,7 +56,12 @@ class CComponentsFooter : public CComponentsHeader fb_pixel_t color_frame = COL_MENUCONTENT_PLUS_6, fb_pixel_t color_body = COL_INFOBAR_SHADOW_PLUS_1, fb_pixel_t color_shadow = COL_MENUCONTENTDARK_PLUS_0); + + ///show button frame and background, default false + bool btn_contour; + public: + CComponentsFooter(CComponentsForm *parent = NULL); CComponentsFooter( const int& x_pos, const int& y_pos, const int& w, const int& h = 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_body = COL_INFOBAR_SHADOW_PLUS_1, 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