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(void)
34 const Font *ft = style()->labelFont();
35 RenderColor *text_color = (isFocused() ? style()->textFocusColor()
36 : style()->textUnfocusColor());
37 unsigned int sidemargin = style()->bevelWidth() * 2;
39 ustring t = _text; // the actual text to draw
40 int x = sidemargin; // x coord for the text
42 // find a string that will fit inside the area for text
43 int max_length = width() - sidemargin * 2;
44 if (max_length <= 0) {
45 t = ""; // can't fit anything
47 size_t text_len = t.size();
52 length = ft->measureString(t);
53 } while (length > max_length && text_len-- > 0);
56 switch (style()->labelTextJustify()) {
57 case RenderStyle::RightJustify:
58 x += max_length - length;
60 case RenderStyle::CenterJustify:
61 x += (max_length - length) / 2;
63 case RenderStyle::LeftJustify:
68 display->renderControl(_screen)->
69 drawString(*_surface, *ft, x, 0, *text_color, t);