1 #include "focuslabel.hh"
5 OtkFocusLabel::OtkFocusLabel(OtkWidget *parent)
6 : OtkFocusWidget(parent), _text("")
8 setTexture(getStyle()->getLabelFocus());
9 setUnfocusTexture(getStyle()->getLabelUnfocus());
12 OtkFocusLabel::~OtkFocusLabel()
16 void OtkFocusLabel::update(void)
19 const BFont &ft = getStyle()->getFont();
20 BColor *text_color = (isFocused() ? getStyle()->getTextFocus()
21 : getStyle()->getTextUnfocus());
22 unsigned int bevel = getStyle()->getBevelWidth();
24 std::string t = _text; // the actual text to draw
25 int x = bevel; // x coord for the text
27 // find a string that will fit inside the area for text
28 int max_length = width() - getBevelWidth() * 2;
29 if (max_length <= 0) {
30 t = ""; // can't fit anything
32 size_t text_len = t.size();
37 length = ft.measureString(t);
38 } while (length > max_length && text_len-- > 0);
41 switch (getStyle()->textJustify()) {
42 case Style::RightJustify:
43 x += max_length - length;
45 case Style::CenterJustify:
46 x += (max_length - length) / 2;
48 case Style::LeftJustify:
53 OtkFocusWidget::update();
55 ft.drawString(getWindow(), x, bevel, *text_color, t);
57 OtkFocusWidget::update();