From 908e23005d4faf0053f7604a0d957a77004bbd49 Mon Sep 17 00:00:00 2001 From: Thilo Graf Date: Wed, 10 May 2017 10:42:08 +0200 Subject: [PATCH] CComponentsHeader: Try to adopt different logo/title alignments Not all constellations are tested. Please report. Origin commit data ------------------ Commit: https://github.com/neutrino-images/ni-neutrino/commit/5b541571f936275ad7973af6e6c9d90fb5016bfa Author: Thilo Graf Date: 2017-05-10 (Wed, 10 May 2017) --- src/gui/components/cc_frm_header.cpp | 56 +++++++++++++++++++++------- 1 file changed, 43 insertions(+), 13 deletions(-) diff --git a/src/gui/components/cc_frm_header.cpp b/src/gui/components/cc_frm_header.cpp index 1f075bfac..da59a3b7f 100644 --- a/src/gui/components/cc_frm_header.cpp +++ b/src/gui/components/cc_frm_header.cpp @@ -302,13 +302,23 @@ void CComponentsHeader::initLogo() //right end int x_logo_right = width - cch_logo_obj->getWidth(); - if (cch_btn_obj) - x_logo_right -= cch_btn_obj->getWidth(); - if (cch_cl_obj) - x_logo_right -= cch_cl_obj->getWidth(); + if (cch_caption_align != CTextBox::RIGHT){ + if (cch_btn_obj) + x_logo_right -= cch_btn_obj->getWidth(); + if (cch_cl_obj) + x_logo_right -= cch_cl_obj->getWidth(); + }else{ + if (cch_icon_obj) + x_logo_right += cch_icon_obj->getWidth(); + } //left end - int x_logo_left = getCCItem(prev_id) ? getCCItem(prev_id)->getXPos() + getCCItem(prev_id)->getWidth() : 0; + int x_logo_left = cch_offset; + if (cch_caption_align != CTextBox::RIGHT) + x_logo_left = getCCItem(prev_id) ? getCCItem(prev_id)->getXPos() + getCCItem(prev_id)->getWidth() : 0; + else + if (cch_icon_obj) + x_logo_left += cch_icon_obj->getWidth(); //calculate available space int logo_space = x_logo_right + cch_logo_obj->getWidth() - x_logo_left; @@ -319,17 +329,30 @@ void CComponentsHeader::initLogo() //set final logo position int x_logo = 0; - if (cch_logo.Align == CC_LOGO_RIGHT) - x_logo = x_logo_right; + if (cch_logo.Align == CC_LOGO_RIGHT){ + if (cch_caption_align == CTextBox::RIGHT) + if (cch_text_obj) + x_logo = cch_text_obj->getXPos() - cch_logo_obj->getWidth(); + else + x_logo = x_logo_right; + } if (cch_logo.Align == CC_LOGO_LEFT) x_logo = x_logo_left; if (cch_logo.Align == CC_LOGO_CENTER){ x_logo = width/2 - cch_logo_obj->getWidth()/2; - //fallback if previous item and logo are overlapping - if (getCCItem(prev_id)){ - int x_tmp = x_logo_left + logo_space/2 - cch_logo_obj->getWidth()/2; - if (x_logo <= x_logo_left) - x_logo = x_tmp; + //fallback if adjacent item and logo are overlapping + if (cch_caption_align != CTextBox::RIGHT){ + if (getCCItem(prev_id)){ + int x_tmp = x_logo_left + logo_space/2 - cch_logo_obj->getWidth()/2; + if (x_logo <= x_logo_left) + x_logo = x_tmp; + } + }else{ + if (cch_text_obj){ + if (x_logo + cch_logo_obj->getWidth() >= cch_text_obj->getXPos()){ + x_logo = (x_logo_left + cch_text_obj->getXPos())/2 - cch_logo_obj->getWidth()/2; + } + } } } @@ -576,13 +599,20 @@ void CComponentsHeader::initCaption() //set header text properties if (cch_text_obj){ + int w_free = cc_text_w; + //recalc caption width - cc_text_w = min(cc_text_w, cch_font->getRenderWidth(cch_text)/*+ OFFSET_INNER_MID*/); + cc_text_w = min(cc_text_w, cch_font->getRenderWidth(cch_text)+ OFFSET_INNER_MID); //set alignment of text item in dependency from text alignment if (cch_caption_align == CTextBox::CENTER) cch_text_x = width/2 - cc_text_w/2; + if (cch_caption_align == CTextBox::RIGHT){ + cch_text_x += w_free; + cch_text_x -= max(cc_text_w, cch_font->getRenderWidth(cch_text)+ OFFSET_INNER_MID); + } + //assign general properties cch_text_obj->setDimensionsAll(cch_text_x, cch_items_y, cc_text_w, height); cch_text_obj->setColorBody(col_body);