#include <algorithm>

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

PotView::PotView(uint32_t &temperature, Widget *child) :
    Layout(child),
    m_temperature(temperature)
{}

void PotView::layout()
{
    ChildNode &childNode = *m_children.begin();
    childNode.pos = glm::ivec2(0, 0);
    childNode.widget->onResize(childNode.widget->getMinSize());
}

glm::ivec2 PotView::getMinSize()
{
    ChildNode &childNode = *m_children.begin();
    return childNode.widget->getMinSize();
}

void PotView::draw(GraphicsContext &context)
{
    context.color = glm::vec4(1.0f);
    
    int spriteIndex = std::max(0, std::min(3, (int) m_temperature/1000));
    context.drawMaterial(
        Material::potTemperature,
        16*spriteIndex, 0,
        16, 16,
        2, m_size[1]-17,
        16, 16
    );

    Layout::draw(context);
}