1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
4 # include "../config.h"
11 Label::Label(Widget *parent)
12 : Widget(parent), _text("")
20 void Label::setStyle(RenderStyle *style)
22 Widget::setStyle(style);
24 setTexture(style->labelUnfocusBackground());
28 void Label::renderForeground(void)
30 const Font *ft = style()->labelFont();
31 unsigned int sidemargin = style()->bevelWidth() * 2;
33 ustring t = _text; // the actual text to draw
34 int x = sidemargin; // x coord for the text
36 // find a string that will fit inside the area for text
37 int max_length = width() - sidemargin * 2;
38 if (max_length <= 0) {
39 t = ""; // can't fit anything
41 size_t text_len = t.size();
46 length = ft->measureString(t);
47 } while (length > max_length && text_len-- > 0);
50 switch (style()->labelTextJustify()) {
51 case RenderStyle::RightJustify:
52 x += max_length - length;
54 case RenderStyle::CenterJustify:
55 x += (max_length - length) / 2;
57 case RenderStyle::LeftJustify:
62 display->renderControl(_screen)->
63 drawString(*_surface, *ft, x, 0, *style()->textUnfocusColor(), t);