UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
Geometry.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
6#include "CoreMinimal.h"
7#include "Layout/Margin.h"
9#include "Layout/SlateRect.h"
14#include "Math/UnrealMathSSE.h"
15#include "Math/Vector2D.h"
20#include "Types/SlateVector2.h"
21
22#include "Geometry.generated.h"
23
24class FArrangedWidget;
25class FLayoutGeometry;
26class SWidget;
27template <typename T> struct TIsPODType;
28
38USTRUCT(BlueprintType)
40{
42
43public:
44
49
53 FGeometry(const FGeometry& RHS) = default;
54
59 SLATECORE_API FGeometry& operator=(const FGeometry& RHS);
60
72 , Scale(1.0f)
73 , AbsolutePosition(0.0f, 0.0f)
74 , bHasRenderTransform(false)
75 {
76 // Since OffsetFromParent is given as a LocalSpaceOffset, we MUST convert this offset into the space of the parent to construct a valid layout transform.
77 // The extra TransformPoint below does this by converting the local offset to an offset in parent space.
79
84 // HACK to allow us to make FGeometry public members immutable to catch misuse.
85 const_cast<FVector2f&>( AbsolutePosition ) = FVector2f(AccumulatedLayoutTransform.GetTranslation());
86 const_cast<float&>( Scale ) = AccumulatedLayoutTransform.GetScale();
87 const_cast<FVector2f&>( Position ) = FVector2f(LocalLayoutTransform.GetTranslation());
88 }
89
90private:
101 FGeometry(
109 , Scale(1.0f)
110 , AbsolutePosition(0.0f, 0.0f)
111 , AccumulatedRenderTransform(
113 // convert the pivot to local space and make it the origin
114 Inverse(TransformPoint(FScale2D(UE::Slate::CastToVector2f(InLocalSize)), UE::Slate::CastToVector2f(InLocalRenderTransformPivot))),
115 // apply the render transform in local space centered around the pivot
117 // translate the pivot point back.
118 TransformPoint(FScale2D(UE::Slate::CastToVector2f(InLocalSize)), UE::Slate::CastToVector2f(InLocalRenderTransformPivot)),
119 // apply the layout transform next.
121 // finally apply the parent accumulated transform, which takes us to the root.
123 )
124 ), bHasRenderTransform(true)
125 {
127 // HACK to allow us to make FGeometry public members immutable to catch misuse.
128 const_cast<FVector2f&>( AbsolutePosition ) = FVector2f(AccumulatedLayoutTransform.GetTranslation());
129 const_cast<float&>( Scale ) = AccumulatedLayoutTransform.GetScale();
130 const_cast<FVector2f&>( Position ) = FVector2f(InLocalLayoutTransform.GetTranslation());
131 }
132
141 FGeometry(
148 , Scale(1.0f)
149 , AbsolutePosition(0.0f, 0.0f)
151 , bHasRenderTransform(bParentHasRenderTransform)
152 {
154 // HACK to allow us to make FGeometry public members immutable to catch misuse.
155 const_cast<FVector2f&>( AbsolutePosition ) = FVector2f(AccumulatedLayoutTransform.GetTranslation());
156 const_cast<float&>( Scale ) = AccumulatedLayoutTransform.GetScale();
157 const_cast<FVector2f&>( Position ) = FVector2f(InLocalLayoutTransform.GetTranslation());
158 }
159
160public:
161
168 bool operator==( const FGeometry& Other ) const
169 {
170 return
171 this->Size == Other.Size &&
172 this->AbsolutePosition == Other.AbsolutePosition &&
173 this->Position == Other.Position &&
174 this->Scale == Other.Scale;
175 }
176
183 bool operator!=( const FGeometry& Other ) const
184 {
185 return !( this->operator==(Other) );
186 }
187
188public:
226 {
227 return FGeometry(InLocalSize, LayoutTransform, RenderTransform, RenderTransformPivot, GetAccumulatedLayoutTransform(), GetAccumulatedRenderTransform());
228 }
229
241 {
242 return FGeometry(InLocalSize, LayoutTransform, GetAccumulatedLayoutTransform(), GetAccumulatedRenderTransform(), bHasRenderTransform);
243 }
245 {
246 return FGeometry(GetLocalSize(), FSlateLayoutTransform(), RenderTransform, RenderTransformPivot, GetAccumulatedLayoutTransform(), GetAccumulatedRenderTransform());
247 }
248
249
258 FArrangedWidget MakeChild(const TSharedRef<SWidget>& ChildWidget, const FLayoutGeometry& LayoutGeometry) const;
259
273
274#if UE_ENABLE_SLATE_VECTOR_DEPRECATION_MECHANISMS
275
286 UE_DEPRECATED(5.2, "Use FGeometry MakeChild(const FVector2f& InLocalSize, const FSlateLayoutTransform& InLayoutTransform) instead.")
287 inline FGeometry MakeChild(const FVector2D& ChildOffset, const FVector2D& InLocalSize, float ChildScale = 1.0f) const
288 {
289 // Since ChildOffset is given as a LocalSpaceOffset, we MUST convert this offset into the space of the parent to construct a valid layout transform.
290 // The extra TransformPoint below does this by converting the local offset to an offset in parent space.
291 return FGeometry(UE::Slate::CastToVector2f(InLocalSize), FSlateLayoutTransform(ChildScale, TransformPoint(ChildScale, UE::Slate::CastToVector2f(ChildOffset))), GetAccumulatedLayoutTransform(), GetAccumulatedRenderTransform(), bHasRenderTransform);
292 }
293
294#endif
295
309
316 {
317 return FPaintGeometry(GetAccumulatedLayoutTransform(), GetAccumulatedRenderTransform(), FVector2f(Size), bHasRenderTransform);
318 }
319
334
348
361
362#if UE_ENABLE_SLATE_VECTOR_DEPRECATION_MECHANISMS
363
375 UE_DEPRECATED(5.2, "Use FPaintGeometry ToPaintGeometry(const FVector2f& InLocalSize, const FSlateLayoutTransform& InLayoutTransform) instead.")
376 FORCEINLINE_DEBUGGABLE FPaintGeometry ToPaintGeometry(const UE::Slate::FDeprecateVector2DParameter& InLocalOffset, const UE::Slate::FDeprecateVector2DParameter& InLocalSize, float InLocalScale = 1.0f) const
377 {
378 // Since ChildOffset is given as a LocalSpaceOffset, we MUST convert this offset into the space of the parent to construct a valid layout transform.
379 // The extra TransformPoint below does this by converting the local offset to an offset in parent space.
381 }
382
383#endif
384
395 {
396 return ToPaintGeometry(FSlateLayoutTransform(UE::Slate::CastToVector2f(LocalOffset)));
397 }
398
408 {
410 // This essentially adds (or subtracts) a border around the widget. We scale the size then offset by the border amount.
411 // Note this is not scaling child widgets, so the scale is not changing.
412 FVector2f NewSize = FVector2f(Size) + InflateAmount2f* 2;
413 return ToPaintGeometry(NewSize, FSlateLayoutTransform(-InflateAmount2f));
414 }
415
421 inline bool IsUnderLocation(const UE::Slate::FDeprecateVector2DParameter& AbsoluteCoordinate) const
422 {
423 // this render transform invert is a little expensive. We might consider caching it?
424 FSlateRotatedRect Rect = TransformRect(GetAccumulatedRenderTransform(), FSlateRotatedRect(FSlateRect(FVector2f(0.0f, 0.0f), FVector2f(Size))));
425 return Rect.IsUnderLocation(AbsoluteCoordinate);
426 }
427
434 {
435 // this render transform invert is a little expensive. We might consider caching it.
436 return UE::Slate::FDeprecateVector2DResult(TransformPoint(Inverse(GetAccumulatedRenderTransform()), UE::Slate::CastToVector2f(AbsoluteCoordinate)));
437 }
438
447 {
448 return UE::Slate::FDeprecateVector2DResult(TransformPoint(GetAccumulatedRenderTransform(), UE::Slate::CastToVector2f(LocalCoordinate)));
449 }
450
458 {
459 const FVector2f AbsoluteCoordinate = LocalToAbsolute(UE::Slate::CastToVector2f(LocalCoordinate));
460 const FVector2f AbsoluteCoordinateRounded = FVector2f(FMath::RoundToFloat(AbsoluteCoordinate.X), FMath::RoundToFloat(AbsoluteCoordinate.Y));
461
462 return AbsoluteToLocal(AbsoluteCoordinateRounded);
463 }
464
466 {
467 return GetLayoutBoundingRect(FSlateRect(FVector2f(0.0f, 0.0f), FVector2f(Size)));
468 }
469
474
476 {
477 return TransformRect(GetAccumulatedLayoutTransform(), FSlateRotatedRect(LocalSpaceRect)).ToBoundingRect();
478 }
479
481 {
482 return GetRenderBoundingRect(FSlateRect(FVector2f(0.0f, 0.0f), FVector2f(Size)));
483 }
484
489
491 {
492 return TransformRect(GetAccumulatedRenderTransform(), FSlateRotatedRect(LocalSpaceRect)).ToBoundingRect();
493 }
494
496 SLATECORE_API FString ToString() const;
497
505 {
506 return UE::Slate::FDeprecateVector2DResult(TransformVector(GetAccumulatedLayoutTransform(), FVector2f(Size)));
507 }
508
511
513 inline const FSlateRenderTransform& GetAccumulatedRenderTransform() const { return AccumulatedRenderTransform; }
514
517 {
518 return FSlateLayoutTransform(Scale, AbsolutePosition);
519 }
520
530 {
532 AccumulatedRenderTransform = ::Concatenate(AccumulatedRenderTransform, LayoutTransform);
533 const_cast<FVector2f&>( AbsolutePosition ) = FVector2f(AccumulatedLayoutTransform.GetTranslation());
534 const_cast<float&>( Scale ) = AccumulatedLayoutTransform.GetScale();
535 }
536
541 {
542 return UE::Slate::FDeprecateVector2DResult(AccumulatedRenderTransform.TransformPoint(FVector2f::ZeroVector));
543 }
544
549 {
550 return UE::Slate::FDeprecateVector2DResult(AccumulatedRenderTransform.TransformVector(FVector2f(GetLocalSize())));
551 }
552
564
576
577 bool HasRenderTransform() const { return bHasRenderTransform; }
578
579public:
591
604 const float /*Absolute*/Scale;
605
618 const FVector2f AbsolutePosition = FVector2f::ZeroVector;
619
628
629private:
630
636 FSlateRenderTransform AccumulatedRenderTransform;
637
639 const uint8 bHasRenderTransform : 1;
640};
641
642
643template <> struct TIsPODType<FGeometry> { enum { Value = true }; };
#define FORCEINLINE_DEBUGGABLE
Definition CoreMiscDefines.h:74
#define UE_DEPRECATED(Version, Message)
Definition CoreMiscDefines.h:302
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
return true
Definition ExternalRpcRegistry.cpp:601
UE::Math::TVector2< float > FVector2f
Definition MathFwd.h:74
#define USTRUCT(...)
Definition ObjectMacros.h:746
#define GENERATED_USTRUCT_BODY(...)
Definition ObjectMacros.h:767
FSlateRect TransformRect(const TransformType &Transform, const FSlateRect &Rect)
Definition SlateRect.h:378
FTransform2D FSlateRenderTransform
Definition SlateRenderTransform.h:9
VectorType TransformVector(const TransformType &Transform, const VectorType &Vector)
Definition TransformCalculus.h:367
PositionType TransformPoint(const TransformType &Transform, const PositionType &Point)
Definition TransformCalculus.h:358
ConcatenateRules< TransformTypeA, TransformTypeB >::ResultType Concatenate(const TransformTypeA &LHS, const TransformTypeB &RHS)
Definition TransformCalculus.h:293
uint32 Size
Definition VulkanMemory.cpp:4034
uint8_t uint8
Definition binka_ue_file_header.h:8
Definition ArrangedWidget.h:18
Definition LayoutGeometry.h:11
Definition SlateLayoutTransform.h:20
Definition SlateRect.h:26
Definition SWidget.h:165
Definition TransformCalculus2D.h:114
Definition SharedPointer.h:153
Definition TransformCalculus2D.h:682
bool IsIdentity() const
Definition TransformCalculus2D.h:823
Definition SScissorRectBox.cpp:10
FDeprecateSlateVector2D FDeprecateVector2DResult
Definition SlateVector2.h:469
const FVector2f & CastToVector2f(const FVector2f &InValue)
Definition SlateVector2.h:591
Definition AdvancedWidgetsModule.cpp:13
@ false
Definition radaudio_common.h:23
Definition Geometry.h:40
FORCEINLINE_DEBUGGABLE FPaintGeometry ToPaintGeometry(const UE::Slate::FDeprecateVector2DParameter &InLocalSize, const FSlateLayoutTransform &InLayoutTransform) const
Definition Geometry.h:329
FGeometry MakeChild(const UE::Slate::FDeprecateVector2DParameter &InLocalSize, const FSlateLayoutTransform &LayoutTransform, const FSlateRenderTransform &RenderTransform, const UE::Slate::FDeprecateVector2DParameter &RenderTransformPivot) const
Definition Geometry.h:225
const float Scale
Definition Geometry.h:604
UE::Slate::FDeprecateVector2DResult LocalToRoundedLocal(UE::Slate::FDeprecateVector2DParameter LocalCoordinate) const
Definition Geometry.h:457
UE::Slate::FDeprecateVector2DResult LocalToAbsolute(UE::Slate::FDeprecateVector2DParameter LocalCoordinate) const
Definition Geometry.h:446
const FDeprecateSlateVector2D Size
Definition Geometry.h:590
FORCEINLINE_DEBUGGABLE FSlateRect GetRenderBoundingRect(const FMargin &LocalSpaceExtendBy) const
Definition Geometry.h:485
FORCEINLINE_DEBUGGABLE FPaintGeometry ToPaintGeometry() const
Definition Geometry.h:315
UE::Slate::FDeprecateVector2DResult GetAbsoluteSize() const
Definition Geometry.h:548
UE::Slate::FDeprecateVector2DResult GetLocalSize() const
Definition Geometry.h:510
static FGeometry MakeRoot(const UE::Slate::FDeprecateVector2DParameter &InLocalSize, const FSlateLayoutTransform &LayoutTransform, const FSlateRenderTransform &RenderTransform)
Definition Geometry.h:209
FORCEINLINE_DEBUGGABLE FGeometry MakeChild(const FSlateRenderTransform &RenderTransform, const UE::Slate::FDeprecateVector2DParameter &RenderTransformPivot=FVector2f(0.5f, 0.5f)) const
Definition Geometry.h:244
FGeometry(const FGeometry &RHS)=default
UE::Slate::FDeprecateVector2DResult GetAbsolutePositionAtCoordinates(const UE::Slate::FDeprecateVector2DParameter &NormalCoordinates) const
Definition Geometry.h:560
FORCEINLINE_DEBUGGABLE FSlateRect GetLayoutBoundingRect() const
Definition Geometry.h:465
FORCEINLINE_DEBUGGABLE FSlateRect GetRenderBoundingRect(const FSlateRect &LocalSpaceRect) const
Definition Geometry.h:490
UE::Slate::FDeprecateVector2DResult GetAbsolutePosition() const
Definition Geometry.h:540
FORCEINLINE_DEBUGGABLE UE::Slate::FDeprecateVector2DResult AbsoluteToLocal(UE::Slate::FDeprecateVector2DParameter AbsoluteCoordinate) const
Definition Geometry.h:433
FORCEINLINE_DEBUGGABLE FSlateRect GetLayoutBoundingRect(const FSlateRect &LocalSpaceRect) const
Definition Geometry.h:475
bool operator!=(const FGeometry &Other) const
Definition Geometry.h:183
bool operator==(const FGeometry &Other) const
Definition Geometry.h:168
FORCEINLINE_DEBUGGABLE FPaintGeometry ToPaintGeometry(const FSlateLayoutTransform &LayoutTransform) const
Definition Geometry.h:357
FORCEINLINE_DEBUGGABLE FGeometry MakeChild(const UE::Slate::FDeprecateVector2DParameter &InLocalSize, const FSlateLayoutTransform &LayoutTransform) const
Definition Geometry.h:240
FPaintGeometry ToOffsetPaintGeometry(const UE::Slate::FDeprecateVector2DParameter &LocalOffset) const
Definition Geometry.h:394
FSlateLayoutTransform GetAccumulatedLayoutTransform() const
Definition Geometry.h:516
FORCEINLINE_DEBUGGABLE FPaintGeometry ToPaintGeometry(const UE::Slate::FDeprecateVector2DParameter &InLocalSize, const FSlateLayoutTransform &InLayoutTransform, const FSlateRenderTransform &RenderTransform, const UE::Slate::FDeprecateVector2DParameter &RenderTransformPivot=FVector2f(0.5f, 0.5f)) const
Definition Geometry.h:344
FORCEINLINE_DEBUGGABLE void AppendTransform(const FSlateLayoutTransform &LayoutTransform)
Definition Geometry.h:529
UE::Slate::FDeprecateVector2DResult GetLocalPositionAtCoordinates(const UE::Slate::FDeprecateVector2DParameter &NormalCoordinates) const
Definition Geometry.h:572
FPaintGeometry ToInflatedPaintGeometry(const UE::Slate::FDeprecateVector2DParameter &InflateAmount) const
Definition Geometry.h:407
bool HasRenderTransform() const
Definition Geometry.h:577
bool IsUnderLocation(const UE::Slate::FDeprecateVector2DParameter &AbsoluteCoordinate) const
Definition Geometry.h:421
const FVector2f Position
Definition Geometry.h:627
UE::Slate::FDeprecateVector2DResult GetDrawSize() const
Definition Geometry.h:504
FORCEINLINE_DEBUGGABLE FSlateRect GetLayoutBoundingRect(const FMargin &LocalSpaceExtendBy) const
Definition Geometry.h:470
static FGeometry MakeRoot(const UE::Slate::FDeprecateVector2DParameter &InLocalSize, const FSlateLayoutTransform &LayoutTransform)
Definition Geometry.h:197
const FSlateRenderTransform & GetAccumulatedRenderTransform() const
Definition Geometry.h:513
FORCEINLINE_DEBUGGABLE FSlateRect GetRenderBoundingRect() const
Definition Geometry.h:480
FGeometry(const UE::Slate::FDeprecateVector2DParameter &OffsetFromParent, const UE::Slate::FDeprecateVector2DParameter &ParentAbsolutePosition, const UE::Slate::FDeprecateVector2DParameter &InLocalSize, float InScale)
Definition Geometry.h:70
Definition Margin.h:17
Definition PaintGeometry.h:24
Definition SlateRotatedRect.h:20
Definition LinuxPlatformSplash.cpp:43
Definition IsPODType.h:12
@ Value
Definition IsPODType.h:13
T Y
Definition Vector2D.h:52
T X
Definition Vector2D.h:49
static CORE_API const TVector2< float > ZeroVector
Definition Vector2D.h:63
Definition SlateVector2.h:485