mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-28 16:01:20 +02:00
CComponentsButton: add possibility to change font type, whitespace fixes
This commit is contained in:
@@ -82,7 +82,7 @@ void CComponentsButton::initVarButton( const int& x_pos, const int& y_pos, const
|
|||||||
cc_item_enabled = enabled;
|
cc_item_enabled = enabled;
|
||||||
cc_item_selected = selected;
|
cc_item_selected = selected;
|
||||||
fr_thickness = 3;
|
fr_thickness = 3;
|
||||||
append_x_offset = 2*fr_thickness;
|
append_x_offset = 6;
|
||||||
append_y_offset = append_x_offset;
|
append_y_offset = append_x_offset;
|
||||||
corner_rad = RADIUS_MID;
|
corner_rad = RADIUS_MID;
|
||||||
|
|
||||||
@@ -95,6 +95,7 @@ void CComponentsButton::initVarButton( const int& x_pos, const int& y_pos, const
|
|||||||
cc_btn_capt = caption;
|
cc_btn_capt = caption;
|
||||||
|
|
||||||
initParent(parent);
|
initParent(parent);
|
||||||
|
initCCBtnItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CComponentsButton::initIcon()
|
void CComponentsButton::initIcon()
|
||||||
@@ -133,12 +134,12 @@ void CComponentsButton::initCaption()
|
|||||||
//set basic properties
|
//set basic properties
|
||||||
if (cc_btn_capt_obj){
|
if (cc_btn_capt_obj){
|
||||||
//position and size
|
//position and size
|
||||||
int x_cap = fr_thickness + append_x_offset;
|
int x_cap = fr_thickness;
|
||||||
x_cap += cc_btn_icon_obj ? cc_btn_icon_obj->getWidth() : 0;
|
x_cap += cc_btn_icon_obj ? cc_btn_icon_obj->getWidth() : 0;
|
||||||
|
|
||||||
int w_cap = width - x_cap - 2*fr_thickness - append_x_offset;
|
int w_cap = width - fr_thickness - append_x_offset - x_cap - fr_thickness;
|
||||||
int h_cap = height - 2*fr_thickness;
|
int h_cap = height - 2*fr_thickness;
|
||||||
|
|
||||||
/*FIXME:
|
/*FIXME:
|
||||||
paint of centered text in y without y_offset
|
paint of centered text in y without y_offset
|
||||||
looks unlovely displaced in y direction besides icon,
|
looks unlovely displaced in y direction besides icon,
|
||||||
@@ -149,7 +150,8 @@ void CComponentsButton::initCaption()
|
|||||||
cc_btn_capt_obj->setDimensionsAll(x_cap, y_cap, w_cap, h_cap);
|
cc_btn_capt_obj->setDimensionsAll(x_cap, y_cap, w_cap, h_cap);
|
||||||
|
|
||||||
//text and font
|
//text and font
|
||||||
cc_btn_font = *cc_btn_dy_font->getDynFont(w_cap, h_cap, cc_btn_capt);
|
if (cc_btn_font == NULL)
|
||||||
|
cc_btn_font = *cc_btn_dy_font->getDynFont(w_cap, h_cap, cc_btn_capt);
|
||||||
cc_btn_capt_obj->setText(cc_btn_capt, CTextBox::NO_AUTO_LINEBREAK, cc_btn_font);
|
cc_btn_capt_obj->setText(cc_btn_capt, CTextBox::NO_AUTO_LINEBREAK, cc_btn_font);
|
||||||
cc_btn_capt_obj->forceTextPaint(); //here required;
|
cc_btn_capt_obj->forceTextPaint(); //here required;
|
||||||
|
|
||||||
@@ -159,6 +161,17 @@ void CComponentsButton::initCaption()
|
|||||||
//corner of text item
|
//corner of text item
|
||||||
cc_btn_capt_obj->setCorner(corner_rad-fr_thickness, corner_type);
|
cc_btn_capt_obj->setCorner(corner_rad-fr_thickness, corner_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//handle common position of icon and text inside container required for alignment
|
||||||
|
int w_required = cc_btn_icon_obj->getWidth() + append_x_offset + cc_btn_font->getRenderWidth(cc_btn_capt, true);
|
||||||
|
|
||||||
|
//do center
|
||||||
|
int x_icon = width/2 - w_required/2;
|
||||||
|
cc_btn_icon_obj->setXPos(x_icon);
|
||||||
|
cc_btn_capt_obj->setXPos(x_icon + cc_btn_icon_obj->getWidth() + append_x_offset);
|
||||||
|
|
||||||
|
//dynamic width
|
||||||
|
width = max(w_required, width);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CComponentsButton::setCaption(const std::string& text)
|
void CComponentsButton::setCaption(const std::string& text)
|
||||||
|
@@ -60,7 +60,7 @@ class CComponentsButton : public CComponentsFrmChain
|
|||||||
std::string cc_btn_capt;
|
std::string cc_btn_capt;
|
||||||
///property: button text as locale, see also setCaption() and getCaptionLocale()
|
///property: button text as locale, see also setCaption() and getCaptionLocale()
|
||||||
neutrino_locale_t cc_btn_capt_locale;
|
neutrino_locale_t cc_btn_capt_locale;
|
||||||
|
|
||||||
///property: icon name, only icons supported, to find in gui/widget/icons.h
|
///property: icon name, only icons supported, to find in gui/widget/icons.h
|
||||||
std::string cc_btn_icon;
|
std::string cc_btn_icon;
|
||||||
|
|
||||||
@@ -75,10 +75,10 @@ class CComponentsButton : public CComponentsFrmChain
|
|||||||
void initIcon();
|
void initIcon();
|
||||||
///initialize label object
|
///initialize label object
|
||||||
void initCaption();
|
void initCaption();
|
||||||
|
|
||||||
///initialize picture and label object
|
///initialize picture and label object
|
||||||
void initCCBtnItems();
|
void initCCBtnItems();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
///basic constructor for button object with most needed params, no button icon is definied here
|
///basic constructor for button object with most needed params, no button icon is definied here
|
||||||
CComponentsButton( const int& x_pos, const int& y_pos, const int& w, const int& h,
|
CComponentsButton( const int& x_pos, const int& y_pos, const int& w, const int& h,
|
||||||
@@ -100,17 +100,20 @@ class CComponentsButton : public CComponentsFrmChain
|
|||||||
|
|
||||||
///set text color
|
///set text color
|
||||||
virtual void setButtonTextColor(fb_pixel_t caption_color){cc_btn_capt_col = caption_color;};
|
virtual void setButtonTextColor(fb_pixel_t caption_color){cc_btn_capt_col = caption_color;};
|
||||||
|
|
||||||
///set caption: parameter as string
|
///set caption: parameter as string
|
||||||
virtual void setCaption(const std::string& text);
|
virtual void setCaption(const std::string& text);
|
||||||
///set caption: parameter as locale
|
///set caption: parameter as locale
|
||||||
virtual void setCaption(const neutrino_locale_t locale_text);
|
virtual void setCaption(const neutrino_locale_t locale_text);
|
||||||
|
|
||||||
///get caption, type as std::string
|
///get caption, type as std::string
|
||||||
virtual std::string getCaptionString(){return cc_btn_capt;};
|
virtual std::string getCaptionString(){return cc_btn_capt;};
|
||||||
///get loacalized caption id, type = neutrino_locale_t
|
///get loacalized caption id, type = neutrino_locale_t
|
||||||
virtual neutrino_locale_t getCaptionLocale(){return cc_btn_capt_locale;};
|
virtual neutrino_locale_t getCaptionLocale(){return cc_btn_capt_locale;};
|
||||||
|
|
||||||
|
///property: set font for label caption, parameter as font object, value NULL causes usaage of dynamic font
|
||||||
|
virtual void setButtonFont(Font* font){cc_btn_font = font;};
|
||||||
|
|
||||||
///reinitialize items
|
///reinitialize items
|
||||||
virtual void Refresh(){initCCBtnItems();};
|
virtual void Refresh(){initCCBtnItems();};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user