summaryrefslogtreecommitdiff
path: root/Widgets/Label.cpp
blob: 98937d62a1c74df76a1c30ac7b803b5f2240a7ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#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);
}