]>
Dogcows Code - chaz/openbox/blob - otk/label.cc
24cf84028ea0f5f31dc261dd0896bd75e79384d7
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(),
18 setTexture(getStyle()->getLabelUnfocus());
23 XftDrawDestroy(_xftdraw
);
26 void OtkLabel::update(void)
29 const BFont
&ft
= getStyle()->getFont();
30 unsigned int bevel
= getStyle()->getBevelWidth() / 2;
32 std::string t
= _text
; // the actual text to draw
33 int x
= bevel
; // x coord for the text
35 // find a string that will fit inside the area for text
36 int max_length
= width() - bevel
* 2;
37 if (max_length
<= 0) {
38 t
= ""; // can't fit anything
40 size_t text_len
= t
.size();
45 length
= ft
.measureString(t
);
46 } while (length
> max_length
&& text_len
-- > 0);
49 switch (getStyle()->textJustify()) {
50 case Style::RightJustify
:
51 x
+= max_length
- length
;
53 case Style::CenterJustify
:
54 x
+= (max_length
- length
) / 2;
56 case Style::LeftJustify
:
63 ft
.drawString(_xftdraw
, x
, bevel
, *getStyle()->getTextUnfocus(), t
);
This page took 0.034554 seconds and 4 git commands to generate.