]>
Dogcows Code - chaz/openbox/blob - src/labelwidget.cc
9ff45298a834f59a5bcc4f17c91169f217e33b5f
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
5 # include "../config.h"
8 #include "otk/screeninfo.hh"
9 #include "otk/display.hh"
10 #include "labelwidget.hh"
14 LabelWidget::LabelWidget(otk::Widget
*parent
, WidgetBase::WidgetType type
)
15 : otk::Widget(parent
),
18 const otk::ScreenInfo
*info
= otk::Display::screenInfo(_screen
);
19 _xftdraw
= XftDrawCreate(otk::Display::display
, _window
, info
->visual(),
24 LabelWidget::~LabelWidget()
26 XftDrawDestroy(_xftdraw
);
30 void LabelWidget::setText(const std::string
&text
)
37 void LabelWidget::setTextures()
40 setTexture(_style
->getLabelFocus());
41 _text_color
= _style
->getTextFocus();
43 setTexture(_style
->getLabelUnfocus());
44 _text_color
= _style
->getTextUnfocus();
49 void LabelWidget::setStyle(otk::Style
*style
)
51 otk::Widget::setStyle(style
);
53 _font
= style
->getFont();
55 _sidemargin
= style
->getBevelWidth() * 2;
56 _justify
= style
->textJustify();
60 void LabelWidget::focus()
67 void LabelWidget::unfocus()
69 otk::Widget::unfocus();
74 void LabelWidget::update()
78 otk::Widget::update();
81 std::string t
= _text
;
82 int x
= _sidemargin
; // x coord for the text
84 // find a string that will fit inside the area for text
85 int max_length
= width() - _sidemargin
* 2;
86 if (max_length
<= 0) {
87 t
= ""; // can't fit anything
89 size_t text_len
= t
.size();
94 length
= _font
->measureString(t
);
95 } while (length
> max_length
&& text_len
-- > 0);
99 case otk::Style::RightJustify
:
100 x
+= max_length
- length
;
102 case otk::Style::CenterJustify
:
103 x
+= (max_length
- length
) / 2;
105 case otk::Style::LeftJustify
:
110 _font
->drawString(_xftdraw
, x
, 0, *_text_color
, t
);
115 void LabelWidget::adjust()
117 // nothing to adjust. no children.
This page took 0.042503 seconds and 3 git commands to generate.