1 #include <lib/gui/elabel.h>
2 #include <lib/gdi/font.h>
4 eLabel::eLabel(eWidget *parent): eWidget(parent)
6 ePtr<eWindowStyle> style;
9 style->getFont(eWindowStyle::fontStatic, m_font);
11 /* default to topleft alignment */
15 m_have_foreground_color = 0;
18 int eLabel::event(int event, void *data, void *data2)
24 ePtr<eWindowStyle> style;
28 eWidget::event(event, data, data2);
30 gPainter &painter = *(gPainter*)data2;
31 painter.setFont(m_font);
32 style->setStyle(painter, eWindowStyle::styleLabel);
34 if (m_have_foreground_color)
35 painter.setForegroundColor(m_foreground_color);
38 if (m_valign == alignTop)
39 flags |= gPainter::RT_VALIGN_TOP;
40 else if (m_valign == alignCenter)
41 flags |= gPainter::RT_VALIGN_CENTER;
42 else if (m_valign == alignBottom)
43 flags |= gPainter::RT_VALIGN_BOTTOM;
45 if (m_halign == alignLeft)
46 flags |= gPainter::RT_HALIGN_LEFT;
47 else if (m_halign == alignCenter)
48 flags |= gPainter::RT_HALIGN_CENTER;
49 else if (m_halign == alignRight)
50 flags |= gPainter::RT_HALIGN_RIGHT;
51 else if (m_halign == alignBlock)
52 flags |= gPainter::RT_HALIGN_BLOCK;
54 flags |= gPainter::RT_WRAP;
55 painter.renderText(eRect(0, 0, size().width(), size().height()), m_text, flags);
61 case evtChangedAlignment:
65 return eWidget::event(event, data, data2);
69 void eLabel::setText(const std::string &string)
74 event(evtChangedText);
77 void eLabel::setFont(gFont *font)
80 event(evtChangedFont);
83 void eLabel::setVAlign(int align)
86 event(evtChangedAlignment);
89 void eLabel::setHAlign(int align)
92 event(evtChangedAlignment);
95 void eLabel::setForegroundColor(const gRGB &col)
97 m_foreground_color = col;
98 m_have_foreground_color = 1;
101 void eLabel::clearForegroundColor()
103 m_have_foreground_color = 0;
106 eSize eLabel::calculateSize()
108 ePtr<eTextPara> p = new eTextPara(eRect(0, 0, size().width(), size().height()));
111 p->renderString(m_text, RS_WRAP);
113 eRect bbox = p->getBoundBox();