stuff-from-scratch/apps/notes_tk/canvas/CanvasCommandSelectorView.cpp
2023-01-23 11:55:58 +00:00

42 lines
1.1 KiB
C++

#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);
}
}