CComponentsButton: ignonre objects if no inititalized

This makes it possible to use buttons with or without icons or text
This commit is contained in:
2014-05-01 21:18:06 +02:00
parent 2bde5a6d08
commit 95c7e44eb1

View File

@@ -164,7 +164,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 = 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; int w_required = fr_thickness + append_x_offset;
w_required += cc_btn_icon_obj ? cc_btn_icon_obj->getWidth() + append_x_offset : 0;
w_required += cc_btn_font ? cc_btn_font->getRenderWidth(cc_btn_capt, true) : 0;
w_required += append_x_offset + fr_thickness;
//dynamic width //dynamic width
if (w_required > width){ if (w_required > width){
@@ -173,10 +176,17 @@ 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 + append_x_offset*/;
cc_btn_icon_obj->setXPos(x_icon); int w_icon = 0;
cc_btn_capt_obj->setXPos(x_icon + cc_btn_icon_obj->getWidth() + append_x_offset); if (cc_btn_icon_obj){
cc_btn_capt_obj->setWidth(width - cc_btn_capt_obj->getXPos()); x_icon += fr_thickness + append_x_offset;
cc_btn_icon_obj->setXPos(x_icon);
w_icon = cc_btn_icon_obj->getWidth();
}
if (cc_btn_capt_obj){
cc_btn_capt_obj->setXPos(x_icon + w_icon + append_x_offset);
cc_btn_capt_obj->setWidth(width - cc_btn_capt_obj->getXPos());
}
} }
void CComponentsButton::setCaption(const std::string& text) void CComponentsButton::setCaption(const std::string& text)