]>
Dogcows Code - chaz/openbox/blob - otk/label.cc
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
4 # include "../config.h"
11 Label::Label(Widget
*parent
)
12 : Widget(parent
), _text("")
21 void Label::setStyle(RenderStyle
*style
)
23 Widget::setStyle(style
);
25 setTexture(style
->labelUnfocusBackground());
29 void Label::renderForeground(void)
31 otk::Widget::renderForeground();
33 const Font
*ft
= style()->labelFont();
34 unsigned int sidemargin
= style()->bevelWidth() * 2;
36 ustring t
= _text
; // the actual text to draw
37 int x
= sidemargin
; // x coord for the text
39 // find a string that will fit inside the area for text
40 int max_length
= width() - sidemargin
* 2;
41 if (max_length
<= 0) {
42 t
= ""; // can't fit anything
44 size_t text_len
= t
.size();
49 length
= ft
->measureString(t
);
50 } while (length
> max_length
&& text_len
-- > 0);
53 switch (style()->labelTextJustify()) {
54 case RenderStyle::RightJustify
:
55 x
+= max_length
- length
;
57 case RenderStyle::CenterJustify
:
58 x
+= (max_length
- length
) / 2;
60 case RenderStyle::LeftJustify
:
65 display
->renderControl(_screen
)->
66 drawString(*_surface
, *ft
, x
, 0, *style()->textUnfocusColor(), t
);
This page took 0.036215 seconds and 4 git commands to generate.