]>
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());
28 void Label::fitString(const std::string
&str
)
30 const Font
*ft
= style()->labelFont();
31 fitSize(ft
->measureString(str
), ft
->height());
34 void Label::fitSize(int w
, int h
)
36 unsigned int sidemargin
= style()->bevelWidth() * 2;
37 resize(w
+ sidemargin
* 2, h
);
43 int w
= _rect
.width(), h
= _rect
.height();
44 const Font
*ft
= style()->labelFont();
45 unsigned int sidemargin
= style()->bevelWidth() * 2;
47 w
= ft
->measureString(_text
) + sidemargin
* 2;
56 void Label::renderForeground(void)
58 Widget::renderForeground();
60 const Font
*ft
= style()->labelFont();
61 unsigned int sidemargin
= style()->bevelWidth() * 2;
63 ustring t
= _text
; // the actual text to draw
64 int x
= sidemargin
; // x coord for the text
66 // find a string that will fit inside the area for text
67 int max_length
= width() - sidemargin
* 2;
68 if (max_length
<= 0) {
69 t
= ""; // can't fit anything
71 size_t text_len
= t
.size();
76 length
= ft
->measureString(t
);
77 } while (length
> max_length
&& text_len
-- > 0);
80 switch (style()->labelTextJustify()) {
81 case RenderStyle::RightJustify
:
82 x
+= max_length
- length
;
84 case RenderStyle::CenterJustify
:
85 x
+= (max_length
- length
) / 2;
87 case RenderStyle::LeftJustify
:
92 display
->renderControl(_screen
)->
93 drawString(*_surface
, *ft
, x
, 0, *style()->textUnfocusColor(), t
);
This page took 0.037965 seconds and 4 git commands to generate.