ladybird/LibGUI/GLabel.cpp

29 lines
590 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
{
}
2019-01-21 00:46:08 +01:00
void GLabel::set_text(String&& text)
{
if (text == m_text)
return;
m_text = move(text);
update();
}
2019-01-21 00:46:08 +01:00
void GLabel::paint_event(GPaintEvent&)
2018-10-10 16:49:36 +02:00
{
Painter painter(*this);
2019-01-21 00:46:08 +01:00
if (fill_with_background_color())
painter.fill_rect({ 0, 0, width(), height() }, background_color());
2018-12-21 02:10:45 +01:00
if (!text().is_empty())
2019-01-21 00:46:08 +01:00
painter.draw_text({ 4, 4, width(), height() }, text(), Painter::TextAlignment::TopLeft, foreground_color());
2018-10-10 16:49:36 +02:00
}