UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
NavigationMethodProximity.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "Input/HittestGrid.h"
7
8#include "NavigationMethodProximity.generated.h"
9
10USTRUCT(DisplayName="Proximity")
12{
14
15public:
16 TSharedPtr<SWidget> FindNextFocusableWidget(const FArrangedWidget& StartingWidget, const EUINavigation Direction, const FNavigationReply& NavigationReply, const FArrangedWidget& RuleWidget, int32 InUserIndex) override;
17
19
20private:
22 UPROPERTY(EditAnywhere, Category = Navigation, meta = (ClampMin = "0.0", ClampMax = "2.0"))
23 float AlignmentFactor = 1.0f;
24
26 UPROPERTY(EditAnywhere, Category = Navigation, meta = (ClampMin = "0.0", ClampMax = "90.0", Units = "Degrees"))
27 float SearchAngleDegrees = 45.0f;
28
30 UPROPERTY(EditAnywhere, Category = Navigation, meta = (ClampMin = "0.0"))
31 float OverlapThreshold = 20.0f;
32
33private:
34
35 struct FCellSearchInfo
36 {
37 FCellSearchInfo(const FNavigationMethodProximity* NavigationMethod, const FSlateRect& CurrentSearchRect, const FVector2f& SamplePoint, bool bWrapped)
38 : NavigationMethod(NavigationMethod)
39 , CurrentSearchRect(CurrentSearchRect)
40 , CurrentCellPoint(FMath::RoundToInt(SamplePoint.X), FMath::RoundToInt(SamplePoint.Y))
41 , StartingCellPoint(FMath::RoundToInt(SamplePoint.X), FMath::RoundToInt(SamplePoint.Y))
42 , bWrapped(bWrapped)
43 {}
44
45 const FNavigationMethodProximity* NavigationMethod;
46 FSlateRect CurrentSearchRect;
47 FIntPoint CurrentCellPoint;
48 FIntPoint StartingCellPoint;
49 bool bWrapped : 1 ;
50 };
51
52 enum class ECellSearchResultAction
53 {
54 ContinueSearch,
55 EndSearch,
56 ApplyBoundaryRule
57 };
58
59 struct FCellSearchResult
60 {
62 FSlateRect WidgetRect;
63 FSlateRect SearchRect;
64 float Distance = FLT_MAX;
65 ECellSearchResultAction Action;
66 };
67
68 TSharedPtr<SWidget> FindFocusableWidgetFromRect(const FSlateRect WidgetRect, const FSlateRect BoundaryRect, const EUINavigation Direction, const FNavigationReply& NavigationReply, int32 UserIndex);
69 FCellSearchResult FindBestWidgetInCell(const FCellSearchInfo& SearchInfo, const FSlateRect BoundaryRect, const EUINavigation Direction, const FNavigationReply& NavigationReply, int32 UserIndex);
70 void HandleBoundaryRule(const FSlateRect SourceRect, const FSlateRect BoundaryRect, const EUINavigation Direction, const FNavigationReply& NavigationReply, FCellSearchResult& OutCellResult, FCellSearchInfo& SearchInfo, TArray<FCellSearchInfo>& OutCellsToSearch);
71 void PopulateCellsToSearch(const FSlateRect& SourceRect, EUINavigation Direction, bool bWrapped, TArray<FCellSearchInfo>& OutCellsToSearch);
72
73 void CalculateSamplePoints(EUINavigation Direction, const FSlateRect& SourceRect, const FSlateRect& DestinationRect, FVector2f& OutSourcePoint, FVector2f& OutDestinationPoint) const;
74 float CalculateDistance(EUINavigation Direction, const FSlateRect& SourceRect, const FSlateRect& DestinationRect) const;
75
76 FVector2f GetSearchDirection(const EUINavigation Direction) const;
77 void GetSearchPoints(const EUINavigation Direction, const FSlateRect& SourceRect, FVector2f& OutCellSearchPointMin, FVector2f& OutCellSearchPointMax) const;
78 float GetSearchDirectionRadians(EUINavigation Direction) const;
79
80 bool IsOutsideNavigationEdge(const EUINavigation Direction, const FSlateRect& SourceRect, const FSlateRect& DestinationRect) const;
81 FSlateRect WrapRectWithinBoundary(const EUINavigation Direction, const FSlateRect& BoundaryRect, const FSlateRect& SourceRect) const;
82
83 TSet<SWidget*> VisitedWidgets;
84
85private:
86#if WITH_SLATE_DEBUGGING
87
88 struct FDrawDebugData
89 {
91 TArray<float> Distances;
92 TArray<FVector2f> Points;
94 };
95
97
100 void DebugSearchCell(const FCellSearchInfo& Cell);
101 void DrawDebug(int32 InLayer, const FGeometry& AllottedGeometry, FSlateWindowElementList& WindowElementList);
102
103#endif //WITH_SLATE_DEBUGGING
104};
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define UPROPERTY(...)
UObject definition macros.
Definition ObjectMacros.h:744
#define GENERATED_BODY(...)
Definition ObjectMacros.h:765
#define USTRUCT(...)
Definition ObjectMacros.h:746
EUINavigation
Definition SlateEnums.h:99
Definition ArrangedWidget.h:18
Definition HittestGrid.h:30
Definition NavigationReply.h:43
Definition SlateRect.h:26
Definition DrawElements.h:220
Definition Array.h:670
Definition SharedPointer.h:692
Definition Geometry.h:40
Definition NavigationMethodProximity.h:12
Definition NavigationMethod.h:12
Definition IntPoint.h:25