ladybird/LibGUI/GLabel.cpp

29 lines
596 B
C++
Raw Normal View History

#include "GLabel.h"
2019-01-19 20:49:56 -02:00
#include <SharedGraphics/Painter.h>
2018-10-10 11:49:36 -03:00
GLabel::GLabel(GWidget* parent)
: GWidget(parent)
2018-10-10 11:49:36 -03:00
{
}
GLabel::~GLabel()
2018-10-10 11:49:36 -03:00
{
}
2019-01-20 21:46:08 -02:00
void GLabel::set_text(String&& text)
{
if (text == m_text)
return;
m_text = move(text);
update();
}
void GLabel::paint_event(GPaintEvent& event)
2018-10-10 11:49:36 -03:00
{
Painter painter(*this);
2019-01-20 21:46:08 -02:00
if (fill_with_background_color())
painter.fill_rect({ 0, 0, width(), height() }, background_color());
2018-12-20 23:10:45 -02:00
if (!text().is_empty())
2019-01-20 21:46:08 -02:00
painter.draw_text({ 4, 4, width(), height() }, text(), Painter::TextAlignment::TopLeft, foreground_color());
2018-10-10 11:49:36 -03:00
}