2019-01-20 01:49:48 -02:00
|
|
|
#include "GLabel.h"
|
2019-01-19 20:49:56 -02:00
|
|
|
#include <SharedGraphics/Painter.h>
|
2018-10-10 11:49:36 -03:00
|
|
|
|
2019-01-20 01:49:48 -02:00
|
|
|
GLabel::GLabel(GWidget* parent)
|
|
|
|
|
: GWidget(parent)
|
2018-10-10 11:49:36 -03:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-20 01:49:48 -02: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)
|
2018-10-10 15:06:58 -03:00
|
|
|
{
|
|
|
|
|
if (text == m_text)
|
|
|
|
|
return;
|
2019-01-10 20:19:29 -02:00
|
|
|
m_text = move(text);
|
2018-10-10 15:06:58 -03:00
|
|
|
update();
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-20 23:18:16 -02:00
|
|
|
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
|
|
|
}
|