]>
Dogcows Code - chaz/openbox/blob - label.cc
16bfd5f47cf9cf49d323b2cac2ee6d4a0d655497
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
= _bevel_width
* 2;
37 resize(w
+ sidemargin
* 2, h
+ _bevel_width
* 2);
43 int w
= _rect
.width(), h
= _rect
.height();
44 const Font
*ft
= style()->labelFont();
45 unsigned int sidemargin
= _bevel_width
* 2;
47 w
= ft
->measureString(_text
) + sidemargin
* 2;
51 // enforce a minimum size
52 if (w
> _rect
.width()) {
53 if (h
> _rect
.height())
56 internalResize(w
, _rect
.height());
57 } else if (h
> _rect
.height())
58 internalResize(_rect
.width(), h
);
64 void Label::renderForeground(void)
66 Widget::renderForeground();
68 const Font
*ft
= style()->labelFont();
69 unsigned int sidemargin
= _bevel_width
* 2;
71 ustring t
= _text
; // the actual text to draw
72 int x
= sidemargin
; // x coord for the text
74 // find a string that will fit inside the area for text
75 int max_length
= width() - sidemargin
* 2;
76 if (max_length
<= 0) {
77 t
= ""; // can't fit anything
79 size_t text_len
= t
.size();
84 length
= ft
->measureString(t
);
85 } while (length
> max_length
&& text_len
-- > 0);
88 switch (style()->labelTextJustify()) {
89 case RenderStyle::RightJustify
:
90 x
+= max_length
- length
;
92 case RenderStyle::CenterJustify
:
93 x
+= (max_length
- length
) / 2;
95 case RenderStyle::LeftJustify
:
100 display
->renderControl(_screen
)->
101 drawString(*_surface
, *ft
, x
, _bevel_width
, *style()->textUnfocusColor(), t
);
This page took 0.035334 seconds and 3 git commands to generate.