UFocusableUserWidget::NativeOnFocusReceived - call SetFocusProperly if not otherwise handled

This commit is contained in:
Steve Streeting 2024-06-25 15:03:28 +01:00
parent bd9c429aae
commit 7f1d0e9c0e
2 changed files with 15 additions and 0 deletions

View File

@ -27,6 +27,19 @@ bool UFocusableUserWidget::TakeFocusIfDesired_Implementation()
return false;
}
FReply UFocusableUserWidget::NativeOnFocusReceived(const FGeometry& InGeometry, const FFocusEvent& InFocusEvent)
{
FReply Reply = Super::NativeOnFocusReceived(InGeometry, InFocusEvent);
if (!Reply.IsEventHandled())
{
SetFocusProperly();
Reply.Handled();
}
return Reply;
}
void UFocusableUserWidget::NativeConstruct()
{
Super::NativeConstruct();

View File

@ -25,6 +25,8 @@ protected:
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Focus")
int AutomaticFocusPriority = 0;
virtual FReply NativeOnFocusReceived(const FGeometry& InGeometry, const FFocusEvent& InFocusEvent) override;
public:
/// UWidget::SetFocus is not virtual FFS. This does the same as SetFocus by default but can be overridden,
/// e.g. to delegate focus to specific children