#include <focuslabel.hh>
Inheritance diagram for otk::FocusLabel:
Public Methods | |
FocusLabel (Widget *parent) | |
~FocusLabel () | |
const ustring & | getText (void) const |
void | setText (const ustring &text) |
virtual void | renderForeground () |
virtual void | update () |
void | fitString (const std::string &str) |
void | fitSize (int w, int h) |
virtual void | setStyle (RenderStyle *style) |
Private Attributes | |
ustring | _text |
Text displayed in the label. |
|
Definition at line 13 of file focuslabel.cc. References setStyle().
00014 : FocusWidget(parent), _text("") 00015 { 00016 setStyle(_style); 00017 } |
|
Definition at line 19 of file focuslabel.cc.
00020 { 00021 } |
|
Definition at line 38 of file focuslabel.cc. References otk::RenderStyle::bevelWidth(), otk::Widget::resize(), and otk::Widget::style(). Referenced by fitString().
|
|
Definition at line 32 of file focuslabel.cc. References fitSize(), otk::Font::height(), otk::RenderStyle::labelFont(), otk::Font::measureString(), and otk::Widget::style().
|
|
Definition at line 16 of file focuslabel.hh. References _text.
00016 { return _text; } |
|
Reimplemented from otk::Widget. Definition at line 68 of file focuslabel.cc. References _text, otk::RenderStyle::bevelWidth(), otk::display, otk::FocusWidget::isFocused(), otk::RenderStyle::labelFont(), otk::RenderStyle::labelTextJustify(), otk::Font::measureString(), otk::Display::renderControl(), otk::ustring::resize(), otk::ustring::size(), otk::Widget::style(), otk::RenderStyle::textFocusColor(), otk::RenderStyle::textUnfocusColor(), and otk::Widget::width().
00069 { 00070 FocusWidget::renderForeground(); 00071 00072 const Font *ft = style()->labelFont(); 00073 RenderColor *text_color = (isFocused() ? style()->textFocusColor() 00074 : style()->textUnfocusColor()); 00075 unsigned int sidemargin = style()->bevelWidth() * 2; 00076 00077 ustring t = _text; // the actual text to draw 00078 int x = sidemargin; // x coord for the text 00079 00080 // find a string that will fit inside the area for text 00081 int max_length = width() - sidemargin * 2; 00082 if (max_length <= 0) { 00083 t = ""; // can't fit anything 00084 } else { 00085 size_t text_len = t.size(); 00086 int length; 00087 00088 do { 00089 t.resize(text_len); 00090 length = ft->measureString(t); 00091 } while (length > max_length && text_len-- > 0); 00092 00093 // justify the text 00094 switch (style()->labelTextJustify()) { 00095 case RenderStyle::RightJustify: 00096 x += max_length - length; 00097 break; 00098 case RenderStyle::CenterJustify: 00099 x += (max_length - length) / 2; 00100 break; 00101 case RenderStyle::LeftJustify: 00102 break; 00103 } 00104 } 00105 00106 display->renderControl(_screen)-> 00107 drawString(*_surface, *ft, x, 0, *text_color, t); 00108 } |
|
Reimplemented from otk::Widget. Reimplemented in otk::Button. Definition at line 24 of file focuslabel.cc. References otk::RenderStyle::labelFocusBackground(), otk::RenderStyle::labelUnfocusBackground(), otk::FocusWidget::setTexture(), and otk::FocusWidget::setUnfocusTexture(). Referenced by FocusLabel().
00025 { 00026 FocusWidget::setStyle(style); 00027 00028 setTexture(style->labelFocusBackground()); 00029 setUnfocusTexture(style->labelUnfocusBackground()); 00030 } |
|
Definition at line 17 of file focuslabel.hh. References otk::Widget::_dirty, and _text. Referenced by main().
|
|
Reimplemented from otk::Widget. Definition at line 44 of file focuslabel.cc. References otk::Widget::_fixed_height, otk::Widget::_fixed_width, otk::Widget::_rect, otk::RenderStyle::bevelWidth(), otk::Font::height(), otk::Rect::height(), otk::Widget::internalResize(), otk::RenderStyle::labelFont(), otk::Font::measureString(), otk::Widget::style(), and otk::Rect::width(). Referenced by otk::Button::buttonPressHandler(), and otk::Button::buttonReleaseHandler().
00045 { 00046 if (_dirty) { 00047 int w = _rect.width(), h = _rect.height(); 00048 const Font *ft = style()->labelFont(); 00049 unsigned int sidemargin = style()->bevelWidth() * 2; 00050 if (!_fixed_width) 00051 w = ft->measureString(_text) + sidemargin * 2; 00052 if (!_fixed_height) 00053 h = ft->height(); 00054 00055 // enforce a minimum size 00056 if (w > _rect.width()) { 00057 if (h > _rect.height()) 00058 internalResize(w, h); 00059 else 00060 internalResize(w, _rect.height()); 00061 } else if (h > _rect.height()) 00062 internalResize(_rect.width(), h); 00063 } 00064 FocusWidget::update(); 00065 } |
|
Text displayed in the label.
Definition at line 30 of file focuslabel.hh. Referenced by getText(), renderForeground(), and setText(). |