From fc29aa59c7c25798a4c6d21d1d4a4ac0d886c003 Mon Sep 17 00:00:00 2001 From: Thilo Graf Date: Thu, 17 Mar 2016 09:12:43 +0100 Subject: [PATCH] CComponentsButton: fix button icon position on dynamic changed conditions In some constellations it is possible, that costum icons with other dimensions will be not correct positionized. This should fix this issue. This reverts partial commit 289f5b30e67174fee00f7d480520ca1e8df6061b. Origin commit data ------------------ Commit: https://github.com/neutrino-images/ni-neutrino/commit/7197f51e8992c75bc27778029a8e1780d7d516cc Author: Thilo Graf Date: 2016-03-17 (Thu, 17 Mar 2016) --- src/gui/components/cc_frm_button.cpp | 43 ++++++++++++++++------------ 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/src/gui/components/cc_frm_button.cpp b/src/gui/components/cc_frm_button.cpp index 4a9b4b68f..163c4be5c 100644 --- a/src/gui/components/cc_frm_button.cpp +++ b/src/gui/components/cc_frm_button.cpp @@ -142,29 +142,29 @@ void CComponentsButton::initIcon() } //initialize icon object + string::size_type pos = cc_btn_icon.find("/", 0); + if (pos == string::npos) + cc_btn_icon = frameBuffer->getIconBasePath() + "/" + cc_btn_icon + ".png"; + if (cc_btn_icon_obj == NULL){ - int y_icon = 0; - - string::size_type pos = cc_btn_icon.find("/", 0); - if (pos == string::npos) - cc_btn_icon = frameBuffer->getIconBasePath() + "/" + cc_btn_icon + ".png"; - - cc_btn_icon_obj = new CComponentsPictureScalable(fr_thickness, y_icon, cc_btn_icon, this); + cc_btn_icon_obj = new CComponentsPictureScalable(fr_thickness, 0, cc_btn_icon, this); cc_btn_icon_obj->SetTransparent(CFrameBuffer::TM_BLACK); - int h_icon = cc_btn_icon_obj->getHeight(); - - //get required icon height - int h_max = height-2*fr_thickness; - - //get current icon dimensions - if (h_icon > h_max) - cc_btn_icon_obj->setHeight(h_max, true); - - y_icon = h_max/2 - cc_btn_icon_obj->getHeight()/2; - - cc_btn_icon_obj->setYPos(y_icon); cc_btn_icon_obj->doPaintBg(false); } + + int y_icon = cc_btn_icon_obj->getYPos(); + int h_icon = cc_btn_icon_obj->getHeight(); + + //get required icon height + int h_max = height-2*fr_thickness; + + //get current icon dimensions + if (h_icon > h_max) + cc_btn_icon_obj->setHeight(h_max, true); + + y_icon = h_max/2 - cc_btn_icon_obj->getHeight()/2; + + cc_btn_icon_obj->setYPos(y_icon); } void CComponentsButton::initCaption() @@ -237,6 +237,11 @@ void CComponentsButton::initCaption() x_icon += fr_thickness + append_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, + *we must ensure centered y position of icon object + */ + int y_icon = height/2 - cc_btn_icon_obj->getHeight()/2; + cc_btn_icon_obj->setYPos(y_icon); } if (cc_btn_capt_obj){ cc_btn_capt_obj->setXPos(x_icon + w_icon + append_x_offset);