Add some widget layout and ability event handling.

This commit is contained in:
jmsgrogan 2020-06-20 19:00:06 +01:00
parent b99708e7d3
commit 4e85edacc8
24 changed files with 285 additions and 31 deletions

View file

@ -3,7 +3,8 @@
Button::Button()
: Widget(),
mLabel()
mLabel(),
mClickFunc()
{
}
@ -13,6 +14,11 @@ std::unique_ptr<Button> Button::Create()
return std::make_unique<Button>();
}
void Button::SetOnClickFunction(clickFunc func)
{
mClickFunc = func;
}
void Button::SetLabel(const std::string& text)
{
mLabel = text;
@ -22,8 +28,15 @@ void Button::OnMyMouseEvent(const MouseEvent* event)
{
if(event->GetAction() == MouseEvent::Action::Pressed)
{
std::cout << "Clicked !!" << std::endl;
SetBackgroundColor(Color::Create(0, 255, 0));
if(mClickFunc)
{
mClickFunc();
}
}
else if(event->GetAction() == MouseEvent::Action::Released)
{
SetBackgroundColor(Color::Create(0, 255, 255));
}
}