CComponentsExtTextForm: fix assign of width with percent value

Assigning of value before width was set, had no effect


Origin commit data
------------------
Commit: 74d25a6089
Author: Thilo Graf <dbt@novatux.de>
Date: 2013-11-10 (Sun, 10 Nov 2013)
This commit is contained in:
2013-11-10 14:53:26 +01:00
parent 4d5a5fef27
commit 2a5f6dd9c5
2 changed files with 15 additions and 6 deletions

View File

@@ -341,6 +341,8 @@ class CComponentsExtTextForm : public CComponentsForm
int ccx_text_width; int ccx_text_width;
///property: font type of both items (label and text), see also setLabelAndText() ///property: font type of both items (label and text), see also setLabelAndText()
Font* ccx_font; Font* ccx_font;
///property: percentage val of label width related to full width, causes fit of text automatically into the available remaining size of item, see also setLabelWidthPercent()
uint8_t ccx_percent_label_w;
///object: label object ///object: label object
CComponentsLabel *ccx_label_obj; CComponentsLabel *ccx_label_obj;
@@ -356,7 +358,7 @@ class CComponentsExtTextForm : public CComponentsForm
protected: protected:
///initialize basic variables ///initialize basic variables
void initVarExtTextForm(const int x_pos = 0, const int y_pos = 0, const int w = 300, const int h = 27, void initVarExtTextForm(const int x_pos = 1, const int y_pos = 1, const int w = 300, const int h = 27,
bool has_shadow = CC_SHADOW_OFF, bool has_shadow = CC_SHADOW_OFF,
fb_pixel_t label_color = COL_MENUCONTENTINACTIVE_TEXT, fb_pixel_t label_color = COL_MENUCONTENTINACTIVE_TEXT,
fb_pixel_t text_color = COL_MENUCONTENT_TEXT, fb_pixel_t text_color = COL_MENUCONTENT_TEXT,

View File

@@ -81,8 +81,16 @@ void CComponentsExtTextForm::initVarExtTextForm(const int x_pos, const int y_pos
cc_item_type = CC_ITEMTYPE_FRM_EXT_TEXT; cc_item_type = CC_ITEMTYPE_FRM_EXT_TEXT;
x = x_pos; x = x_pos;
y = y_pos; y = y_pos;
width = w; width = w;
//init ccx_label_width and ccx_text_width
//default ccx_label_width = 30% of form width
ccx_percent_label_w = DEF_LABEL_WIDTH_PERCENT;
ccx_label_width = ccx_percent_label_w * width/100;
ccx_text_width = width-ccx_label_width;
height = h; height = h;
ccx_label_text = ""; ccx_label_text = "";
ccx_text = ""; ccx_text = "";
shadow = has_shadow; shadow = has_shadow;
@@ -98,9 +106,7 @@ void CComponentsExtTextForm::initVarExtTextForm(const int x_pos, const int y_pos
ccx_font = *(CNeutrinoFonts::getInstance()->getDynFont(dx, dy)); ccx_font = *(CNeutrinoFonts::getInstance()->getDynFont(dx, dy));
ccx_label_align = ccx_text_align = CTextBox::NO_AUTO_LINEBREAK; ccx_label_align = ccx_text_align = CTextBox::NO_AUTO_LINEBREAK;
//init ccx_label_width and ccx_text_width
//default ccx_label_width = 30% of form width
setLabelWidthPercent(DEF_LABEL_WIDTH_PERCENT );
} }
void CComponentsExtTextForm::initLabel() void CComponentsExtTextForm::initLabel()
@@ -125,6 +131,7 @@ void CComponentsExtTextForm::initLabel()
//set properties //set properties
if (ccx_label_obj){ if (ccx_label_obj){
ccx_label_width = (ccx_percent_label_w * width/100);
ccx_label_obj->setText(ccx_label_text, ccx_label_align, ccx_font); ccx_label_obj->setText(ccx_label_text, ccx_label_align, ccx_font);
ccx_label_obj->setTextColor(ccx_label_color); ccx_label_obj->setTextColor(ccx_label_color);
ccx_label_obj->setDimensionsAll(fr_thickness, 0, ccx_label_width-fr_thickness, height-2*fr_thickness); ccx_label_obj->setDimensionsAll(fr_thickness, 0, ccx_label_width-fr_thickness, height-2*fr_thickness);
@@ -154,6 +161,7 @@ void CComponentsExtTextForm::initText()
//set properties //set properties
if (ccx_text_obj){ if (ccx_text_obj){
ccx_text_width = width-ccx_label_obj->getWidth();
ccx_text_obj->setText(ccx_text, ccx_text_align, ccx_font); ccx_text_obj->setText(ccx_text, ccx_text_align, ccx_font);
ccx_text_obj->setTextColor(ccx_text_color); ccx_text_obj->setTextColor(ccx_text_color);
ccx_text_obj->setDimensionsAll(CC_APPEND, 0, ccx_text_width-2*fr_thickness, height-2*fr_thickness); ccx_text_obj->setDimensionsAll(CC_APPEND, 0, ccx_text_width-2*fr_thickness, height-2*fr_thickness);
@@ -216,8 +224,7 @@ void CComponentsExtTextForm::initCCTextItems()
void CComponentsExtTextForm::setLabelWidthPercent(const uint8_t& percent_val) void CComponentsExtTextForm::setLabelWidthPercent(const uint8_t& percent_val)
{ {
ccx_label_width = percent_val * width/100; ccx_percent_label_w = (int)percent_val;
ccx_text_width = width-ccx_label_width;
initCCTextItems(); initCCTextItems();
} }