diff --git a/src/gui/components/cc_frm_button.cpp b/src/gui/components/cc_frm_button.cpp index 9b9d4c956..f932d4d44 100644 --- a/src/gui/components/cc_frm_button.cpp +++ b/src/gui/components/cc_frm_button.cpp @@ -164,7 +164,10 @@ void CComponentsButton::initCaption() } //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 if (w_required > width){ @@ -173,10 +176,17 @@ void CComponentsButton::initCaption() } //do center - int x_icon = width/2 - w_required/2 + fr_thickness + append_x_offset; - cc_btn_icon_obj->setXPos(x_icon); - cc_btn_capt_obj->setXPos(x_icon + cc_btn_icon_obj->getWidth() + append_x_offset); - cc_btn_capt_obj->setWidth(width - cc_btn_capt_obj->getXPos()); + int x_icon = width/2 - w_required/2 /*+ fr_thickness + append_x_offset*/; + int w_icon = 0; + if (cc_btn_icon_obj){ + 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)