#include <label.hh>
Inheritance diagram for otk::Label:
Public Methods | |
Label (Widget *parent) | |
~Label () | |
const ustring & | getText (void) const |
void | setText (const ustring &text) |
virtual void | renderForeground (void) |
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 to be displayed in the label. | |
ustring | _drawtext |
The actual text being shown, may be a subset of _text. | |
int | _drawx |
The drawing offset for the text. |
|
Definition at line 11 of file label.cc. References setStyle().
|
|
Definition at line 17 of file label.cc.
00018 { 00019 } |
|
Definition at line 34 of file label.cc. References otk::RenderStyle::bevelWidth(), otk::Widget::resize(), and otk::Widget::style(). Referenced by fitString().
|
|
Definition at line 28 of file label.cc. References fitSize(), otk::Font::height(), otk::RenderStyle::labelFont(), otk::Font::measureString(), and otk::Widget::style().
|
|
Definition at line 16 of file label.hh. References _text.
00016 { return _text; } |
|
Reimplemented from otk::Widget. Definition at line 64 of file label.cc. References _text, otk::RenderStyle::bevelWidth(), otk::display, otk::RenderStyle::labelFont(), otk::RenderStyle::labelTextJustify(), otk::Font::measureString(), otk::Display::renderControl(), otk::ustring::resize(), otk::ustring::size(), otk::Widget::style(), and otk::Widget::width().
00065 { 00066 Widget::renderForeground(); 00067 00068 const Font *ft = style()->labelFont(); 00069 unsigned int sidemargin = style()->bevelWidth() * 2; 00070 00071 ustring t = _text; // the actual text to draw 00072 int x = sidemargin; // x coord for the text 00073 00074 // find a string that will fit inside the area for text 00075 int max_length = width() - sidemargin * 2; 00076 if (max_length <= 0) { 00077 t = ""; // can't fit anything 00078 } else { 00079 size_t text_len = t.size(); 00080 int length; 00081 00082 do { 00083 t.resize(text_len); 00084 length = ft->measureString(t); 00085 } while (length > max_length && text_len-- > 0); 00086 00087 // justify the text 00088 switch (style()->labelTextJustify()) { 00089 case RenderStyle::RightJustify: 00090 x += max_length - length; 00091 break; 00092 case RenderStyle::CenterJustify: 00093 x += (max_length - length) / 2; 00094 break; 00095 case RenderStyle::LeftJustify: 00096 break; 00097 } 00098 } 00099 00100 display->renderControl(_screen)-> 00101 drawString(*_surface, *ft, x, 0, *style()->textUnfocusColor(), t); 00102 } |
|
Reimplemented from otk::Widget. Definition at line 21 of file label.cc. References otk::RenderStyle::labelUnfocusBackground(), and otk::Widget::setTexture(). Referenced by Label().
00022 { 00023 Widget::setStyle(style); 00024 00025 setTexture(style->labelUnfocusBackground()); 00026 } |
|
Definition at line 17 of file label.hh. References otk::Widget::_dirty, and _text.
|
|
Reimplemented from otk::Widget. Definition at line 40 of file label.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().
00041 { 00042 if (_dirty) { 00043 int w = _rect.width(), h = _rect.height(); 00044 const Font *ft = style()->labelFont(); 00045 unsigned int sidemargin = style()->bevelWidth() * 2; 00046 if (!_fixed_width) 00047 w = ft->measureString(_text) + sidemargin * 2; 00048 if (!_fixed_height) 00049 h = ft->height(); 00050 00051 // enforce a minimum size 00052 if (w > _rect.width()) { 00053 if (h > _rect.height()) 00054 internalResize(w, h); 00055 else 00056 internalResize(w, _rect.height()); 00057 } else if (h > _rect.height()) 00058 internalResize(_rect.width(), h); 00059 } 00060 Widget::update(); 00061 } |
|
The actual text being shown, may be a subset of _text.
|
|
The drawing offset for the text.
|
|
Text to be displayed in the label.
Definition at line 30 of file label.hh. Referenced by getText(), renderForeground(), and setText(). |