CComponentsHeader: add possibility to modify text alignment

usable in header and its derived classes and in class CComponentsWindow


Origin commit data
------------------
Branch: ni/coolstream
Commit: 64c6eb5945
Author: Thilo Graf <dbt@novatux.de>
Date: 2013-10-23 (Wed, 23 Oct 2013)



------------------
This commit was generated by Migit
This commit is contained in:
2013-10-23 15:46:11 +02:00
parent 6eb5133fa5
commit 9f144909f3
3 changed files with 30 additions and 17 deletions

View File

@@ -123,6 +123,7 @@ class CComponentsHeader : public CComponentsForm
int cch_items_y, cch_icon_x, cch_icon_w, cch_text_x, cch_buttons, cch_buttons_w, cch_buttons_h, cch_buttons_space, cch_offset; int cch_items_y, cch_icon_x, cch_icon_w, cch_text_x, cch_buttons, cch_buttons_w, cch_buttons_h, cch_buttons_space, cch_offset;
std::vector<std::string> v_cch_btn; std::vector<std::string> v_cch_btn;
int cch_size_mode; int cch_size_mode;
int cch_caption_align;
void initIcon(); void initIcon();
void initCaption(); void initCaption();
@@ -162,8 +163,9 @@ class CComponentsHeader : public CComponentsForm
virtual ~CComponentsHeader(); virtual ~CComponentsHeader();
virtual void setCaption(const std::string& caption); virtual void setCaption(const std::string& caption, const int& align_mode = CTextBox::NO_AUTO_LINEBREAK);
virtual void setCaption(neutrino_locale_t caption_locale); virtual void setCaption(neutrino_locale_t caption_locale, const int& align_mode = CTextBox::NO_AUTO_LINEBREAK);
virtual void setCaptionAlignment(const int& align_mode){cch_caption_align = align_mode;};
virtual void setCaptionFont(Font* font_name); virtual void setCaptionFont(Font* font_name);
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;};
virtual void setOffset(const int offset){cch_offset = offset;}; virtual void setOffset(const int offset){cch_offset = offset;};
@@ -225,6 +227,8 @@ class CComponentsWindow : public CComponentsForm
CComponentsFooter * ccw_footer; CComponentsFooter * ccw_footer;
///property: caption in header, see also getHeaderObject() ///property: caption in header, see also getHeaderObject()
std::string ccw_caption; std::string ccw_caption;
///property: alignment mode for header caption
int ccw_align_mode;
///property: icon name in header, see also getHeaderObject() ///property: icon name in header, see also getHeaderObject()
const char* ccw_icon_name; const char* ccw_icon_name;
///property: assigned default icon buttons in header, see also getHeaderObject() ///property: assigned default icon buttons in header, see also getHeaderObject()
@@ -293,10 +297,12 @@ class CComponentsWindow : public CComponentsForm
void showHeader(bool show = true){ccw_show_header = show;}; void showHeader(bool show = true){ccw_show_header = show;};
///set caption in header with string, see also getHeaderObject() ///set caption in header with string, see also getHeaderObject()
void setWindowCaption(const std::string& text){ccw_caption = text;}; void setWindowCaption(const std::string& text, const int& align_mode = CTextBox::NO_AUTO_LINEBREAK){ccw_caption = text; ccw_align_mode = align_mode;};
///set caption in header from locales, see also getHeaderObject() ///set caption in header from locales, see also getHeaderObject()
void setWindowCaption(neutrino_locale_t locale_text); void setWindowCaption(neutrino_locale_t locale_text, const int& align_mode = CTextBox::NO_AUTO_LINEBREAK);
///set caption alignment
void setWindowCaptionAlignment(const int& align_mode){ccw_align_mode = align_mode;};
///set icon name in header, see also getHeaderObject() ///set icon name in header, see also getHeaderObject()
void setWindowIcon(const char* iconname){ccw_icon_name = iconname;}; void setWindowIcon(const char* iconname){ccw_icon_name = iconname;};
@@ -309,7 +315,6 @@ class CComponentsWindow : public CComponentsForm
///returns a pointer to the internal body object, use this to get access to body properities ///returns a pointer to the internal body object, use this to get access to body properities
CComponentsForm* getBodyObject(){return ccw_body;}; CComponentsForm* getBodyObject(){return ccw_body;};
///returns a pointer to the internal footer object, use this to get access to footer properities ///returns a pointer to the internal footer object, use this to get access to footer properities
CComponentsFooter* getFooterObject(){return ccw_footer;}; CComponentsFooter* getFooterObject(){return ccw_footer;};

View File

@@ -109,6 +109,7 @@ void CComponentsHeader::initVarHeader()
cch_btn_obj = NULL; cch_btn_obj = NULL;
cch_text = ""; cch_text = "";
cch_col_text = COL_MENUHEAD_TEXT; cch_col_text = COL_MENUHEAD_TEXT;
cch_caption_align = CTextBox::NO_AUTO_LINEBREAK;
cch_items_y = 0; cch_items_y = 0;
cch_offset = 8; cch_offset = 8;
cch_icon_x = cch_offset; cch_icon_x = cch_offset;
@@ -130,14 +131,16 @@ CComponentsHeader::~CComponentsHeader()
cleanCCForm(); cleanCCForm();
} }
void CComponentsHeader::setCaption(const std::string& caption) void CComponentsHeader::setCaption(const std::string& caption, const int& align_mode)
{ {
cch_text = caption; cch_text = caption;
cch_caption_align = align_mode;
} }
void CComponentsHeader::setCaption(neutrino_locale_t caption_locale) void CComponentsHeader::setCaption(neutrino_locale_t caption_locale, const int& align_mode)
{ {
cch_text = g_Locale->getText(caption_locale); cch_text = g_Locale->getText(caption_locale);
cch_caption_align = align_mode;
} }
void CComponentsHeader::setCaptionFont(Font* font_name) void CComponentsHeader::setCaptionFont(Font* font_name)
@@ -312,12 +315,13 @@ void CComponentsHeader::initButtons()
void CComponentsHeader::initCaption() void CComponentsHeader::initCaption()
{ {
//recalc header text position if header icon is defined //recalc header text position if header icon is defined
int cc_text_w = 0;
if (cch_icon_name != NULL){ if (cch_icon_name != NULL){
cch_text_x = cch_icon_x+cch_icon_w+cch_offset; cch_text_x = cch_icon_x+cch_icon_w+cch_offset;
} }
//calc width of text object in header //calc width of text object in header
int cc_text_w = width-cch_text_x-cch_offset; cc_text_w = width-cch_text_x-cch_offset;
if (cch_buttons_w) if (cch_buttons_w)
cc_text_w -= cch_buttons_w-cch_offset; cc_text_w -= cch_buttons_w-cch_offset;
@@ -335,9 +339,12 @@ void CComponentsHeader::initCaption()
//set header text properties //set header text properties
if (cch_text_obj){ if (cch_text_obj){
//set alignment of text item in dependency from text alignment
if (cch_caption_align == CTextBox::CENTER)
cch_text_x = CC_CENTERED;
cch_text_obj->setDimensionsAll(cch_text_x, cch_items_y, cc_text_w, height); cch_text_obj->setDimensionsAll(cch_text_x, cch_items_y, cc_text_w, height);
cch_text_obj->doPaintBg(false); cch_text_obj->doPaintBg(false);
cch_text_obj->setText(cch_text, CTextBox::TOP | CTextBox::NO_AUTO_LINEBREAK, cch_font); cch_text_obj->setText(cch_text, cch_caption_align, cch_font);
cch_text_obj->forceTextPaint(); //here required cch_text_obj->forceTextPaint(); //here required
cch_text_obj->setTextColor(cch_col_text); cch_text_obj->setTextColor(cch_col_text);
cch_text_obj->setColorBody(col_body); cch_text_obj->setColorBody(col_body);

View File

@@ -142,13 +142,15 @@ void CComponentsWindow::initVarWindow()
ccw_buttons = 0; //no header buttons ccw_buttons = 0; //no header buttons
ccw_show_footer = true; ccw_show_footer = true;
ccw_show_header = true; ccw_show_header = true;
ccw_align_mode = CTextBox::NO_AUTO_LINEBREAK;
setShadowOnOff(true); setShadowOnOff(true);
} }
void CComponentsWindow::setWindowCaption(neutrino_locale_t locale_text) void CComponentsWindow::setWindowCaption(neutrino_locale_t locale_text, const int& align_mode)
{ {
ccw_caption = g_Locale->getText(locale_text); ccw_caption = g_Locale->getText(locale_text);
ccw_align_mode = align_mode;
} }
void CComponentsWindow::initHeader() void CComponentsWindow::initHeader()
@@ -159,12 +161,12 @@ void CComponentsWindow::initHeader()
//add of header item happens initCCWItems() //add of header item happens initCCWItems()
} }
//set header properties //set header properties //TODO: assigned properties with internal header objekt have no effect!
if (ccw_head){ if (ccw_head){
ccw_head->setPos(0, 0);
ccw_head->setWidth(width-2*fr_thickness); ccw_head->setWidth(width-2*fr_thickness);
// ccw_head->setPos(0, 0);
ccw_head->setIcon(ccw_icon_name); ccw_head->setIcon(ccw_icon_name);
ccw_head->setCaption(ccw_caption); ccw_head->setCaption(ccw_caption, ccw_align_mode);
ccw_head->initCCItems(); ccw_head->initCCItems();
ccw_head->setDefaultButtons(ccw_buttons); ccw_head->setDefaultButtons(ccw_buttons);
} }
@@ -196,7 +198,6 @@ void CComponentsWindow::initBody()
void CComponentsWindow::initFooter() void CComponentsWindow::initFooter()
{ {
if (ccw_footer== NULL){ if (ccw_footer== NULL){
ccw_footer= new CComponentsFooter(); ccw_footer= new CComponentsFooter();
initFooter(); initFooter();
//add of footer item happens initCCWItems() //add of footer item happens initCCWItems()