mirror of
https://github.com/sinbad/StevesUEHelpers.git
synced 2025-02-23 09:35:25 +00:00
Merge pull request #17 from emistorrs/LoseFocusOnUnhover
Unfocus on Unhover for FocusableButton and FocusableCheckbox
This commit is contained in:
commit
2ecc91f554
@ -109,5 +109,35 @@ void UFocusableButton::SlateHandleHovered()
|
|||||||
|
|
||||||
void UFocusableButton::SlateHandleUnhovered()
|
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())
|
||||||
|
{
|
||||||
|
TSharedPtr<SWidget> SafeWidget = GetCachedWidget();
|
||||||
|
if (SafeWidget.IsValid())
|
||||||
|
{
|
||||||
|
if (SafeWidget->HasUserFocus(UserIndex.GetValue()))
|
||||||
|
{
|
||||||
|
FSlateApplication::Get().ClearUserFocus(UserIndex.GetValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -95,5 +95,35 @@ void UFocusableCheckBox::SlateHandleHovered()
|
|||||||
|
|
||||||
void UFocusableCheckBox::SlateHandleUnhovered()
|
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())
|
||||||
|
{
|
||||||
|
TSharedPtr<SWidget> SafeWidget = GetCachedWidget();
|
||||||
|
if (SafeWidget.IsValid())
|
||||||
|
{
|
||||||
|
if (SafeWidget->HasUserFocus(UserIndex.GetValue()))
|
||||||
|
{
|
||||||
|
FSlateApplication::Get().ClearUserFocus(UserIndex.GetValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,9 @@ public:
|
|||||||
UPROPERTY(BlueprintReadWrite, EditAnywhere)
|
UPROPERTY(BlueprintReadWrite, EditAnywhere)
|
||||||
bool bTakeFocusOnHover = true;
|
bool bTakeFocusOnHover = true;
|
||||||
|
|
||||||
|
UPROPERTY(BlueprintReadWrite, EditAnywhere)
|
||||||
|
bool bLoseFocusOnUnhover = true;
|
||||||
|
|
||||||
// Simulate a button press
|
// Simulate a button press
|
||||||
UFUNCTION(BlueprintCallable)
|
UFUNCTION(BlueprintCallable)
|
||||||
void SimulatePress();
|
void SimulatePress();
|
||||||
@ -56,6 +59,8 @@ protected:
|
|||||||
void SlateHandleHovered();
|
void SlateHandleHovered();
|
||||||
void SlateHandleUnhovered();
|
void SlateHandleUnhovered();
|
||||||
|
|
||||||
|
void Unfocus() const;
|
||||||
|
|
||||||
virtual TSharedRef<SWidget> RebuildWidget() override;
|
virtual TSharedRef<SWidget> RebuildWidget() override;
|
||||||
|
|
||||||
|
|
||||||
|
@ -43,6 +43,10 @@ public:
|
|||||||
|
|
||||||
UPROPERTY(BlueprintReadWrite, EditAnywhere)
|
UPROPERTY(BlueprintReadWrite, EditAnywhere)
|
||||||
bool bTakeFocusOnHover = true;
|
bool bTakeFocusOnHover = true;
|
||||||
|
|
||||||
|
UPROPERTY(BlueprintReadWrite, EditAnywhere)
|
||||||
|
bool bLoseFocusOnUnhover = true;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
FCheckBoxStyle FocussedStyle;
|
FCheckBoxStyle FocussedStyle;
|
||||||
|
|
||||||
@ -54,6 +58,8 @@ protected:
|
|||||||
void SlateHandleHovered();
|
void SlateHandleHovered();
|
||||||
void SlateHandleUnhovered();
|
void SlateHandleUnhovered();
|
||||||
|
|
||||||
|
void Unfocus() const;
|
||||||
|
|
||||||
virtual TSharedRef<SWidget> RebuildWidget() override;
|
virtual TSharedRef<SWidget> RebuildWidget() override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user