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");
73 otk::Widget::update();
77 void LabelWidget::renderForeground()
81 printf("LabelWidget::renderForeground()\n");
82 otk::Widget::renderForeground();
85 otk::ustring t = _text;
86 int x = _sidemargin; // x coord for the text
88 // find a string that will fit inside the area for text
89 int max_length = width() - _sidemargin * 2;
90 if (max_length <= 0) {
91 t = ""; // can't fit anything
93 size_t text_len = t.size();
98 length = _font->measureString(t);
99 } while (length > max_length && text_len-- > 0);
103 case otk::RenderStyle::RightJustify:
104 x += max_length - length;
106 case otk::RenderStyle::CenterJustify:
107 x += (max_length - length) / 2;
109 case otk::RenderStyle::LeftJustify:
114 otk::display->renderControl(_screen)->drawString
115 (*_surface, *_font, x, 0, *_text_color, t);
120 void LabelWidget::adjust()
122 // nothing to adjust. no children.