1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
4 # include "../config.h"
11 Label::Label(Widget *parent)
12 : Widget(parent), _text("")
14 const ScreenInfo *info = display->screenInfo(screen());
15 _xftdraw = XftDrawCreate(**display, window(), info->visual(),
21 XftDrawDestroy(_xftdraw);
24 void Label::setStyle(Style *style)
26 Widget::setStyle(style);
28 setTexture(style->getLabelUnfocus());
32 void Label::update(void)
35 const Font *ft = style()->getFont();
36 unsigned int sidemargin = style()->getBevelWidth() * 2;
38 ustring t = _text; // the actual text to draw
39 int x = sidemargin; // x coord for the text
41 // find a string that will fit inside the area for text
42 int max_length = width() - sidemargin * 2;
43 if (max_length <= 0) {
44 t = ""; // can't fit anything
46 size_t text_len = t.size();
51 length = ft->measureString(t);
52 } while (length > max_length && text_len-- > 0);
55 switch (style()->textJustify()) {
56 case Style::RightJustify:
57 x += max_length - length;
59 case Style::CenterJustify:
60 x += (max_length - length) / 2;
62 case Style::LeftJustify:
69 ft->drawString(_xftdraw, x, 0, *style()->getTextUnfocus(), t);