#include "CanvasCommandSelectorView.h"

#include "HorizontalSpacer.h"
#include "Button.h"

#include "ThemeManager.h"
#include "PaintEvent.h"

CanvasCommandSelectorView::CanvasCommandSelectorView()
    : Widget()
{
    auto circle_button = Button::Create();

    auto on_circle_click = [this](Widget*){
        onCommandSelected(CanvasDrawCommand::CIRCLE);
    };
    circle_button->setLabel("Circle");
    circle_button->setMargin(2);
    circle_button->setOnClickFunction(on_circle_click);

    auto on_line_click = [this](Widget*){
        onCommandSelected(CanvasDrawCommand::LINE);
    };
    auto line_button = Button::Create();
    line_button->setLabel("Line");
    line_button->setMargin(2);
    line_button->setOnClickFunction(on_line_click);

    auto hspacer = HorizontalSpacer::Create();
    hspacer->addWidgetWithScale(std::move(circle_button), 1);
    hspacer->addWidgetWithScale(std::move(line_button), 1);

    addWidget(std::move(hspacer));
}

void CanvasCommandSelectorView::onCommandSelected(CanvasDrawCommand command)
{
    if(mCommandSelectedCallback)
    {
        mCommandSelectedCallback(command);
    }
}
