GLabel.cpp 583 B

12345678910111213141516171819202122232425262728
  1. #include "GLabel.h"
  2. #include <SharedGraphics/Painter.h>
  3. GLabel::GLabel(GWidget* parent)
  4. : GWidget(parent)
  5. {
  6. }
  7. GLabel::~GLabel()
  8. {
  9. }
  10. void GLabel::setText(String&& text)
  11. {
  12. if (text == m_text)
  13. return;
  14. m_text = move(text);
  15. update();
  16. }
  17. void GLabel::paintEvent(GPaintEvent&)
  18. {
  19. Painter painter(*this);
  20. if (fillWithBackgroundColor())
  21. painter.fill_rect({ 0, 0, width(), height() }, backgroundColor());
  22. if (!text().is_empty())
  23. painter.draw_text({ 4, 4, width(), height() }, text(), Painter::TextAlignment::TopLeft, foregroundColor());
  24. }