summaryrefslogtreecommitdiff
path: root/plugingui/label.cc
diff options
context:
space:
mode:
Diffstat (limited to 'plugingui/label.cc')
-rw-r--r--plugingui/label.cc58
1 files changed, 34 insertions, 24 deletions
diff --git a/plugingui/label.cc b/plugingui/label.cc
index bcc7005..f4a2cc1 100644
--- a/plugingui/label.cc
+++ b/plugingui/label.cc
@@ -27,43 +27,53 @@
#include "label.h"
#include "painter.h"
+#include "guievent.h"
-GUI::Label::Label(GUI::Widget *parent) : GUI::Widget(parent)
+namespace GUI {
+
+Label::Label(Widget *parent)
+ : Widget(parent)
{
}
-void GUI::Label::setText(std::string text)
+void Label::setText(const std::string& text)
{
- _text = text;
- repaintEvent(NULL);
+ _text = text;
+ repaintEvent(nullptr);
}
-void GUI::Label::repaintEvent(GUI::RepaintEvent *e)
+void Label::setAlignment(TextAlignment alignment)
{
- Painter p(this);
-
- p.clear();
-
- p.setColour(Colour(1));
+ this->alignment = alignment;
+}
- Font font(":fontemboss.png");
- p.drawText(10, (height() + font.textHeight()) / 2, font, _text, true);
+void Label::resizeToText()
+{
+ resize(font.textWidth(_text) + border, font.textHeight());
}
+void Label::repaintEvent(RepaintEvent* repaintEvent)
+{
+ Painter p(*this);
-#ifdef TEST_LABEL
-//Additional dependency files
-//deps:
-//Required cflags (autoconf vars may be used)
-//cflags:
-//Required link options (autoconf vars may be used)
-//libs:
-#include "test.h"
+ p.clear();
-TEST_BEGIN;
+ p.setColour(Colour(1));
-// TODO: Put some testcode here (see test.h for usable macros).
+ int offset = 0;
+ switch(alignment) {
+ case TextAlignment::left:
+ offset = border;
+ break;
+ case TextAlignment::center:
+ offset = (width() - font.textWidth(_text)) / 2;
+ break;
+ case TextAlignment::right:
+ offset = width() - font.textWidth(_text) - border;
+ break;
+ }
-TEST_END;
+ p.drawText(offset, (height() + font.textHeight()) / 2, font, _text, true);
+}
-#endif/*TEST_LABEL*/
+} // GUI::