1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
4 # include "../config.h"
7 #include "focuslabel.hh"
9 #include "screeninfo.hh"
13 FocusLabel::FocusLabel(Widget *parent)
14 : FocusWidget(parent), _text("")
18 FocusLabel::~FocusLabel()
23 void FocusLabel::setStyle(RenderStyle *style)
25 FocusWidget::setStyle(style);
27 setTexture(style->labelFocusBackground());
28 setUnfocusTexture(style->labelUnfocusBackground());
32 void FocusLabel::renderForeground()
34 otk::Widget::renderForeground();
36 const Font *ft = style()->labelFont();
37 RenderColor *text_color = (isFocused() ? style()->textFocusColor()
38 : style()->textUnfocusColor());
39 unsigned int sidemargin = style()->bevelWidth() * 2;
41 ustring t = _text; // the actual text to draw
42 int x = sidemargin; // x coord for the text
44 // find a string that will fit inside the area for text
45 int max_length = width() - sidemargin * 2;
46 if (max_length <= 0) {
47 t = ""; // can't fit anything
49 size_t text_len = t.size();
54 length = ft->measureString(t);
55 } while (length > max_length && text_len-- > 0);
58 switch (style()->labelTextJustify()) {
59 case RenderStyle::RightJustify:
60 x += max_length - length;
62 case RenderStyle::CenterJustify:
63 x += (max_length - length) / 2;
65 case RenderStyle::LeftJustify:
70 display->renderControl(_screen)->
71 drawString(*_surface, *ft, x, 0, *text_color, t);