#include "Label.h"

#include "TextElement.h"
#include "GeometryElement.h"
#include "VisualLayer.h"

Label::Label()
    : Widget(),
      mLabel()
{

}

std::unique_ptr<Label> Label::Create()
{
    return std::make_unique<Label>();
}

void Label::SetLabel(const std::string& text)
{
    mLabel = text;
}

void Label::OnPaintEvent(const PaintEvent* event)
{
    mMyLayers.clear();
    AddBackground(event);

    if(!mLabel.empty())
    {
        unsigned fontOffset = unsigned(mLabel.size()) * 4;
        auto middle = DiscretePoint(mLocation.GetX() + mSize.mWidth/2 - fontOffset,
                mLocation.GetY() + mSize.mHeight/2 + 4);
        auto textLayer = VisualLayer::Create();
        auto textElement = TextElement::Create(mLabel, middle);
        textElement->SetFillColor(Color::Create(*mBackgroundColor));
        textLayer->SetText(std::move(textElement));
        mMyLayers.push_back(std::move(textLayer));
    }
    CopyMyLayers();
}
