From ab8aa776870fb80a9c19ca3a14ef39884906fb2b Mon Sep 17 00:00:00 2001 From: Thilo Graf Date: Wed, 14 Dec 2016 16:19:40 +0100 Subject: [PATCH] CComponentsHeader: fix font and height handling Font was not changeable. setCaptionFont() was without effect. --- src/gui/components/cc_frm_header.cpp | 24 ++++++-------- src/gui/components/cc_frm_header.h | 49 ++++++++++++++++++++-------- 2 files changed, 46 insertions(+), 27 deletions(-) diff --git a/src/gui/components/cc_frm_header.cpp b/src/gui/components/cc_frm_header.cpp index c7485ec83..5a6e3ec74 100644 --- a/src/gui/components/cc_frm_header.cpp +++ b/src/gui/components/cc_frm_header.cpp @@ -93,12 +93,10 @@ void CComponentsHeader::initVarHeader( const int& x_pos, const int& y_pos, const //init header width width = width_old = w == 0 ? frameBuffer->getScreenWidth(true) : w; + height = height_old = h; - //init header default height - height = height_old = max(h, g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getHeight()); - - cch_size_mode = CC_HEADER_SIZE_LARGE; - initCaptionFont(); //sets cch_font and calculate height if required; + cch_font = NULL; + cch_size_mode = CC_HEADER_SIZE_LARGE; shadow = shadow_mode; col_frame = col_frame_old = color_frame; @@ -160,15 +158,15 @@ void CComponentsHeader::setCaption(neutrino_locale_t caption_locale, const int& void CComponentsHeader::setCaptionFont(Font* font) { - initCaptionFont(font); //cch_font = font + cch_font = font; } -void CComponentsHeader::initCaptionFont(Font* font) +void CComponentsHeader::initCaptionFont() { Font *l_font = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE]; Font *s_font = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]; - if (font == NULL){ + if (cch_font == NULL){ cch_font = (cch_size_mode == CC_HEADER_SIZE_LARGE? l_font : s_font); //select matching height @@ -177,10 +175,8 @@ void CComponentsHeader::initCaptionFont(Font* font) else height = std::min(height, s_font->getHeight()); } - else{ - cch_font = font; + else height = std::max(height, cch_font->getHeight()); - } } void CComponentsHeader::setIcon(const char* icon_name) @@ -513,12 +509,12 @@ void CComponentsHeader::initCaption() void CComponentsHeader::initCCItems() { - //set basic properties - Init(x, y, width, height, col_frame, col_body, col_shadow); - //set size initCaptionFont(); + //set basic properties + Init(x, y, width, height, col_frame, col_body, col_shadow); + //init icon initIcon(); diff --git a/src/gui/components/cc_frm_header.h b/src/gui/components/cc_frm_header.h index b3f185e68..d091e800f 100644 --- a/src/gui/components/cc_frm_header.h +++ b/src/gui/components/cc_frm_header.h @@ -99,7 +99,7 @@ class CComponentsHeader : public CComponentsForm, public CCTextScreen bool cch_cl_enable_run; ///init font object and recalculates height if required - void initCaptionFont(Font* font = NULL); + void initCaptionFont(); ///sub: init icon object void initIcon(); ///sub: init caption object @@ -136,13 +136,44 @@ class CComponentsHeader : public CComponentsForm, public CCTextScreen virtual void setCaption(neutrino_locale_t caption_locale, const int& align_mode = CTextBox::NO_AUTO_LINEBREAK, const fb_pixel_t& text_color = COL_MENUHEAD_TEXT); ///set alignment of caption within header, possible paramters are CTextBox::CENTER, CTextBox::NO_AUTO_LINEBREAK - virtual void setCaptionAlignment(const int& align_mode){cch_caption_align = align_mode;}; - ///set text font object for caption + virtual void setCaptionAlignment(const int& align_mode){cch_caption_align = align_mode;} + + /**Set text font for title. + * Internal default font is g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE] and + * default height of header object is calculated from this font type. + * Height can be changed with modes by setSizeMode(), setHeight() or constructor. + * @return void + * + * @param[in] font exepts font object, type Font* + * @see getCaptionFont(), setSizeMode(), + * setCaptionColor(), + * setCaptionAlignment(), + * setCaption() + */ virtual void setCaptionFont(Font* font); ///returns font object of title caption - virtual Font* getCaptionFont(){return cch_font;}; + virtual Font* getCaptionFont(){return cch_font;} ///set text color for caption - virtual void setCaptionColor(fb_pixel_t text_color){cch_col_text = text_color;}; + virtual void setCaptionColor(fb_pixel_t text_color){cch_col_text = text_color;} + + enum + { + CC_HEADER_SIZE_LARGE = 0, + CC_HEADER_SIZE_SMALL = 1 + }; + /**Set size mode of header. + * These modes are using fonts SNeutrinoSettings::FONT_TYPE_MENU_TITLE for large mode (default) + * and SNeutrinoSettings::FONT_TYPE_MENU for small mode to set required height. + * If other size wanted then use set setCaptionFont() and setHeight() + * @return void + * + * @param[in] size_mode exepts type int (enums) + * possible modes are: + * CC_HEADER_SIZE_LARGE + * CC_HEADER_SIZE_SMALL + * @see setCaption(), setHeight() + */ + virtual void setSizeMode(const int& size_mode){cch_size_mode = size_mode; initCCItems();} ///set offset between items virtual void setOffset(const int offset){cch_offset = offset;}; @@ -198,14 +229,6 @@ class CComponentsHeader : public CComponentsForm, public CCTextScreen ///set offset between icons within context button object virtual void setButtonsSpace(const int buttons_space){cch_buttons_space = buttons_space;} - enum - { - CC_HEADER_SIZE_LARGE = 0, - CC_HEADER_SIZE_SMALL = 1 - }; - ///set size of header, possible values are CC_HEADER_SIZE_LARGE, CC_HEADER_SIZE_SMALL - virtual void setSizeMode(const int& size_mode){cch_size_mode = size_mode; initCCItems();} - ///init all items within header object virtual void initCCItems(); ///returns the text object