UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
SGridPanel.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"
7#include "Layout/Visibility.h"
9#include "SlotBase.h"
10#include "Widgets/SWidget.h"
11#include "Layout/Children.h"
12#include "Widgets/SPanel.h"
13
15class FPaintArgs;
17
18class SGridPanel : public SPanel
19{
21
22public:
23 // Used by the mandatory named parameter in FSlot
24 class Layer
25 {
26 public:
29 {
30
31 }
32
34 };
35
36 class FSlot : public TBasicLayoutWidgetSlot<FSlot>
37 {
38 friend SGridPanel;
39
40 public:
42 FSlot( int32 Column, int32 Row, int32 InLayer )
44 , ColumnParam( Column )
45 , ColumnSpanParam( 1 )
46 , RowParam( Row )
47 , RowSpanParam( 1 )
48 , LayerParam( InLayer )
49 , NudgeParam( FVector2D::ZeroVector )
50 {
51 }
52
67
68 SLATE_API void Construct(const FChildren& SlotOwner, FSlotArguments&& InArgs);
69
70 public:
73 {
74 return ColumnParam;
75 }
76
77 void SetColumn(int32 Column)
78 {
79 Column = FMath::Max(0, Column);
80 if (Column != ColumnParam)
81 {
82 ColumnParam = Column;
83 NotifySlotChanged();
84 }
85 }
86
89 {
90 return ColumnSpanParam;
91 }
92
93 void SetColumnSpan(int32 ColumnSpan)
94 {
95 // clamp span to a sensible size, otherwise computing slot sizes can slow down dramatically
96 ColumnSpan = FMath::Clamp(ColumnSpan, 1, 10000);
97 if (ColumnSpan != ColumnSpanParam)
98 {
99 ColumnSpanParam = ColumnSpan;
100 NotifySlotChanged();
101 }
102 }
103
105 int32 GetRow() const
106 {
107 return RowParam;
108 }
109
110 void SetRow(int32 Row)
111 {
112 Row = FMath::Max(0, Row);
113 if (Row != RowParam)
114 {
115 RowParam = Row;
116 NotifySlotChanged();
117 }
118 }
119
122 {
123 return RowSpanParam;
124 }
125
126 void SetRowSpan(int32 RowSpan)
127 {
128 // clamp span to a sensible size, otherwise computing slots sizes can slow down dramatically
129 RowSpan = FMath::Clamp(RowSpan, 1, 10000);
130 if (RowSpan != RowSpanParam)
131 {
132 RowSpanParam = RowSpan;
133 NotifySlotChanged();
134 }
135 }
136
139 {
140 return LayerParam;
141 }
142
144 {
145 if (Layer != LayerParam)
146 {
147 LayerParam = Layer;
148 const bool bSlotLayerChanged = true;
149 NotifySlotChanged(bSlotLayerChanged);
150 }
151 }
152
155 {
156 return NudgeParam;
157 }
158
159 void SetNudge(const FVector2D& Nudge)
160 {
161 NudgeParam = Nudge;
163 }
164
165 private:
168
169 int32 ColumnParam;
170 int32 ColumnSpanParam;
171 int32 RowParam;
172 int32 RowSpanParam;
173 int32 LayerParam;
174 FVector2D NudgeParam;
175
177 inline void NotifySlotChanged(bool bSlotLayerChanged = false)
178 {
179 if ( Panel.IsValid() )
180 {
181 Panel.Pin()->NotifySlotChanged(this, bSlotLayerChanged);
182 }
183 }
184 };
185
189 static SLATE_API FSlot::FSlotArguments Slot( int32 Column, int32 Row, Layer InLayer = Layer(0) );
190
198
206
211
212 SLATE_SLOT_ARGUMENT( FSlot, Slots )
213
214
215 FArguments& FillColumn( int32 ColumnId, const TAttribute<float>& Coefficient )
216 {
217 while (ColFillCoefficients.Num() <= ColumnId)
218 {
220 }
221 ColFillCoefficients[ColumnId] = Coefficient;
222 return Me();
223 }
224
226 FArguments& FillRow( int32 RowId, const TAttribute<float>& Coefficient )
227 {
228 while (RowFillCoefficients.Num() <= RowId)
229 {
231 }
232 RowFillCoefficients[RowId] = Coefficient;
233 return Me();
234 }
235
238
241
243
246
249
250 SLATE_API void Construct( const FArguments& InArgs );
251
261
263 SLATE_API void SetColumnFill( int32 ColumnId, const TAttribute<float>& Coefficient );
264
266 SLATE_API void SetRowFill( int32 RowId, const TAttribute<float>& Coefficient );
267
269 SLATE_API void ClearFill();
270
271public:
272
273 // SWidget interface
274
275 SLATE_API virtual int32 OnPaint( const FPaintArgs& Args, const FGeometry& AllottedGeometry, const FSlateRect& MyCullingRect, FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled ) const override;
280
281private:
282
289 static SLATE_API void ComputePartialSums( TArray<float>& TurnMeIntoPartialSums );
290
292 static SLATE_API void DistributeSizeContributions( float SizeContribution, TArray<float>& DistributeOverMe, int32 StartIndex, int32 UpperBound );
293
300 SLATE_API int32 FindInsertSlotLocation( const FSlot* InSlot );
301
303 SLATE_API void ComputeDesiredCellSizes( TArray<float>& OutColumns, TArray<float>& OutRows ) const;
304
306 SLATE_API int32 LayoutDebugPaint(const FGeometry& AllottedGeometry, const FSlateRect& MyCullingRect, FSlateWindowElementList& OutDrawElements, int32 LayerId ) const;
307
314 SLATE_API void NotifySlotChanged(const FSlot* InSlot, bool bSlotLayerChanged = false);
315
316private:
317
319 TPanelChildren<FSlot> Slots;
320
325 TArray<float> Columns;
326
331 TArray<float> Rows;
332
334 FVector2D TotalDesiredSizes;
335
339
342};
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 SLATE_SLOT_ARGUMENT(SlotType, SlotName)
Definition DeclarativeSyntaxSupport.h:348
#define SLATE_SLOT_BEGIN_ARGS(SlotType, SlotParentType)
Definition DeclarativeSyntaxSupport.h:361
#define SLATE_END_ARGS()
Definition DeclarativeSyntaxSupport.h:116
#define SLATE_SLOT_END_ARGS()
Definition DeclarativeSyntaxSupport.h:386
#define SLATE_ARGUMENT(ArgType, ArgName)
Definition DeclarativeSyntaxSupport.h:208
#define SLATE_DECLARE_WIDGET_API(WidgetType, ParentType, ModuleApiDefine)
Definition SlateControlledConstruction.h:22
Definition ArrangedChildren.h:15
Definition ChildrenBase.h:27
Definition PaintArgs.h:23
Definition SlateRect.h:26
Definition DrawElements.h:220
Definition WidgetStyle.h:15
Definition SGridPanel.h:37
FVector2D GetNudge() const
Definition SGridPanel.h:154
void SetColumnSpan(int32 ColumnSpan)
Definition SGridPanel.h:93
int32 GetRow() const
Definition SGridPanel.h:105
void SetRow(int32 Row)
Definition SGridPanel.h:110
int32 GetColumn() const
Definition SGridPanel.h:72
void SetRowSpan(int32 RowSpan)
Definition SGridPanel.h:126
void SetLayer(int32 Layer)
Definition SGridPanel.h:143
int32 GetRowSpan() const
Definition SGridPanel.h:121
void SetColumn(int32 Column)
Definition SGridPanel.h:77
int32 GetColumnSpan() const
Definition SGridPanel.h:88
int32 GetLayer() const
Definition SGridPanel.h:138
void SetNudge(const FVector2D &Nudge)
Definition SGridPanel.h:159
FSlot(int32 Column, int32 Row, int32 InLayer)
Definition SGridPanel.h:42
Definition SGridPanel.h:25
int32 TheLayer
Definition SGridPanel.h:33
Layer(int32 InLayer)
Definition SGridPanel.h:27
Definition SGridPanel.h:19
FArguments & FillRow(int32 RowId, const TAttribute< float > &Coefficient)
Definition SGridPanel.h:226
virtual SLATE_API FChildren * GetChildren() override
Definition SGridPanel.cpp:307
SLATE_API bool RemoveSlot(const TSharedRef< SWidget > &SlotWidget)
Definition SGridPanel.cpp:77
virtual SLATE_API int32 OnPaint(const FPaintArgs &Args, const FGeometry &AllottedGeometry, const FSlateRect &MyCullingRect, FSlateWindowElementList &OutDrawElements, int32 LayerId, const FWidgetStyle &InWidgetStyle, bool bParentEnabled) const override
Definition SGridPanel.cpp:118
FArguments & FillColumn(int32 ColumnId, const TAttribute< float > &Coefficient)
Definition SGridPanel.h:215
SLATE_API void ClearFill()
Definition SGridPanel.cpp:353
SLATE_BEGIN_ARGS(SGridPanel)
Definition SGridPanel.h:207
virtual SLATE_API void CacheDesiredSize(float) override
Definition SGridPanel.cpp:281
static SLATE_API FSlot::FSlotArguments Slot(int32 Column, int32 Row, Layer InLayer=Layer(0))
Definition SGridPanel.cpp:54
SLATE_API void SetColumnFill(int32 ColumnId, const TAttribute< float > &Coefficient)
Definition SGridPanel.cpp:331
virtual SLATE_API void OnArrangeChildren(const FGeometry &AllottedGeometry, FArrangedChildren &ArrangedChildren) const override
Definition SGridPanel.cpp:217
SLATE_API FVector2D GetDesiredRegionSize(const FIntPoint &StartCell, int32 Width, int32 Height) const
Definition SGridPanel.cpp:313
SLATE_API void SetRowFill(int32 RowId, const TAttribute< float > &Coefficient)
Definition SGridPanel.cpp:342
SLATE_API void ClearChildren()
Definition SGridPanel.cpp:82
virtual SLATE_API FVector2D ComputeDesiredSize(float) const override
Definition SGridPanel.cpp:301
TArray< TAttribute< float > > ColFillCoefficients
Definition SGridPanel.h:237
SLATE_API FScopedWidgetSlotArguments AddSlot(int32 Column, int32 Row, Layer InLayer=Layer(0))
Definition SGridPanel.cpp:59
TArray< TAttribute< float > > RowFillCoefficients
Definition SGridPanel.h:240
Definition SPanel.h:30
void Construct()
Definition SPanel.h:65
Definition Array.h:670
UE_REWRITE SizeType Num() const
Definition Array.h:1144
UE_FORCEINLINE_HINT SizeType Emplace(ArgsType &&... Args)
Definition Array.h:2561
Definition Attribute.h:17
Definition BasicLayoutWidgetSlot.h:599
FSlotArguments && InArgs
Definition BasicLayoutWidgetSlot.h:630
Definition Children.h:461
Definition SharedPointer.h:153
Definition SharedPointer.h:1295
@ false
Definition radaudio_common.h:23
static SLATECORE_API const EVisibility SelfHitTestInvisible
Definition Visibility.h:26
Definition Geometry.h:40
static constexpr UE_FORCEINLINE_HINT T Clamp(const T X, const T MinValue, const T MaxValue)
Definition UnrealMathUtility.h:592
Definition Optional.h:131
Definition IntPoint.h:25