ladybird/LibGUI/GLabel.cpp

29 lines
583 B
C++
Raw Normal View History

#include "GLabel.h"
2019-01-19 23:49:56 +01:00
#include <SharedGraphics/Painter.h>
2018-10-10 16:49:36 +02:00
GLabel::GLabel(GWidget* parent)
: GWidget(parent)
2018-10-10 16:49:36 +02:00
{
}
GLabel::~GLabel()
2018-10-10 16:49:36 +02:00
{
}
void GLabel::setText(String&& text)
{
if (text == m_text)
return;
m_text = move(text);
update();
}
void GLabel::paintEvent(GPaintEvent&)
2018-10-10 16:49:36 +02:00
{
Painter painter(*this);
if (fillWithBackgroundColor())
painter.fill_rect({ 0, 0, width(), height() }, backgroundColor());
2018-12-21 02:10:45 +01:00
if (!text().is_empty())
painter.draw_text({ 4, 4, width(), height() }, text(), Painter::TextAlignment::TopLeft, foregroundColor());
2018-10-10 16:49:36 +02:00
}