mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-29 08:21:12 +02:00
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.
This commit is contained in:
@@ -187,6 +187,7 @@ void CComponentsButton::initCaption()
|
||||
}
|
||||
|
||||
//set basic properties
|
||||
int x_offset = (!cc_btn_text_obj || !cc_btn_icon_obj) ? 0 : append_x_offset;
|
||||
int w_frame = fr_thickness;
|
||||
int reduce = 2*w_frame;
|
||||
if (cc_btn_text_obj){
|
||||
@@ -198,7 +199,7 @@ void CComponentsButton::initCaption()
|
||||
if (cc_btn_font == NULL)
|
||||
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());
|
||||
/*NOTE:
|
||||
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
|
||||
int w_required = w_frame + append_x_offset;
|
||||
w_required += cc_btn_icon_obj ? cc_btn_icon_obj->getWidth() + append_x_offset : 0;
|
||||
int w_required = w_frame + x_offset;
|
||||
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 += append_x_offset + w_frame;
|
||||
w_required += x_offset + w_frame;
|
||||
|
||||
//dynamic width
|
||||
if (w_required > width){
|
||||
@@ -247,10 +248,10 @@ void CComponentsButton::initCaption()
|
||||
}
|
||||
|
||||
//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;
|
||||
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);
|
||||
w_icon = cc_btn_icon_obj->getWidth();
|
||||
/*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);
|
||||
}
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user