]>
Dogcows Code - chaz/openbox/blob - otk/label.cc
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
4 # include "../config.h"
11 OtkLabel::OtkLabel(OtkWidget
*parent
)
12 : OtkWidget(parent
), _text("")
14 const ScreenInfo
*info
= OBDisplay::screenInfo(getScreen());
15 _xftdraw
= XftDrawCreate(OBDisplay::display
, getWindow(), info
->getVisual(),
23 XftDrawDestroy(_xftdraw
);
26 void OtkLabel::setStyle(Style
*style
)
28 OtkWidget::setStyle(style
);
30 setTexture(getStyle()->getLabelUnfocus());
34 void OtkLabel::update(void)
37 const BFont
&ft
= getStyle()->getFont();
38 unsigned int sidemargin
= getStyle()->getBevelWidth() * 2;
40 std::string t
= _text
; // the actual text to draw
41 int x
= sidemargin
; // x coord for the text
43 // find a string that will fit inside the area for text
44 int max_length
= width() - sidemargin
* 2;
45 if (max_length
<= 0) {
46 t
= ""; // can't fit anything
48 size_t text_len
= t
.size();
53 length
= ft
.measureString(t
);
54 } while (length
> max_length
&& text_len
-- > 0);
57 switch (getStyle()->textJustify()) {
58 case Style::RightJustify
:
59 x
+= max_length
- length
;
61 case Style::CenterJustify
:
62 x
+= (max_length
- length
) / 2;
64 case Style::LeftJustify
:
71 ft
.drawString(_xftdraw
, x
, 0, *getStyle()->getTextUnfocus(), t
);
This page took 0.036645 seconds and 4 git commands to generate.