Move windows to uptr. Add simple text editing.

This commit is contained in:
jmsgrogan 2020-06-20 16:34:10 +01:00
parent 2bcc7b3d83
commit b99708e7d3
55 changed files with 1257 additions and 994 deletions

View file

@ -2,43 +2,42 @@
#include <iostream>
Button::Button()
: Widget(),
mLabel()
: Widget(),
mLabel()
{
}
std::shared_ptr<Button> Button::Create()
std::unique_ptr<Button> Button::Create()
{
return std::make_shared<Button>();
return std::make_unique<Button>();
}
void Button::SetLabel(const std::string& text)
{
mLabel = text;
mLabel = text;
}
void Button::OnMyMouseEvent(MouseEventPtr event)
void Button::OnMyMouseEvent(const MouseEvent* event)
{
if(event->GetAction() == MouseEvent::Action::Pressed)
{
std::cout << "Clicked !!" << std::endl;
SetBackgroundColor(Color::Create(0, 255, 0));
}
if(event->GetAction() == MouseEvent::Action::Pressed)
{
std::cout << "Clicked !!" << std::endl;
SetBackgroundColor(Color::Create(0, 255, 0));
}
}
void Button::OnPaintEvent(PaintEventPtr event)
void Button::OnPaintEvent(const PaintEvent* event)
{
mLayers.clear();
AddBackground(event);
if(!mLabel.empty())
{
auto middle = DiscretePoint(mLocation.GetX() + mWidth/2,
mLocation.GetY() + mHeight/2);
auto text = TextElement::Create(mLabel, middle);
auto textLayer = VisualLayer::Create();
textLayer->SetText(text);
mLayers.push_back(textLayer);
}
mMyLayers.clear();
AddBackground(event);
if(!mLabel.empty())
{
auto middle = DiscretePoint(mLocation.GetX() + mWidth/2,
mLocation.GetY() + mHeight/2);
auto textLayer = VisualLayer::Create();
textLayer->SetText(TextElement::Create(mLabel, middle));
mMyLayers.push_back(std::move(textLayer));
}
CopyMyLayers();
}