]>
Dogcows Code - chaz/openbox/blob - src/labelwidget.cc
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 LabelWidget::LabelWidget(otk::Widget
*parent
, WidgetBase::WidgetType type
)
14 : otk::Widget(parent
),
20 LabelWidget::~LabelWidget()
25 void LabelWidget::setText(const otk::ustring
&text
)
32 void LabelWidget::setTextures()
35 setTexture(_style
->labelFocusBackground());
36 _text_color
= _style
->textFocusColor();
38 setTexture(_style
->labelUnfocusBackground());
39 _text_color
= _style
->textUnfocusColor();
44 void LabelWidget::setStyle(otk::RenderStyle
*style
)
46 otk::Widget::setStyle(style
);
48 _font
= style
->labelFont();
49 _sidemargin
= style
->bevelWidth() * 2;
50 _justify
= style
->labelTextJustify();
56 void LabelWidget::focus()
63 void LabelWidget::unfocus()
65 otk::Widget::unfocus();
70 void LabelWidget::renderForeground()
74 otk::Widget::renderForeground();
77 otk::ustring t
= _text
;
78 int x
= _sidemargin
; // x coord for the text
80 // find a string that will fit inside the area for text
81 int max_length
= width() - _sidemargin
* 2;
82 if (max_length
<= 0) {
83 t
= ""; // can't fit anything
85 size_t text_len
= t
.size();
90 length
= _font
->measureString(t
);
91 } while (length
> max_length
&& text_len
-- > 0);
95 case otk::RenderStyle::RightJustify
:
96 x
+= max_length
- length
;
98 case otk::RenderStyle::CenterJustify
:
99 x
+= (max_length
- length
) / 2;
101 case otk::RenderStyle::LeftJustify
:
106 otk::display
->renderControl(_screen
)->drawString
107 (*_surface
, *_font
, x
, 0, *_text_color
, t
);
112 void LabelWidget::adjust()
114 // nothing to adjust. no children.
This page took 0.036186 seconds and 4 git commands to generate.