CComponentsButton: fix offset between icon and text items

We have only two items, therfore it makes sense to set offset to 0
if we have only one item. Otherwise a single item will not be centered.


Origin commit data
------------------
Commit: 294278aad3
Author: Thilo Graf <dbt@novatux.de>
Date: 2017-05-28 (Sun, 28 May 2017)
This commit is contained in:
2017-05-28 13:30:58 +02:00
parent 6d9267c1c3
commit 78d7830040

View File

@@ -187,6 +187,7 @@ void CComponentsButton::initCaption()
} }
//set basic properties //set basic properties
int x_offset = (!cc_btn_text_obj || !cc_btn_icon_obj) ? 0 : append_x_offset;
int w_frame = fr_thickness; int w_frame = fr_thickness;
int reduce = 2*w_frame; int reduce = 2*w_frame;
if (cc_btn_text_obj){ if (cc_btn_text_obj){
@@ -198,7 +199,7 @@ void CComponentsButton::initCaption()
if (cc_btn_font == NULL) if (cc_btn_font == NULL)
cc_btn_font = g_Font[SNeutrinoSettings::FONT_TYPE_BUTTON_TEXT]; cc_btn_font = g_Font[SNeutrinoSettings::FONT_TYPE_BUTTON_TEXT];
int w_cap = min(width - append_x_offset - x_cap - reduce, cc_btn_font->getRenderWidth(cc_btn_text)); int w_cap = min(width - x_offset - x_cap - reduce, cc_btn_font->getRenderWidth(cc_btn_text));
int h_cap = min(height - reduce, cc_btn_font->getHeight()); int h_cap = min(height - reduce, cc_btn_font->getHeight());
/*NOTE: /*NOTE:
paint of centered text in y direction without y_offset paint of centered text in y direction without y_offset
@@ -235,10 +236,10 @@ void CComponentsButton::initCaption()
} }
//handle common position of icon and text inside container required for alignment //handle common position of icon and text inside container required for alignment
int w_required = w_frame + append_x_offset; int w_required = w_frame + x_offset;
w_required += cc_btn_icon_obj ? cc_btn_icon_obj->getWidth() + append_x_offset : 0; w_required += cc_btn_icon_obj ? cc_btn_icon_obj->getWidth() + x_offset : 0;
w_required += cc_btn_font ? cc_btn_font->getRenderWidth(cc_btn_text) : 0; w_required += cc_btn_font ? cc_btn_font->getRenderWidth(cc_btn_text) : 0;
w_required += append_x_offset + w_frame; w_required += x_offset + w_frame;
//dynamic width //dynamic width
if (w_required > width){ if (w_required > width){
@@ -247,10 +248,10 @@ void CComponentsButton::initCaption()
} }
//do center //do center
int x_icon = width/2 - w_required/2 /*+ fr_thickness + append_x_offset*/; int x_icon = width/2 - w_required/2 /*+ fr_thickness + x_offset*/;
int w_icon = 0; int w_icon = 0;
if (cc_btn_icon_obj){ if (cc_btn_icon_obj){
x_icon += w_frame + append_x_offset; x_icon += w_frame + x_offset;
cc_btn_icon_obj->setXPos(x_icon); cc_btn_icon_obj->setXPos(x_icon);
w_icon = cc_btn_icon_obj->getWidth(); w_icon = cc_btn_icon_obj->getWidth();
/*in case of dynamic changed height of caption or button opbject itself, /*in case of dynamic changed height of caption or button opbject itself,
@@ -260,7 +261,7 @@ void CComponentsButton::initCaption()
cc_btn_icon_obj->setYPos(y_icon); cc_btn_icon_obj->setYPos(y_icon);
} }
if (cc_btn_text_obj){ if (cc_btn_text_obj){
cc_btn_text_obj->setXPos(x_icon + w_icon + append_x_offset); cc_btn_text_obj->setXPos(x_icon + w_icon + x_offset);
cc_btn_text_obj->setWidth(width - cc_btn_text_obj->getXPos()); cc_btn_text_obj->setWidth(width - cc_btn_text_obj->getXPos());
} }
} }