Add widget state support.
This commit is contained in:
parent
19091a0e80
commit
8536908eab
19 changed files with 385 additions and 46 deletions
|
@ -42,22 +42,79 @@ void Button::setLabel(const std::string& text)
|
|||
}
|
||||
}
|
||||
|
||||
void Button::setState(ButtonData::State state)
|
||||
{
|
||||
if (mStyle.mState != state)
|
||||
{
|
||||
mStyle.mState = state;
|
||||
mStateDirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Button::setEnabled(bool isEnabled)
|
||||
{
|
||||
if (mEnabled != isEnabled)
|
||||
{
|
||||
mEnabled = isEnabled;
|
||||
if (mStyle.mState == ButtonData::State::Disabled)
|
||||
{
|
||||
setState(ButtonData::State::Enabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Button::updateState()
|
||||
{
|
||||
setBackground(mStyle.getContainerColor());
|
||||
|
||||
}
|
||||
|
||||
void Button::onMyMouseEvent(const MouseEvent* event)
|
||||
{
|
||||
MLOG_INFO("Widget mouse event");
|
||||
if(event->getAction() == MouseEvent::Action::Pressed)
|
||||
if (!mEnabled)
|
||||
{
|
||||
mStyle.mState = ButtonData::State::Pressed;
|
||||
setBackground(mStyle.getContainerColor());
|
||||
if(mClickFunc)
|
||||
return;
|
||||
}
|
||||
|
||||
if (event->getAction() == MouseEvent::Action::Pressed)
|
||||
{
|
||||
setState(ButtonData::State::Pressed);
|
||||
}
|
||||
else if (event->getAction() == MouseEvent::Action::Released)
|
||||
{
|
||||
resetState();
|
||||
if (mClickFunc)
|
||||
{
|
||||
mClickFunc(this);
|
||||
}
|
||||
}
|
||||
else if(event->getAction() == MouseEvent::Action::Released)
|
||||
else if (event->getAction() == MouseEvent::Action::Enter)
|
||||
{
|
||||
mStyle.mState = ButtonData::State::Enabled;
|
||||
setBackground(mStyle.getContainerColor());
|
||||
resetState();
|
||||
}
|
||||
else if (event->getAction() == MouseEvent::Action::Leave)
|
||||
{
|
||||
resetState();
|
||||
}
|
||||
}
|
||||
|
||||
void Button::resetState()
|
||||
{
|
||||
if (mHasFocus)
|
||||
{
|
||||
setState(ButtonData::State::Focused);
|
||||
}
|
||||
else if (mContainsMouse)
|
||||
{
|
||||
setState(ButtonData::State::Hovered);
|
||||
}
|
||||
else if (mEnabled)
|
||||
{
|
||||
setState(ButtonData::State::Enabled);
|
||||
}
|
||||
else
|
||||
{
|
||||
setState(ButtonData::State::Disabled);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue