UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
SlotBase.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 "Misc/Attribute.h"
8
9class FChildren;
10class SWidget;
11
14{
15public:
19 FSlotBase& operator=(const FSlotBase&) = delete;
20 FSlotBase(const FSlotBase&) = delete;
21
22 SLATECORE_API virtual ~FSlotBase();
23
24public:
25 struct FSlotArguments {};
26
27public:
32 const FChildren* GetOwner() const { return Owner; }
33
39
44 SLATECORE_API void SetOwner(const FChildren& Children);
45
48 {
49 DetatchParentFromContent();
50 Widget = MoveTemp(InWidget);
51 AfterContentOrOwnerAssigned();
52 }
54 {
55 DetatchParentFromContent();
56 Widget = InWidget;
57 AfterContentOrOwnerAssigned();
58 }
59
65 inline const TSharedRef<SWidget>& GetWidget() const
66 {
67 return Widget;
68 }
69
76
79
80protected:
85 template<typename TargetValueType, typename SourceValueType>
87 {
88 if (!TargetValue.IdenticalTo(SourceValue))
89 {
90 const bool bWasBound = TargetValue.IsBound();
91 const bool bBoundnessChanged = bWasBound != SourceValue.IsBound();
92 TargetValue = SourceValue;
93
96 {
98 }
99
101 return true;
102 }
103
104 return false;
105 }
106
107private:
108 SLATECORE_API void DetatchParentFromContent();
109 SLATECORE_API void AfterContentOrOwnerAssigned();
110
111private:
113 const FChildren* Owner;
115 TSharedRef<SWidget> Widget;
116};
117
118
120template <typename SlotType>
121class TSlotBase : public FSlotBase
122{
123public:
125
127 {
129 return static_cast<SlotType&>(*this);
130 }
132 {
133 this->AttachWidget(InChildWidget);
134 return static_cast<SlotType&>(*this);
135 }
136
137 SlotType& Expose(SlotType*& OutVarToInit)
138 {
139 OutVarToInit = static_cast<SlotType*>(this);
140 return static_cast<SlotType&>(*this);
141 }
142
143
146
149 {
150 public:
153 : Slot(MoveTemp(InSlot))
154 {
155 check(Slot.Get());
156 }
161
162
163 public:
165 typename SlotType::FSlotArguments& operator[](TSharedRef<SWidget>&& InChildWidget)
166 {
167 ChildWidget = MoveTemp(InChildWidget);
168 return Me();
169 }
170 typename SlotType::FSlotArguments& operator[](const TSharedRef<SWidget>& InChildWidget)
171 {
172 ChildWidget = InChildWidget;
173 return Me();
174 }
175
177 typename SlotType::FSlotArguments& Expose(SlotType*& OutVarToInit)
178 {
179 OutVarToInit = Slot.Get();
180 return Me();
181 }
182
185 {
186 ChildWidget = InChildWidget;
187 }
188
190 const TSharedPtr<SWidget>& GetAttachedWidget() const { return ChildWidget; }
191
193 SlotType* GetSlot() const { return Slot.Get(); }
194
197 {
198 return MoveTemp(Slot);
199 }
200
202 typename SlotType::FSlotArguments& Me()
203 {
204 return static_cast<typename SlotType::FSlotArguments&>(*this);
205 }
206
207 private:
209 TSharedPtr<SWidget> ChildWidget;
210 };
211
213 {
214 if (InArgs.GetAttachedWidget())
215 {
216 AttachWidget(InArgs.GetAttachedWidget().ToSharedRef());
217 }
219 }
220};
#define check(expr)
Definition AssertionMacros.h:314
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
EInvalidateWidgetReason
Definition InvalidateWidgetReason.h:14
UE_INTRINSIC_CAST UE_REWRITE constexpr std::remove_reference_t< T > && MoveTemp(T &&Obj) noexcept
Definition UnrealTemplate.h:520
Definition ChildrenBase.h:27
Definition SlotBase.h:14
SLATECORE_API const TSharedPtr< SWidget > DetachWidget()
Definition SlotBase.cpp:46
virtual SLATECORE_API ~FSlotBase()
Definition SlotBase.cpp:97
const FChildren * GetOwner() const
Definition SlotBase.h:32
SLATECORE_API void SetOwner(const FChildren &Children)
Definition SlotBase.cpp:34
SLATECORE_API SWidget * GetOwnerWidget() const
Definition SlotBase.cpp:29
bool SetAttribute(TAttribute< TargetValueType > &TargetValue, const TAttribute< SourceValueType > &SourceValue, EInvalidateWidgetReason BaseInvalidationReason)
Definition SlotBase.h:86
FSlotBase(const FSlotBase &)=delete
void AttachWidget(TSharedRef< SWidget > &&InWidget)
Definition SlotBase.h:47
FSlotBase & operator=(const FSlotBase &)=delete
void AttachWidget(const TSharedRef< SWidget > &InWidget)
Definition SlotBase.h:53
const TSharedRef< SWidget > & GetWidget() const
Definition SlotBase.h:65
SLATECORE_API FSlotBase()
Definition SlotBase.cpp:8
Definition SWidget.h:165
Definition Attribute.h:17
bool IsBound() const
Definition Attribute.h:427
bool IdenticalTo(const TAttribute &InOther) const
Definition Attribute.h:460
Definition SharedPointer.h:692
Definition SharedPointer.h:153
Definition SlotBase.h:122
EConstructSlotIsFChildren
Definition SlotBase.h:145
@ ConstructSlotIsFChildren
Definition SlotBase.h:145
SlotType & operator[](TSharedRef< SWidget > &&InChildWidget)
Definition SlotBase.h:126
SlotType & operator[](const TSharedRef< SWidget > &InChildWidget)
Definition SlotBase.h:131
void Construct(const FChildren &SlotOwner, FSlotArguments &&InArgs)
Definition SlotBase.h:212
SlotType & Expose(SlotType *&OutVarToInit)
Definition SlotBase.h:137
Definition UniquePtr.h:107
UE_FORCEINLINE_HINT T * Get() const
Definition UniquePtr.h:324
Definition SlotBase.h:25
Definition SlotBase.h:149
FSlotArguments(const FSlotArguments &)=delete
FSlotArguments & operator=(FSlotArguments &&)=default
FSlotArguments(EConstructSlotIsFChildren)
Definition SlotBase.h:151
SlotType * GetSlot() const
Definition SlotBase.h:193
FSlotArguments & operator=(const FSlotArguments &)=delete
SlotType::FSlotArguments & Expose(SlotType *&OutVarToInit)
Definition SlotBase.h:177
TUniquePtr< SlotType > StealSlot()
Definition SlotBase.h:196
SlotType::FSlotArguments & operator[](TSharedRef< SWidget > &&InChildWidget)
Definition SlotBase.h:165
SlotType::FSlotArguments & Me()
Definition SlotBase.h:202
void AttachWidget(const TSharedRef< SWidget > &InChildWidget)
Definition SlotBase.h:184
FSlotArguments(FSlotArguments &&)=default
FSlotArguments(TUniquePtr< SlotType > InSlot)
Definition SlotBase.h:152
const TSharedPtr< SWidget > & GetAttachedWidget() const
Definition SlotBase.h:190
SlotType::FSlotArguments & operator[](const TSharedRef< SWidget > &InChildWidget)
Definition SlotBase.h:170