]>
Dogcows Code - chaz/openbox/blob - labelwidget.cc
5a33cf3dd0bfdf78e857d74ee587504b8c78ee76
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
4 # include "../config.h"
7 #include "otk/screeninfo.hh"
8 #include "otk/display.hh"
9 #include "labelwidget.hh"
13 OBLabelWidget::OBLabelWidget(otk::OtkWidget
*parent
, OBWidget::WidgetType type
)
14 : otk::OtkWidget(parent
),
17 const otk::ScreenInfo
*info
= otk::OBDisplay::screenInfo(_screen
);
18 _xftdraw
= XftDrawCreate(otk::OBDisplay::display
, _window
, info
->visual(),
23 OBLabelWidget::~OBLabelWidget()
25 XftDrawDestroy(_xftdraw
);
29 void OBLabelWidget::setText(const std::string
&text
)
36 void OBLabelWidget::setTextures()
39 setTexture(_style
->getLabelFocus());
40 _text_color
= _style
->getTextFocus();
42 setTexture(_style
->getLabelUnfocus());
43 _text_color
= _style
->getTextUnfocus();
48 void OBLabelWidget::setStyle(otk::Style
*style
)
50 OtkWidget::setStyle(style
);
52 _font
= style
->getFont();
54 _sidemargin
= style
->getBevelWidth() * 2;
55 _justify
= style
->textJustify();
59 void OBLabelWidget::focus()
61 otk::OtkWidget::focus();
66 void OBLabelWidget::unfocus()
68 otk::OtkWidget::unfocus();
73 void OBLabelWidget::update()
76 std::string t
= _text
;
77 int x
= _sidemargin
; // x coord for the text
79 // find a string that will fit inside the area for text
80 int max_length
= width() - _sidemargin
* 2;
81 if (max_length
<= 0) {
82 t
= ""; // can't fit anything
84 size_t text_len
= t
.size();
89 length
= _font
->measureString(t
);
90 } while (length
> max_length
&& text_len
-- > 0);
94 case otk::Style::RightJustify
:
95 x
+= max_length
- length
;
97 case otk::Style::CenterJustify
:
98 x
+= (max_length
- length
) / 2;
100 case otk::Style::LeftJustify
:
107 _font
->drawString(_xftdraw
, x
, 0, *_text_color
, t
);
113 void OBLabelWidget::adjust()
This page took 0.039804 seconds and 3 git commands to generate.