diff --git a/Source/StevesUEHelpers/Private/StevesUI/FocusableButton.cpp b/Source/StevesUEHelpers/Private/StevesUI/FocusableButton.cpp index c7f7264..a5378cd 100644 --- a/Source/StevesUEHelpers/Private/StevesUI/FocusableButton.cpp +++ b/Source/StevesUEHelpers/Private/StevesUI/FocusableButton.cpp @@ -1,6 +1,7 @@ #include "StevesUI/FocusableButton.h" #include "StevesUI/SFocusableButton.h" #include "Components/ButtonSlot.h" +#include "Framework/Application/NavigationConfig.h" UFocusableButton::UFocusableButton(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer) @@ -43,6 +44,31 @@ void UFocusableButton::RefreshFocussedStyle_Implementation() FocussedStyle.Normal = FocussedStyle.Hovered; } +void UFocusableButton::SimulatePress() +{ + if (MyButton) + { + // In order to get the visual change we need to call SButton::Press() and SButton::Release(), but they're both private + // The only public method we can use to simulate the click properly is OnKeyDown/Up or OnMouseButtonDown/Up + // Use Virtual_Accept since that is general + FKeyEvent KeyEvent(EKeys::Virtual_Accept, FModifierKeysState(), 0, false, 0, 0); + MyButton->OnKeyDown(MyButton->GetCachedGeometry(), KeyEvent); + } +} + +void UFocusableButton::SimulateRelease() +{ + if (MyButton) + { + // In order to get the visual change we need to call SButton::Press() and SButton::Release(), but they're both private + // The only public method we can use to simulate the click properly is OnKeyDown/Up or OnMouseButtonDown/Up + // Use Virtual_Accept since that is general + FKeyEvent KeyEvent(EKeys::Virtual_Accept, FModifierKeysState(), 0, false, 0, 0); + MyButton->OnKeyUp(MyButton->GetCachedGeometry(), KeyEvent); + + } +} + void UFocusableButton::SlateHandleFocusReceived() { ApplyFocusStyle(); diff --git a/Source/StevesUEHelpers/Public/StevesUI/FocusableButton.h b/Source/StevesUEHelpers/Public/StevesUI/FocusableButton.h index 181a008..a6f610f 100644 --- a/Source/StevesUEHelpers/Public/StevesUI/FocusableButton.h +++ b/Source/StevesUEHelpers/Public/StevesUI/FocusableButton.h @@ -38,6 +38,12 @@ public: UPROPERTY(BlueprintReadWrite, EditAnywhere) bool bTakeFocusOnHover = true; + // Simulate a button press + UFUNCTION(BlueprintCallable) + void SimulatePress(); + // Simulate a button release + UFUNCTION(BlueprintCallable) + void SimulateRelease(); protected: FButtonStyle FocussedStyle;