mirror of
https://github.com/sinbad/StevesUEHelpers.git
synced 2025-02-23 09:35:25 +00:00
Unfocus on Unhover for Button and Checkbox
This commit is contained in:
parent
2fa1f35b83
commit
75f38faa81
@ -109,5 +109,28 @@ void UFocusableButton::SlateHandleHovered()
|
||||
|
||||
void UFocusableButton::SlateHandleUnhovered()
|
||||
{
|
||||
OnUnhovered.Broadcast();
|
||||
if (bLoseFocusOnUnhover)
|
||||
{
|
||||
Unfocus();
|
||||
}
|
||||
OnUnhovered.Broadcast();
|
||||
}
|
||||
|
||||
void UFocusableButton::Unfocus() const
|
||||
{
|
||||
APlayerController* OwningPlayer = GetOwningPlayer();
|
||||
if (OwningPlayer == nullptr || !OwningPlayer->IsLocalController() || OwningPlayer->Player ==
|
||||
nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (ULocalPlayer* LocalPlayer = OwningPlayer->GetLocalPlayer())
|
||||
{
|
||||
TOptional<int32> UserIndex = FSlateApplication::Get().GetUserIndexForController(
|
||||
LocalPlayer->GetControllerId());
|
||||
if (UserIndex.IsSet())
|
||||
{
|
||||
FSlateApplication::Get().ClearUserFocus(UserIndex.GetValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -95,5 +95,28 @@ void UFocusableCheckBox::SlateHandleHovered()
|
||||
|
||||
void UFocusableCheckBox::SlateHandleUnhovered()
|
||||
{
|
||||
OnUnhovered.Broadcast();
|
||||
if (bLoseFocusOnUnhover)
|
||||
{
|
||||
Unfocus();
|
||||
}
|
||||
OnUnhovered.Broadcast();
|
||||
}
|
||||
|
||||
void UFocusableCheckBox::Unfocus() const
|
||||
{
|
||||
APlayerController* OwningPlayer = GetOwningPlayer();
|
||||
if (OwningPlayer == nullptr || !OwningPlayer->IsLocalController() || OwningPlayer->Player ==
|
||||
nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (ULocalPlayer* LocalPlayer = OwningPlayer->GetLocalPlayer())
|
||||
{
|
||||
TOptional<int32> UserIndex = FSlateApplication::Get().GetUserIndexForController(
|
||||
LocalPlayer->GetControllerId());
|
||||
if (UserIndex.IsSet())
|
||||
{
|
||||
FSlateApplication::Get().ClearUserFocus(UserIndex.GetValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -38,6 +38,9 @@ public:
|
||||
UPROPERTY(BlueprintReadWrite, EditAnywhere)
|
||||
bool bTakeFocusOnHover = true;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, EditAnywhere)
|
||||
bool bLoseFocusOnUnhover = true;
|
||||
|
||||
// Simulate a button press
|
||||
UFUNCTION(BlueprintCallable)
|
||||
void SimulatePress();
|
||||
@ -56,6 +59,8 @@ protected:
|
||||
void SlateHandleHovered();
|
||||
void SlateHandleUnhovered();
|
||||
|
||||
void Unfocus() const;
|
||||
|
||||
virtual TSharedRef<SWidget> RebuildWidget() override;
|
||||
|
||||
|
||||
|
@ -43,6 +43,10 @@ public:
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, EditAnywhere)
|
||||
bool bTakeFocusOnHover = true;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, EditAnywhere)
|
||||
bool bLoseFocusOnUnhover = true;
|
||||
|
||||
protected:
|
||||
FCheckBoxStyle FocussedStyle;
|
||||
|
||||
@ -54,6 +58,8 @@ protected:
|
||||
void SlateHandleHovered();
|
||||
void SlateHandleUnhovered();
|
||||
|
||||
void Unfocus() const;
|
||||
|
||||
virtual TSharedRef<SWidget> RebuildWidget() override;
|
||||
|
||||
public:
|
||||
|
Loading…
x
Reference in New Issue
Block a user