mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Add focused styling to buttons (#13414)
This commit is contained in:
parent
2a1bc82887
commit
9d1ae80e89
7 changed files with 31 additions and 8 deletions
|
@ -200,6 +200,7 @@ bool GUIButton::OnEvent(const SEvent& event)
|
|||
// mouse is outside of the formspec. Thus, we test the position here.
|
||||
if ( !IsPushButton && AbsoluteClippingRect.isPointInside(
|
||||
core::position2d<s32>(event.MouseInput.X, event.MouseInput.Y ))) {
|
||||
Environment->setFocus(this);
|
||||
setPressed(true);
|
||||
}
|
||||
|
||||
|
@ -258,8 +259,10 @@ void GUIButton::draw()
|
|||
// PATCH
|
||||
// Track hovered state, if it has changed then we need to update the style.
|
||||
bool hovered = isHovered();
|
||||
if (hovered != WasHovered) {
|
||||
bool focused = isFocused();
|
||||
if (hovered != WasHovered || focused != WasFocused) {
|
||||
WasHovered = hovered;
|
||||
WasFocused = focused;
|
||||
setFromState();
|
||||
}
|
||||
|
||||
|
@ -387,7 +390,7 @@ EGUI_BUTTON_IMAGE_STATE GUIButton::getImageState(bool pressed, const ButtonImage
|
|||
{
|
||||
// figure state we should have
|
||||
EGUI_BUTTON_IMAGE_STATE state = EGBIS_IMAGE_DISABLED;
|
||||
bool focused = Environment->hasFocus((IGUIElement*)this);
|
||||
bool focused = isFocused();
|
||||
bool mouseOver = isHovered();
|
||||
if (isEnabled())
|
||||
{
|
||||
|
@ -582,6 +585,12 @@ bool GUIButton::isHovered() const
|
|||
IGUIElement *hovered = Environment->getHovered();
|
||||
return hovered == this || (hovered != nullptr && hovered->getParent() == this);
|
||||
}
|
||||
|
||||
//! Returns if this element (or one of its direct children) is focused
|
||||
bool GUIButton::isFocused() const
|
||||
{
|
||||
return Environment->hasFocus((IGUIElement*)this, true);
|
||||
}
|
||||
// END PATCH
|
||||
|
||||
//! Sets the pressed state of the button if this is a pushbutton
|
||||
|
@ -662,6 +671,9 @@ void GUIButton::setFromState()
|
|||
if (isHovered())
|
||||
state = static_cast<StyleSpec::State>(state | StyleSpec::STATE_HOVERED);
|
||||
|
||||
if (isFocused())
|
||||
state = static_cast<StyleSpec::State>(state | StyleSpec::STATE_FOCUSED);
|
||||
|
||||
setFromStyle(StyleSpec::getStyleFromStatePropagation(Styles, state));
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue