From ff78f69368406c2ac8d3d56e17ec5cb26e83855f Mon Sep 17 00:00:00 2001 From: Thilo Graf Date: Thu, 1 May 2014 21:18:06 +0200 Subject: [PATCH] CComponentsButton: ignonre objects if no inititalized This makes it possible to use buttons with or without icons or text Origin commit data ------------------ Commit: https://github.com/neutrino-images/ni-neutrino/commit/95c7e44eb1742307d8d91e0443d9c597a1343155 Author: Thilo Graf Date: 2014-05-01 (Thu, 01 May 2014) --- src/gui/components/cc_frm_button.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) 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)