5 OtkLabel::OtkLabel(OtkWidget *parent)
6 : OtkWidget(parent), _text(""), _dirty(false)
8 setTexture(getStyle()->getLabelUnfocus());
15 void OtkLabel::update(void)
18 const BFont &ft = getStyle()->getFont();
19 unsigned int bevel = getStyle()->getBevelWidth();
21 std::string t = _text; // the actual text to draw
22 int x = bevel; // x coord for the text
24 // find a string that will fit inside the area for text
25 int max_length = width() - getBevelWidth() * 2;
26 if (max_length <= 0) {
27 t = ""; // can't fit anything
29 size_t text_len = t.size();
34 length = ft.measureString(t);
35 } while (length > max_length && text_len-- > 0);
38 switch (getStyle()->textJustify()) {
39 case Style::RightJustify:
40 x += max_length - length;
42 case Style::CenterJustify:
43 x += (max_length - length) / 2;
45 case Style::LeftJustify:
52 ft.drawString(getWindow(), x, bevel, *getStyle()->getTextUnfocus(), t);
59 int OtkLabel::exposeHandler(const XExposeEvent &e)
62 return OtkWidget::exposeHandler(e);
65 int OtkLabel::configureHandler(const XConfigureEvent &e)
67 if (!(e.width == width() && e.height == height()))
69 return OtkWidget::configureHandler(e);