ladybird/Widgets/Label.cpp

35 lines
699 B
C++

#include "Label.h"
#include "Painter.h"
#include <cstdio>
Label::Label(Widget* parent)
: Widget(parent)
{
}
Label::~Label()
{
}
void Label::setText(String&& text)
{
if (text == m_text)
return;
m_text = std::move(text);
update();
}
void Label::paintEvent(PaintEvent&)
{
Painter painter(*this);
painter.fillRect({ 0, 0, width(), height() }, backgroundColor());
if (!text().isEmpty())
painter.drawText({ 4, 4, width(), height() }, text(), Painter::TextAlignment::TopLeft, foregroundColor());
}
void Label::mouseMoveEvent(MouseEvent& event)
{
printf("Label::mouseMoveEvent: x=%d, y=%d\n", event.x(), event.y());
Widget::mouseMoveEvent(event);
}