mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-27 15:32:59 +02:00
CComponentsButton, CComponentsFooter: rework bestfit of buttons inside chain
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
#include <global.h>
|
||||
#include <neutrino.h>
|
||||
#include "cc_frm_footer.h"
|
||||
#include <system/debug.h>
|
||||
|
||||
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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user