]>
Dogcows Code - chaz/openbox/blob - otk/focuslabel.cc
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
4 # include "../config.h"
7 #include "focuslabel.hh"
9 #include "screeninfo.hh"
13 FocusLabel::FocusLabel(Widget
*parent
)
14 : FocusWidget(parent
), _text("")
18 FocusLabel::~FocusLabel()
23 void FocusLabel::setStyle(Style
*style
)
25 FocusWidget::setStyle(style
);
27 setTexture(style
->getLabelFocus());
28 setUnfocusTexture(style
->getLabelUnfocus());
32 void FocusLabel::update(void)
35 const Font
*ft
= style()->getFont();
36 Color
*text_color
= (isFocused() ? style()->getTextFocus()
37 : style()->getTextUnfocus());
38 unsigned int sidemargin
= style()->getBevelWidth() * 2;
40 ustring t
= _text
; // the actual text to draw
41 int x
= sidemargin
; // x coord for the text
43 // find a string that will fit inside the area for text
44 int max_length
= width() - sidemargin
* 2;
45 if (max_length
<= 0) {
46 t
= ""; // can't fit anything
48 size_t text_len
= t
.size();
53 length
= ft
->measureString(t
);
54 } while (length
> max_length
&& text_len
-- > 0);
57 switch (style()->textJustify()) {
58 case Style::RightJustify
:
59 x
+= max_length
- length
;
61 case Style::CenterJustify
:
62 x
+= (max_length
- length
) / 2;
64 case Style::LeftJustify
:
69 FocusWidget::update();
71 display
->renderControl(_screen
)->
72 drawString(this, *ft
, x
, 0, *text_color
, t
);
74 FocusWidget::update();
This page took 0.03812 seconds and 4 git commands to generate.