mirror of
https://github.com/sinbad/StevesUEHelpers.git
synced 2025-02-23 09:35:25 +00:00
Simulate button press / release
This commit is contained in:
parent
78d203e7c1
commit
d3045cc463
@ -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();
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user