#include "label.h"

using namespace genv;
using namespace std;

void label::init()
{
    marginLeft = 10; marginTop = 10;
    visible = true;
    background = false;
    fontColor.setValue(black);
    backgroundColor.setValue(backgroundColor);
    align = align_left;
    tabStop = false;
}

label::label(float x0, float y0, float width0, float height0) : widget(x0, y0, width0, height0)
{
    init();
    Text = "Label";
}

label::label(float x0, float y0, float width0, float height0, string txt) : widget(x0, y0, width0, height0)
{
    init();
    Text = txt;
}

void label::setText(string txt) { Text = txt; }
string label::getText() const { return Text; }

void label::draw() const
{
    if (visible)
    {
        if (background)
        {
            colorize(backgroundColor);
            gout << move_to(x,y) << box(width, height);
        }
        colorize(fontColor);
        if (align == align_left)
        {
            genv::gout << move_to(x + marginLeft, y + marginTop + genv::gout.cascent()) << genv::text(Text);
        }
    }
}

void label::setMargin(float mL, float mT)
{
    marginLeft = mL;
    marginTop = mT;
}
