]>
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 bevel
= getStyle()->getBevelWidth() / 2;
40 std::string t
= _text
; // the actual text to draw
41 int x
= bevel
; // x coord for the text
43 // find a string that will fit inside the area for text
44 int max_length
= width() - bevel
* 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
, bevel
, *getStyle()->getTextUnfocus(), t
);
This page took 0.042054 seconds and 4 git commands to generate.