UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
SlateRect.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
6#include "Layout/Margin.h"
8
26{
27public:
28
29 float Left;
30 float Top;
31 float Right;
32 float Bottom;
33
34 explicit FSlateRect( float InLeft = -1, float InTop = -1, float InRight = -1, float InBottom = -1 )
35 : Left(InLeft)
36 , Top(InTop)
37 , Right(InRight)
39 { }
40
47
56
57public:
58
62 inline bool IsValid() const
63 {
64 return !(Left == -1 && Right == -1 && Bottom == -1 && Top == -1) && Right >= Left && Bottom >= Top;
65 }
66
70 inline bool IsEmpty() const
71 {
72 return GetArea() <= UE_SMALL_NUMBER;
73 }
74
84 inline FVector2f GetSize2f() const
85 {
86 return FVector2f(Right - Left, Bottom - Top);
87 }
88
92 inline float GetArea() const
93 {
94 return (Right - Left) * (Bottom - Top);
95 }
96
106 inline FVector2f GetCenter2f() const
107 {
108 return FVector2f(Left, Top) + GetSize2f() * 0.5f;
109 }
110
120 inline FVector2f GetTopLeft2f() const
121 {
122 return FVector2f(Left, Top);
123 }
124
135 {
136 return FVector2f(Right, Top);
137 }
138
149 {
150 return FVector2f(Right, Bottom);
151 }
152
163 {
164 return FVector2f(Left, Bottom);
165 }
166
174 inline FSlateRect InsetBy(const struct FMargin& InsetAmount) const
175 {
176 return FSlateRect(Left + InsetAmount.Left, Top + InsetAmount.Top, Right - InsetAmount.Right, Bottom - InsetAmount.Bottom);
177 }
178
187 {
188 return FSlateRect(Left - ExtendAmount.Left, Top - ExtendAmount.Top, Right + ExtendAmount.Right, Bottom + ExtendAmount.Bottom);
189 }
190
202
210 inline FSlateRect ScaleBy(float ScaleBy) const
211 {
212 const FVector2f Delta = GetSize() * 0.5f * ScaleBy;
213 return ExtendBy(FMargin(Delta));
214 }
215
223 inline FSlateRect Expand( const FSlateRect& Other ) const
224 {
225 return FSlateRect( FMath::Min( Left, Other.Left ), FMath::Min( Top, Other.Top ), FMath::Max( Right, Other.Right ), FMath::Max( Bottom, Other.Bottom ) );
226 }
227
231 inline FSlateRect Round() const
232 {
233 return FSlateRect(
234 FMath::RoundToFloat(Left),
235 FMath::RoundToFloat(Top),
236 FMath::RoundToFloat(Right),
237 FMath::RoundToFloat(Bottom));
238 }
239
248 {
249 bool bOverlapping;
251 }
252
262 {
263 FSlateRect Intersected( FMath::Max( this->Left, Other.Left ), FMath::Max(this->Top, Other.Top), FMath::Min( this->Right, Other.Right ), FMath::Min( this->Bottom, Other.Bottom ) );
264 if ( (Intersected.Bottom < Intersected.Top) || (Intersected.Right < Intersected.Left) )
265 {
266 OutOverlapping = false;
267 // The intersection has 0 area and should not be rendered at all.
268 return FSlateRect(0,0,0,0);
269 }
270 else
271 {
272 OutOverlapping = true;
273 return Intersected;
274 }
275 }
276
284 {
285 return Point.X >= Left && Point.X <= Right && Point.Y >= Top && Point.Y <= Bottom;
286 }
287
288 bool operator==( const FSlateRect& Other ) const
289 {
290 return
291 Left == Other.Left &&
292 Top == Other.Top &&
293 Right == Other.Right &&
294 Bottom == Other.Bottom;
295 }
296
297 bool operator!=( const FSlateRect& Other ) const
298 {
299 return Left != Other.Left || Top != Other.Top || Right != Other.Right || Bottom != Other.Bottom;
300 }
301
302 friend FSlateRect operator+( const FSlateRect& A, const FSlateRect& B )
303 {
304 return FSlateRect( A.Left + B.Left, A.Top + B.Top, A.Right + B.Right, A.Bottom + B.Bottom );
305 }
306
307 friend FSlateRect operator-( const FSlateRect& A, const FSlateRect& B )
308 {
309 return FSlateRect( A.Left - B.Left, A.Top - B.Top, A.Right - B.Right, A.Bottom - B.Bottom );
310 }
311
312 friend FSlateRect operator*( float Scalar, const FSlateRect& Rect )
313 {
315 }
316
318 static bool DoRectanglesIntersect( const FSlateRect& A, const FSlateRect& B )
319 {
320 // Segments A and B do not intersect when:
321 //
322 // (left) A (right)
323 // o-------------o
324 // o---o OR o---o
325 // B B
326 //
327 //
328 // We assume the A and B are well-formed rectangles.
329 // i.e. (Top,Left) is above and to the left of (Bottom,Right)
330 const bool bDoNotOverlap =
331 B.Right < A.Left || A.Right < B.Left ||
332 B.Bottom < A.Top || A.Bottom < B.Top;
333
334 return ! bDoNotOverlap;
335 }
336
338 inline static bool IsRectangleContained( const FSlateRect& A, const FSlateRect& B )
339 {
340 return (A.Left <= B.Left) && (A.Right >= B.Right) && (A.Top <= B.Top) && (A.Bottom >= B.Bottom);
341 }
342
348 SLATECORE_API FString ToString() const;
349
357 SLATECORE_API bool InitFromString(const FString& InSourceString);
358
359
360 friend inline uint32 GetTypeHash(const FSlateRect& Key)
361 {
362 uint32 Hash = 0;
363 Hash = HashCombine(Hash, GetTypeHash(Key.Left));
364 Hash = HashCombine(Hash, GetTypeHash(Key.Right));
365 Hash = HashCombine(Hash, GetTypeHash(Key.Top));
366 Hash = HashCombine(Hash, GetTypeHash(Key.Bottom));
367 return Hash;
368 }
369};
370
377template <typename TransformType>
393
394template<> struct TIsPODType<FSlateRect> { enum { Value = true }; };
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define X(Name, Desc)
Definition FormatStringSan.h:47
UE::Math::TVector2< float > FVector2f
Definition MathFwd.h:74
FSlateRect TransformRect(const TransformType &Transform, const FSlateRect &Rect)
Definition SlateRect.h:378
PositionType TransformPoint(const TransformType &Transform, const PositionType &Point)
Definition TransformCalculus.h:358
constexpr uint32 HashCombine(uint32 A, uint32 C)
Definition TypeHash.h:36
#define UE_SMALL_NUMBER
Definition UnrealMathUtility.h:130
uint32 Size
Definition VulkanMemory.cpp:4034
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition SlateRect.h:26
FSlateRect ExtendBy(const FMargin &ExtendAmount) const
Definition SlateRect.h:186
FSlateRect ScaleBy(float ScaleBy) const
Definition SlateRect.h:210
FSlateRect(const UE::Slate::FDeprecateVector2DParameter &InStartPos, const UE::Slate::FDeprecateVector2DParameter &InEndPos)
Definition SlateRect.h:41
FVector2f GetSize2f() const
Definition SlateRect.h:84
float Left
Definition SlateRect.h:29
float GetArea() const
Definition SlateRect.h:92
FSlateRect Round() const
Definition SlateRect.h:231
FSlateRect InsetBy(const struct FMargin &InsetAmount) const
Definition SlateRect.h:174
bool operator==(const FSlateRect &Other) const
Definition SlateRect.h:288
FVector2f GetBottomRight2f() const
Definition SlateRect.h:148
float Top
Definition SlateRect.h:30
bool ContainsPoint(const UE::Slate::FDeprecateVector2DParameter &Point) const
Definition SlateRect.h:283
float Right
Definition SlateRect.h:31
bool IsValid() const
Definition SlateRect.h:62
static bool DoRectanglesIntersect(const FSlateRect &A, const FSlateRect &B)
Definition SlateRect.h:318
FSlateRect IntersectionWith(const FSlateRect &Other, bool &OutOverlapping) const
Definition SlateRect.h:261
UE::Slate::FDeprecateVector2DResult GetTopLeft() const
Definition SlateRect.h:116
FVector2f GetBottomLeft2f() const
Definition SlateRect.h:162
FSlateRect OffsetBy(const UE::Slate::FDeprecateVector2DParameter &OffsetAmount) const
Definition SlateRect.h:198
UE::Slate::FDeprecateVector2DResult GetSize() const
Definition SlateRect.h:80
friend uint32 GetTypeHash(const FSlateRect &Key)
Definition SlateRect.h:360
friend FSlateRect operator+(const FSlateRect &A, const FSlateRect &B)
Definition SlateRect.h:302
friend FSlateRect operator-(const FSlateRect &A, const FSlateRect &B)
Definition SlateRect.h:307
static FSlateRect FromPointAndExtent(const UE::Slate::FDeprecateVector2DParameter &TopLeft, const UE::Slate::FDeprecateVector2DParameter &Size)
Definition SlateRect.h:52
FSlateRect(float InLeft=-1, float InTop=-1, float InRight=-1, float InBottom=-1)
Definition SlateRect.h:34
FVector2f GetTopLeft2f() const
Definition SlateRect.h:120
UE::Slate::FDeprecateVector2DResult GetCenter() const
Definition SlateRect.h:102
FVector2f GetCenter2f() const
Definition SlateRect.h:106
SLATECORE_API FString ToString() const
Definition SlateRect.cpp:5
UE::Slate::FDeprecateVector2DResult GetTopRight() const
Definition SlateRect.h:130
FSlateRect IntersectionWith(const FSlateRect &Other) const
Definition SlateRect.h:247
UE::Slate::FDeprecateVector2DResult GetBottomLeft() const
Definition SlateRect.h:158
friend FSlateRect operator*(float Scalar, const FSlateRect &Rect)
Definition SlateRect.h:312
SLATECORE_API bool InitFromString(const FString &InSourceString)
Definition SlateRect.cpp:10
float Bottom
Definition SlateRect.h:32
UE::Slate::FDeprecateVector2DResult GetBottomRight() const
Definition SlateRect.h:144
static bool IsRectangleContained(const FSlateRect &A, const FSlateRect &B)
Definition SlateRect.h:338
FSlateRect Expand(const FSlateRect &Other) const
Definition SlateRect.h:223
bool IsEmpty() const
Definition SlateRect.h:70
bool operator!=(const FSlateRect &Other) const
Definition SlateRect.h:297
FVector2f GetTopRight2f() const
Definition SlateRect.h:134
FDeprecateSlateVector2D FDeprecateVector2DResult
Definition SlateVector2.h:469
Definition Margin.h:17
Definition LinuxPlatformSplash.cpp:43
int32 Right
Definition LinuxPlatformSplash.cpp:47
int32 Bottom
Definition LinuxPlatformSplash.cpp:48
int32 Left
Definition LinuxPlatformSplash.cpp:46
int32 Top
Definition LinuxPlatformSplash.cpp:45
Definition IsPODType.h:12
@ Value
Definition IsPODType.h:13
Definition SlateVector2.h:485