#include <Widget/Layout/Frame/Frame.hpp>

Frame::Frame(Widget *child) : Layout(child), color(Color::frameBackground) {}
Frame::Frame(glm::vec4 color, Widget *child) : Layout(child), color(color) {}

Frame* Frame::withMargin(int margin)
{
    this->margin = margin;
    return this;
}

void Frame::layout()
{
    ChildNode &childNode = m_children.back();
    childNode.pos = glm::ivec2(margin);
    childNode.widget->onResize(m_size - glm::ivec2(2*margin));
}

glm::ivec2 Frame::getMinSize()
{
    return m_children.back().widget->getMinSize() + glm::ivec2(2*margin);
}

void Frame::draw(GraphicsContext &context)
{
    context.color = color;
    context.drawRect(0, 0, m_size[0], m_size[1]);

    Layout::draw(context);
}