diff --git a/src/gui/components/cc_frm_button.cpp b/src/gui/components/cc_frm_button.cpp index bb05d2ed1..9b9d4c956 100644 --- a/src/gui/components/cc_frm_button.cpp +++ b/src/gui/components/cc_frm_button.cpp @@ -29,7 +29,7 @@ #include #include - +#include #include "cc_frm_button.h" @@ -152,6 +152,7 @@ void CComponentsButton::initCaption() //text and font if (cc_btn_font == NULL) cc_btn_font = *cc_btn_dy_font->getDynFont(w_cap, h_cap, cc_btn_capt); + cc_btn_capt_obj->setText(cc_btn_capt, CTextBox::NO_AUTO_LINEBREAK, cc_btn_font); cc_btn_capt_obj->forceTextPaint(); //here required; @@ -163,20 +164,25 @@ void CComponentsButton::initCaption() } //handle common position of icon and text inside container required for alignment - int w_required = cc_btn_icon_obj->getWidth() + append_x_offset + cc_btn_font->getRenderWidth(cc_btn_capt, true); - - //do center - int x_icon = width/2 - w_required/2; - cc_btn_icon_obj->setXPos(x_icon); - cc_btn_capt_obj->setXPos(x_icon + cc_btn_icon_obj->getWidth() + append_x_offset); + int w_required = fr_thickness + append_x_offset + cc_btn_icon_obj->getWidth() + append_x_offset + cc_btn_font->getRenderWidth(cc_btn_capt, true) + append_x_offset + fr_thickness; //dynamic width - width = max(w_required, width); + if (w_required > width){ + dprintf(DEBUG_INFO, "[CComponentsButton] [%s - %d] width of button (%s) will be changed: defined width=%d, required width=%d\n", __func__, __LINE__, cc_btn_capt.c_str(), width, w_required); + width = max(w_required, width); + } + + //do center + int x_icon = width/2 - w_required/2 + fr_thickness + append_x_offset; + cc_btn_icon_obj->setXPos(x_icon); + cc_btn_capt_obj->setXPos(x_icon + cc_btn_icon_obj->getWidth() + append_x_offset); + cc_btn_capt_obj->setWidth(width - cc_btn_capt_obj->getXPos()); } void CComponentsButton::setCaption(const std::string& text) { cc_btn_capt = text; + initCCBtnItems(); } void CComponentsButton::setCaption(const neutrino_locale_t locale_text) diff --git a/src/gui/components/cc_frm_footer.cpp b/src/gui/components/cc_frm_footer.cpp index fe8e10321..2bc6ca09a 100644 --- a/src/gui/components/cc_frm_footer.cpp +++ b/src/gui/components/cc_frm_footer.cpp @@ -28,6 +28,7 @@ #include #include #include "cc_frm_footer.h" +#include using namespace std; @@ -89,49 +90,66 @@ void CComponentsFooter::initVarFooter( const int& x_pos, const int& y_pos, const 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) +void CComponentsFooter::setButtonLabels(const struct button_label_s * const content, const size_t& label_count, const int& chain_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 + int w_chain = chain_width > 0 ? chain_width : width;//TODO: alow and handle only with rational values >0, exit here + if (w_chain < 100){ + dprintf(DEBUG_NORMAL, "[CComponentsFooter] [%s - %d] stupid width of chain: width = %d, values < 100 are nonsens, buttons not painted!\n", __func__, __LINE__, w_chain); + return; + } + + //consider context button group on the right side of footer, if exist then subtract result from chain_width of button container if (cch_btn_obj) - w_total -= cch_btn_obj->getWidth(); + w_chain -= 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; + int x_chain = 0; if (cch_icon_obj) - x_btnchain = (cch_icon_obj->getXPos() + cch_offset + cch_icon_obj->getWidth()); + x_chain = (cch_icon_obj->getXPos() + cch_offset + cch_icon_obj->getWidth()); //... reduce also total width for button label container - w_total -= x_btnchain; + w_chain -= x_chain; - //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); + //initialize container (chain object) as button label container: this contains all passed (as interleaved) button label items, with this container we can work inside + //footer as primary container (in this context '=this') and the parent for the button label container (chain object), + //button label container (chain object) itself is concurrent the parent object for button objects. + CComponentsFrmChain *chain = new CComponentsFrmChain(x_chain, CC_CENTERED, w_chain, height, 0, CC_DIR_X, this); + chain->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); + //calculate default static width of button labels inside button object container related to available width of chain object + int w_btn_fix = chain->getWidth() / label_count; + int w_btn_min = min(label_width, w_btn_fix); - //unused size, usable for offset calculation - int w_btn_unused = w_total - w_btn * label_count; + int w_used = 0; - //consider offset of button labels - int w_btn_offset = w_btn_unused / (label_count+1); - btnchain->setAppendOffset(w_btn_offset, 0); - - //finally generate and add button objects passed from button label content. + //generate and add button objects passed from button label content with default width to chain object. 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); + CComponentsButton *btn = new CComponentsButton(0, CC_CENTERED, w_btn_min, height-height/4, content[i].text, content[i].button); btn->setButtonFont(ccf_btn_font); btn->doPaintBg(btn_contour); - btnchain->addCCItem(btn); + chain->addCCItem(btn); + + //set x position of next button object + if (i != 0) + btn->setXPos(CC_APPEND); + + //collect used button width inside chain object + w_used += btn->getWidth(); } + + //calculate offset between button objects inside chain object + int w_rest = max(w_chain - w_used, 0); + int btn_offset = w_rest / chain->size(); + chain->setAppendOffset(btn_offset, 0); + dprintf(DEBUG_INFO, "[CComponentsFooter] [%s - %d] btn_offset = %d, w_rest = %d, w_chain = %d, w_used = %d, chain->size() = %u\n", btn_offset, w_rest, w_chain, w_used, chain->size()); + + //set x position of 1st button object inside chain, this is centering button objects inside chain + int x_1st_btn = btn_offset/2; + chain->getCCItem(0)->setXPos(x_1st_btn); } -void CComponentsFooter::setButtonLabels(const struct button_label_l * const content, const size_t& label_count, const int& total_width, const int& label_width) +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]; @@ -140,27 +158,27 @@ void CComponentsFooter::setButtonLabels(const struct button_label_l * const cont buttons[i].text = g_Locale->getText(content[i].locale); } - setButtonLabels(buttons, label_count, total_width, label_width); + setButtonLabels(buttons, label_count, chain_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) +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, total_width, label_width); + setButtonLabels((button_label_l*)content, label_count, chain_width, label_width); } -void CComponentsFooter::setButtonLabel(const char *button_icon, const std::string& text, const int& total_width, const int& label_width) +void CComponentsFooter::setButtonLabel(const char *button_icon, const std::string& text, const int& chain_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); + setButtonLabels(button, 1, chain_width, label_width); } -void CComponentsFooter::setButtonLabel(const char *button_icon, const neutrino_locale_t& locale, const int& total_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) { string txt = g_Locale->getText(locale); - setButtonLabel(button_icon, txt, total_width, label_width); + setButtonLabel(button_icon, txt, chain_width, label_width); } diff --git a/src/gui/components/cc_frm_footer.h b/src/gui/components/cc_frm_footer.h index 2d6ed3fe4..d943a5bc7 100644 --- a/src/gui/components/cc_frm_footer.h +++ b/src/gui/components/cc_frm_footer.h @@ -74,19 +74,19 @@ class CComponentsFooter : public CComponentsHeader 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 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); + ///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 old label type, count as size_t, total_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 - void setButtonLabels(const struct button_label * const content, const size_t& label_count, const int& total_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, 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); + ///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); + ///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); ///causes show/hide countour of button frame and background, parameter bool show, default= true void showButtonContour(bool show = true){btn_contour = show;}; diff --git a/src/gui/test_menu.cpp b/src/gui/test_menu.cpp index 2a491e5dd..5b7db682e 100644 --- a/src/gui/test_menu.cpp +++ b/src/gui/test_menu.cpp @@ -59,12 +59,13 @@ extern int cs_test_card(int unit, char * str); -#define TestButtonsCount 3 +#define TestButtonsCount 4 const struct button_label TestButtons[/*TestButtonsCount*/] = { { NEUTRINO_ICON_BUTTON_RED , LOCALE_STRINGINPUT_CAPS }, { NEUTRINO_ICON_BUTTON_GREEN , LOCALE_STRINGINPUT_CLEAR }, - { NEUTRINO_ICON_BUTTON_YELLOW , LOCALE_MESSAGEBOX_INFO } + { NEUTRINO_ICON_BUTTON_YELLOW , LOCALE_MESSAGEBOX_INFO }, + { NEUTRINO_ICON_BUTTON_BLUE , LOCALE_STRINGINPUT_CLEAR } }; @@ -368,7 +369,7 @@ int CTestMenu::exec(CMenuTarget* parent, const std::string &actionKey) } else if (actionKey == "button"){ if (button == NULL) - button = new CComponentsButtonRed(100, 100, 100, 40, "Test"); + button = new CComponentsButtonRed(100, 100, 100, 50, "Test"); if (!button->isPainted()){ if (button->isSelected()) @@ -544,10 +545,13 @@ int CTestMenu::exec(CMenuTarget* parent, const std::string &actionKey) if (footer == NULL){ footer = new CComponentsFooter (100, 30, 1000, hh, CComponentsFooter::CC_BTN_HELP | CComponentsFooter::CC_BTN_EXIT | CComponentsFooter::CC_BTN_MENU |CComponentsFooter::CC_BTN_MUTE_ZAP_ACTIVE, NULL, true); int start = 5, btnw =90, btnh = 37; + footer->showButtonContour(); + footer->setButtonFont(g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_SMALL]); footer->setIcon(NEUTRINO_ICON_INFO); //add button labels with conventional button label struct - footer->setButtonLabels(TestButtons, TestButtonsCount, 0, 250); + footer->setButtonLabels(TestButtons, TestButtonsCount, 0, 150); + //also possible: use directly button name and as 2nd parameter string or locale as text // footer->setButtonLabel(NEUTRINO_ICON_BUTTON_RED, "This is a button label text!", 0, 250);