UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
ChildrenBase.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 "SlotBase.h"
7#include "SlateGlobals.h"
9
10#ifndef UE_WITH_SLATE_CHILDREN_DEBUGGING
11#define UE_WITH_SLATE_CHILDREN_DEBUGGING !(UE_BUILD_SHIPPING)
12#endif
13
14
15class SWidget;
16class FSlotBase;
17
18
27{
28public:
30 : Owner(InOwner)
31 , Name("Children")
32 {
34 }
36 : Owner(InOwner)
37 , Name(InName)
38 {
40 check(!Name.IsNone());
41 }
42
43 FChildren(std::nullptr_t) = delete;
44
45 //~ Prevents allocation of FChildren. It creates confusion between FSlot and FChildren.
46 void* operator new (size_t) = delete;
47 void* operator new[](size_t) = delete;
48
50 virtual int32 Num() const = 0;
55
58 {
60 return *Owner;
61 }
62
64 template<typename Predicate>
65 inline void ForEachWidget(Predicate&& Pred)
66 {
67#if UE_WITH_SLATE_CHILDREN_DEBUGGING
69 TGuardValue<bool> IteratingGuard(Debug_bIsIteratingChildren, true);
70#endif
71
72 int32 WidgetCount = Num();
73 for (int32 Index = 0; Index < WidgetCount; ++Index)
74 {
76 Pred(WidgetRef.GetWidget());
77 }
78 }
79
81 template<typename Predicate>
82 inline void ForEachWidget(Predicate&& Pred) const
83 {
84#if UE_WITH_SLATE_CHILDREN_DEBUGGING
86 TGuardValue<bool> IteratingGuard(Debug_bIsIteratingChildren, true);
87#endif
88
89 int32 WidgetCount = Num();
90 for (int32 Index = 0; Index < WidgetCount; ++Index)
91 {
93 Pred(WidgetRef.GetWidget());
94 }
95 }
96
98 virtual int32 NumSlot() const
99 {
100 return Num();
101 }
102
104 virtual const FSlotBase& GetSlotAt(int32 ChildIndex) const = 0;
105
107 virtual bool SupportSlotWithSlateAttribute() const
108 {
109 return false;
110 }
111
114 {
116 return Name;
117 }
118
119protected:
120 friend class FCombinedChildren;
121 template<typename T>
122 friend class TOneDynamicChild;
123
126
128 {
129 private:
131 SWidget& WidgetReference;
132
133 public:
135 : WidgetCopy(MoveTemp(InWidgetCopy))
136 , WidgetReference(WidgetCopy.GetValue().Get())
137 {}
139 : WidgetCopy()
140 , WidgetReference(InWidgetRef)
141 {}
143 : WidgetCopy(Other.WidgetCopy)
144 , WidgetReference(WidgetCopy.IsSet() ? WidgetCopy.GetValue().Get() : Other.WidgetReference)
145 {}
147 : WidgetCopy(MoveTemp(Other.WidgetCopy))
148 , WidgetReference(WidgetCopy.IsSet() ? WidgetCopy.GetValue().Get() : Other.WidgetReference)
149 {}
150 FWidgetRef& operator=(const FWidgetRef&) = delete;
153 {
154 return WidgetReference;
155 }
156 };
157
159 {
160 private:
162 const SWidget& WidgetReference;
163
164 public:
166 : WidgetCopy(MoveTemp(InWidgetCopy))
167 , WidgetReference(WidgetCopy.GetValue().Get())
168 {}
170 : WidgetCopy()
171 , WidgetReference(InWidgetRef)
172 {}
174 : WidgetCopy(Other.WidgetCopy)
175 , WidgetReference(WidgetCopy.IsSet() ? WidgetCopy.GetValue().Get() : Other.WidgetReference)
176 {}
178 : WidgetCopy(MoveTemp(Other.WidgetCopy))
179 , WidgetReference(WidgetCopy.IsSet() ? WidgetCopy.GetValue().Get() : Other.WidgetReference)
180 {}
183 const SWidget& GetWidget() const
184 {
185 return WidgetReference;
186 }
187 };
188
193
194protected:
195#if UE_WITH_SLATE_CHILDREN_DEBUGGING
196 virtual ~FChildren()
197 {
199 Debug_DestroyedTag = 0xA3;
200 UE_CLOG(Debug_bIsIteratingChildren, LogSlate, Fatal,
201 TEXT("Destroying widget while iterating children! Owner: %s [%s]"),
203 *Name.ToString());
204 }
205
207 {
209 UE_CLOG(Debug_DestroyedTag != 0xDC, LogSlate, Fatal, TEXT("The FChildren is destroyed. You probably have 1 widget owned by 2 different FChildren."));
210 }
211
212#else
213
214 virtual ~FChildren() = default;
215
216 void Debug_TestDestroyTag() const
217 {
218 }
219
220#endif // !WITH_SLATE_DEBUGGING
221
222private:
223 SWidget* Owner;
224 FName Name;
225
226#if UE_WITH_SLATE_CHILDREN_DEBUGGING
227 mutable bool Debug_bIsIteratingChildren = false;
228 mutable uint8 Debug_DestroyedTag = 0xDC;
229#endif // WITH_SLATE_DEBUGGING
230};
#define check(expr)
Definition AssertionMacros.h:314
#define TEXT(x)
Definition Platform.h:1272
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 UE_CLOG(Condition, CategoryName, Verbosity, Format,...)
Definition LogMacros.h:298
UE_INTRINSIC_CAST UE_REWRITE constexpr std::remove_reference_t< T > && MoveTemp(T &&Obj) noexcept
Definition UnrealTemplate.h:520
uint8_t uint8
Definition binka_ue_file_header.h:8
Definition ChildrenBase.h:27
virtual TSharedRef< const SWidget > GetChildAt(int32 Index) const =0
FChildren(SWidget *InOwner)
Definition ChildrenBase.h:29
FChildren(SWidget *InOwner, FName InName)
Definition ChildrenBase.h:35
FName GetName() const
Definition ChildrenBase.h:113
ECopyConstruct
Definition ChildrenBase.h:124
@ CopyConstruct
Definition ChildrenBase.h:124
void ForEachWidget(Predicate &&Pred)
Definition ChildrenBase.h:65
virtual const FSlotBase & GetSlotAt(int32 ChildIndex) const =0
SWidget & GetOwner() const
Definition ChildrenBase.h:57
virtual FConstWidgetRef GetChildRefAt(int32 Index) const =0
virtual bool SupportSlotWithSlateAttribute() const
Definition ChildrenBase.h:107
virtual TSharedRef< SWidget > GetChildAt(int32 Index)=0
void ForEachWidget(Predicate &&Pred) const
Definition ChildrenBase.h:82
ERefConstruct
Definition ChildrenBase.h:125
@ ReferenceConstruct
Definition ChildrenBase.h:125
void Debug_TestDestroyTag() const
Definition ChildrenBase.h:206
FChildren(std::nullptr_t)=delete
virtual ~FChildren()
Definition ChildrenBase.h:196
virtual int32 NumSlot() const
Definition ChildrenBase.h:98
virtual FWidgetRef GetChildRefAt(int32 Index)=0
virtual int32 Num() const =0
Definition Children.h:19
Definition NameTypes.h:617
CORE_API FString ToString() const
Definition UnrealNames.cpp:3537
FORCEINLINE bool IsNone() const
Definition NameTypes.h:827
static SLATECORE_API FString GetWidgetDebugInfo(const SWidget *InWidget)
Definition ReflectionMetadata.cpp:54
Definition SlotBase.h:14
Definition SWidget.h:165
Definition Children.h:1028
Definition SharedPointer.h:153
U16 Index
Definition radfft.cpp:71
Definition ChildrenBase.h:159
FConstWidgetRef(FConstWidgetRef &&Other)
Definition ChildrenBase.h:177
FConstWidgetRef(ERefConstruct, const SWidget &InWidgetRef)
Definition ChildrenBase.h:169
FConstWidgetRef & operator=(const FConstWidgetRef &)=delete
FConstWidgetRef(ECopyConstruct, TSharedRef< const SWidget > InWidgetCopy)
Definition ChildrenBase.h:165
FConstWidgetRef(const FConstWidgetRef &Other)
Definition ChildrenBase.h:173
const SWidget & GetWidget() const
Definition ChildrenBase.h:183
FConstWidgetRef & operator=(FConstWidgetRef &&)=delete
Definition ChildrenBase.h:128
FWidgetRef & operator=(const FWidgetRef &)=delete
FWidgetRef(FWidgetRef &&Other)
Definition ChildrenBase.h:146
FWidgetRef(ERefConstruct, SWidget &InWidgetRef)
Definition ChildrenBase.h:138
FWidgetRef & operator=(FWidgetRef &&)=delete
FWidgetRef(const FWidgetRef &Other)
Definition ChildrenBase.h:142
SWidget & GetWidget() const
Definition ChildrenBase.h:152
FWidgetRef(ECopyConstruct, TSharedRef< SWidget > InWidgetCopy)
Definition ChildrenBase.h:134
Definition UnrealTemplate.h:341
Definition Optional.h:131