CComponentsButton: try to fix fallback for font size

Some conditions were not catched.
This commit is contained in:
2017-01-03 11:25:43 +01:00
parent 753cfda243
commit a5d2c2cb1d

View File

@@ -120,7 +120,7 @@ void CComponentsButton::initVarButton( const int& x_pos, const int& y_pos, const
cc_btn_icon_obj = NULL;
cc_btn_text_obj = NULL;
cc_btn_dy_font = CNeutrinoFonts::getInstance();
cc_btn_font = g_Font[SNeutrinoSettings::FONT_TYPE_BUTTON_TEXT];
cc_btn_font = NULL;
cc_btn_icon = icon_name;
cc_btn_text = caption;
cc_directKey = CRCInput::RC_nokey;
@@ -188,6 +188,7 @@ void CComponentsButton::initCaption()
//set basic properties
int w_frame = fr_thickness;
int reduce = 2*w_frame;
if (cc_btn_text_obj){
//position and size
int x_cap = w_frame;
@@ -197,8 +198,8 @@ void CComponentsButton::initCaption()
if (cc_btn_font == NULL)
cc_btn_font = g_Font[SNeutrinoSettings::FONT_TYPE_BUTTON_TEXT];
int w_cap = width - w_frame - append_x_offset - x_cap - w_frame;
int h_cap = min(height - 2*w_frame, cc_btn_font->getHeight());
int w_cap = min(width - append_x_offset - x_cap - reduce, cc_btn_font->getRenderWidth(cc_btn_text));
int h_cap = min(height - reduce, cc_btn_font->getHeight());
/*NOTE:
paint of centered text in y direction without y_offset
looks unlovely displaced in y direction especially besides small icons and inside small areas,
@@ -210,13 +211,17 @@ void CComponentsButton::initCaption()
cc_btn_text_obj->setDimensionsAll(x_cap, y_cap, w_cap, h_cap);
//text and font
Font* def_font = *cc_btn_dy_font->getDynFont(w_cap, h_cap, cc_btn_text);
/* If button dimension too small, use dynamic font, this ignores possible defined font
* Otherwise definied font will be used. Button dimensions are calculated from parent container (e.g. footer...).
* These dimensions must be enough to display complete content like possible icon and without truncated text.
*/
if ((cc_btn_font->getHeight()- 2*w_frame) > (height - 2*w_frame) && (cc_btn_font->getRenderWidth(cc_btn_text)- 2*w_frame) > w_cap)
cc_btn_font = def_font;
Font *tmp_font = cc_btn_font;
if ((tmp_font->getHeight()-reduce) > (height-reduce) && (tmp_font->getRenderWidth(cc_btn_text)-reduce) > width-reduce)
tmp_font = *cc_btn_dy_font->getDynFont(w_cap, h_cap, cc_btn_text);
if ((cc_btn_font->getHeight()-reduce) > (height-reduce))
tmp_font = *cc_btn_dy_font->getDynFont(w_cap, h_cap, cc_btn_text);
cc_btn_font = tmp_font;
cc_btn_text_obj->setText(cc_btn_text, CTextBox::NO_AUTO_LINEBREAK, cc_btn_font);
cc_btn_text_obj->forceTextPaint(); //here required;