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("")
19 FocusLabel::~FocusLabel()
24 void FocusLabel::setStyle(RenderStyle *style)
26 FocusWidget::setStyle(style);
28 setTexture(style->labelFocusBackground());
29 setUnfocusTexture(style->labelUnfocusBackground());
33 void FocusLabel::renderForeground()
35 otk::Widget::renderForeground();
37 const Font *ft = style()->labelFont();
38 RenderColor *text_color = (isFocused() ? style()->textFocusColor()
39 : style()->textUnfocusColor());
40 unsigned int sidemargin = style()->bevelWidth() * 2;
42 ustring t = _text; // the actual text to draw
43 int x = sidemargin; // x coord for the text
45 // find a string that will fit inside the area for text
46 int max_length = width() - sidemargin * 2;
47 if (max_length <= 0) {
48 t = ""; // can't fit anything
50 size_t text_len = t.size();
55 length = ft->measureString(t);
56 } while (length > max_length && text_len-- > 0);
59 switch (style()->labelTextJustify()) {
60 case RenderStyle::RightJustify:
61 x += max_length - length;
63 case RenderStyle::CenterJustify:
64 x += (max_length - length) / 2;
66 case RenderStyle::LeftJustify:
71 display->renderControl(_screen)->
72 drawString(*_surface, *ft, x, 0, *text_color, t);