]>
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("")
20 void Label::setStyle(RenderStyle
*style
)
22 Widget::setStyle(style
);
24 setTexture(style
->labelUnfocusBackground());
28 void Label::renderForeground(void)
30 otk::Widget::renderForeground();
32 const Font
*ft
= style()->labelFont();
33 unsigned int sidemargin
= style()->bevelWidth() * 2;
35 ustring t
= _text
; // the actual text to draw
36 int x
= sidemargin
; // x coord for the text
38 // find a string that will fit inside the area for text
39 int max_length
= width() - sidemargin
* 2;
40 if (max_length
<= 0) {
41 t
= ""; // can't fit anything
43 size_t text_len
= t
.size();
48 length
= ft
->measureString(t
);
49 } while (length
> max_length
&& text_len
-- > 0);
52 switch (style()->labelTextJustify()) {
53 case RenderStyle::RightJustify
:
54 x
+= max_length
- length
;
56 case RenderStyle::CenterJustify
:
57 x
+= (max_length
- length
) / 2;
59 case RenderStyle::LeftJustify
:
64 display
->renderControl(_screen
)->
65 drawString(*_surface
, *ft
, x
, 0, *style()->textUnfocusColor(), t
);
This page took 0.042219 seconds and 4 git commands to generate.