1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
4 # include "../config.h"
7 #include "otk/screeninfo.hh"
8 #include "otk/display.hh"
9 #include "labelwidget.hh"
13 LabelWidget::LabelWidget(otk::Widget *parent, WidgetBase::WidgetType type)
14 : otk::Widget(parent),
20 LabelWidget::~LabelWidget()
25 void LabelWidget::setText(const otk::ustring &text)
32 void LabelWidget::setTextures()
35 setTexture(_style->labelFocusBackground());
36 _text_color = _style->textFocusColor();
38 setTexture(_style->labelUnfocusBackground());
39 _text_color = _style->textUnfocusColor();
44 void LabelWidget::setStyle(otk::RenderStyle *style)
46 otk::Widget::setStyle(style);
48 _font = style->labelFont();
49 _sidemargin = style->bevelWidth() * 2;
50 _justify = style->labelTextJustify();
56 void LabelWidget::focus()
63 void LabelWidget::unfocus()
65 otk::Widget::unfocus();
70 void LabelWidget::update()
72 printf("LabelWidget::update()\n");
76 void LabelWidget::renderForeground()
80 otk::Widget::renderForeground();
83 otk::ustring t = _text;
84 int x = _sidemargin; // x coord for the text
86 // find a string that will fit inside the area for text
87 int max_length = width() - _sidemargin * 2;
88 if (max_length <= 0) {
89 t = ""; // can't fit anything
91 size_t text_len = t.size();
96 length = _font->measureString(t);
97 } while (length > max_length && text_len-- > 0);
101 case otk::RenderStyle::RightJustify:
102 x += max_length - length;
104 case otk::RenderStyle::CenterJustify:
105 x += (max_length - length) / 2;
107 case otk::RenderStyle::LeftJustify:
112 otk::display->renderControl(_screen)->drawString
113 (*_surface, *_font, x, 0, *_text_color, t);
118 void LabelWidget::adjust()
120 // nothing to adjust. no children.