Set up stacked widget.
This commit is contained in:
parent
4e85edacc8
commit
ee51f3ee09
51 changed files with 808 additions and 195 deletions
|
@ -4,9 +4,10 @@
|
|||
Button::Button()
|
||||
: Widget(),
|
||||
mLabel(),
|
||||
mCachedColor(255, 255, 255),
|
||||
mClickFunc()
|
||||
{
|
||||
|
||||
mClickedColor = Color::Create(180, 180, 180);
|
||||
}
|
||||
|
||||
std::unique_ptr<Button> Button::Create()
|
||||
|
@ -28,15 +29,16 @@ void Button::OnMyMouseEvent(const MouseEvent* event)
|
|||
{
|
||||
if(event->GetAction() == MouseEvent::Action::Pressed)
|
||||
{
|
||||
SetBackgroundColor(Color::Create(0, 255, 0));
|
||||
mCachedColor = *mBackgroundColor;
|
||||
SetBackgroundColor(Color::Create(*mClickedColor));
|
||||
if(mClickFunc)
|
||||
{
|
||||
mClickFunc();
|
||||
mClickFunc(this);
|
||||
}
|
||||
}
|
||||
else if(event->GetAction() == MouseEvent::Action::Released)
|
||||
{
|
||||
SetBackgroundColor(Color::Create(0, 255, 255));
|
||||
SetBackgroundColor(Color::Create(mCachedColor));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -46,10 +48,13 @@ void Button::OnPaintEvent(const PaintEvent* event)
|
|||
AddBackground(event);
|
||||
if(!mLabel.empty())
|
||||
{
|
||||
auto middle = DiscretePoint(mLocation.GetX() + mWidth/2,
|
||||
mLocation.GetY() + mHeight/2);
|
||||
unsigned fontOffset = mLabel.size() * 4;
|
||||
auto middle = DiscretePoint(mLocation.GetX() + mSize.mWidth/2 - fontOffset,
|
||||
mLocation.GetY() + mSize.mHeight/2 + 4);
|
||||
auto textLayer = VisualLayer::Create();
|
||||
textLayer->SetText(TextElement::Create(mLabel, middle));
|
||||
auto textElement = TextElement::Create(mLabel, middle);
|
||||
textElement->SetFillColor(Color::Create(*mBackgroundColor));
|
||||
textLayer->SetText(std::move(textElement));
|
||||
mMyLayers.push_back(std::move(textLayer));
|
||||
}
|
||||
CopyMyLayers();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue