Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

otk::Label Class Reference

#include <label.hh>

Inheritance diagram for otk::Label:

Inheritance graph
[legend]
Collaboration diagram for otk::Label:

Collaboration graph
[legend]
List of all members.

Public Methods

 Label (Widget *parent)
 ~Label ()
const ustringgetText (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.


Constructor & Destructor Documentation

otk::Label::Label Widget   parent
 

Definition at line 11 of file label.cc.

References setStyle().

00012   : Widget(parent), _text("")
00013 {
00014   setStyle(_style);
00015 }

otk::Label::~Label  
 

Definition at line 17 of file label.cc.

00018 {
00019 }


Member Function Documentation

void otk::Label::fitSize int    w,
int    h
 

Definition at line 34 of file label.cc.

References otk::RenderStyle::bevelWidth(), otk::Widget::resize(), and otk::Widget::style().

Referenced by fitString().

00035 {
00036   unsigned int sidemargin = style()->bevelWidth() * 2;
00037   resize(w + sidemargin * 2, h);
00038 }

void otk::Label::fitString const std::string &    str
 

Definition at line 28 of file label.cc.

References fitSize(), otk::Font::height(), otk::RenderStyle::labelFont(), otk::Font::measureString(), and otk::Widget::style().

00029 {
00030   const Font *ft = style()->labelFont();
00031   fitSize(ft->measureString(str), ft->height());
00032 }

const ustring& otk::Label::getText void    const [inline]
 

Definition at line 16 of file label.hh.

References _text.

00016 { return _text; }

void otk::Label::renderForeground void    [virtual]
 

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 }

void otk::Label::setStyle RenderStyle   style [virtual]
 

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 }

void otk::Label::setText const ustring   text [inline]
 

Definition at line 17 of file label.hh.

References otk::Widget::_dirty, and _text.

00017 { _text = text; _dirty = true; }

void otk::Label::update   [virtual]
 

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 }


Member Data Documentation

ustring otk::Label::_drawtext [private]
 

The actual text being shown, may be a subset of _text.

Definition at line 32 of file label.hh.

int otk::Label::_drawx [private]
 

The drawing offset for the text.

Definition at line 34 of file label.hh.

ustring otk::Label::_text [private]
 

Text to be displayed in the label.

Definition at line 30 of file label.hh.

Referenced by getText(), renderForeground(), and setText().


The documentation for this class was generated from the following files:
Generated on Tue Feb 4 23:00:27 2003 for Openbox by doxygen1.3-rc2