]> Dogcows Code - chaz/openbox/blob - otk/label.cc
add an OtkAppWidget which are "root windows", i.e. the managed child of root, to...
[chaz/openbox] / otk / label.cc
1 #include "label.hh"
2
3 namespace otk {
4
5 OtkLabel::OtkLabel(OtkWidget *parent)
6 : OtkWidget(parent), _text("")
7 {
8 setTexture(getStyle()->getLabelUnfocus());
9 }
10
11 OtkLabel::~OtkLabel()
12 {
13 }
14
15 void OtkLabel::update(void)
16 {
17 if (_dirty) {
18 const BFont &ft = getStyle()->getFont();
19 unsigned int bevel = getStyle()->getBevelWidth();
20
21 std::string t = _text; // the actual text to draw
22 int x = bevel; // x coord for the text
23
24 // find a string that will fit inside the area for text
25 int max_length = width() - getBevelWidth() * 2;
26 if (max_length <= 0) {
27 t = ""; // can't fit anything
28 } else {
29 size_t text_len = t.size();
30 int length;
31
32 do {
33 t.resize(text_len);
34 length = ft.measureString(t);
35 } while (length > max_length && text_len-- > 0);
36
37 // justify the text
38 switch (getStyle()->textJustify()) {
39 case Style::RightJustify:
40 x += max_length - length;
41 break;
42 case Style::CenterJustify:
43 x += (max_length - length) / 2;
44 break;
45 case Style::LeftJustify:
46 break;
47 }
48 }
49
50 OtkWidget::update();
51
52 ft.drawString(getWindow(), x, bevel, *getStyle()->getTextUnfocus(), t);
53 } else
54 OtkWidget::update();
55 }
56
57 }
This page took 0.036322 seconds and 4 git commands to generate.