stuff-from-scratch/apps/notes_tk/canvas/CanvasCommandSelectorView.cpp

45 lines
1.2 KiB
C++
Raw Normal View History

2022-12-05 10:59:45 +00:00
#include "CanvasCommandSelectorView.h"
#include "HorizontalSpacer.h"
#include "Button.h"
2023-01-17 13:01:59 +00:00
#include "ThemeManager.h"
#include "PaintEvent.h"
2022-12-05 10:59:45 +00:00
CanvasCommandSelectorView::CanvasCommandSelectorView()
: Widget()
{
auto circle_button = Button::Create();
auto on_circle_click = [this](Widget* self){
onCommandSelected(CanvasDrawCommand::CIRCLE);
};
circle_button->setLabel("Circle");
2023-01-17 13:01:59 +00:00
circle_button->setBackground(ThemeToken::SystemToken::Primary);
2022-12-05 10:59:45 +00:00
circle_button->setMargin(2);
circle_button->setOnClickFunction(on_circle_click);
auto on_line_click = [this](Widget* self){
onCommandSelected(CanvasDrawCommand::LINE);
};
auto line_button = Button::Create();
line_button->setLabel("Line");
2023-01-17 13:01:59 +00:00
line_button->setBackground(ThemeToken::SystemToken::Primary);
2022-12-05 10:59:45 +00:00
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);
}
}