Files
UnrealEngineUWP/Engine/Source/Runtime/UMG/Private/Components/UniformGridSlot.cpp
benui-dev ed58490cf7 PR #8311: Added arrow key shortcuts to change order of Widgets in Panels (Contributed by benui-dev)
#rb vincent.gauthier
#preflight 61e0a52f0f52107164b1da26

#ROBOMERGE-AUTHOR: vincent.gauthier
#ROBOMERGE-SOURCE: CL 18607252 in //UE5/Release-5.0/... via CL 18607270 via CL 18607303
#ROBOMERGE-BOT: UE5 (Release-Engine-Test -> Main) (v899-18417669)

[CL 18607330 by benui-dev in ue5-main branch]
2022-01-13 17:37:40 -05:00

108 lines
2.3 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "Components/UniformGridSlot.h"
#include "Components/Widget.h"
/////////////////////////////////////////////////////
// UUniformGridSlot
UUniformGridSlot::UUniformGridSlot(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
, Slot(nullptr)
{
HorizontalAlignment = HAlign_Left;
VerticalAlignment = VAlign_Top;
}
void UUniformGridSlot::ReleaseSlateResources(bool bReleaseChildren)
{
Super::ReleaseSlateResources(bReleaseChildren);
Slot = nullptr;
}
void UUniformGridSlot::BuildSlot(TSharedRef<SUniformGridPanel> GridPanel)
{
GridPanel->AddSlot(Column, Row)
.Expose(Slot)
.HAlign(HorizontalAlignment)
.VAlign(VerticalAlignment)
[
Content == nullptr ? SNullWidget::NullWidget : Content->TakeWidget()
];
}
void UUniformGridSlot::SetRow(int32 InRow)
{
Row = InRow;
if ( Slot )
{
Slot->SetRow(InRow);
}
}
void UUniformGridSlot::SetColumn(int32 InColumn)
{
Column = InColumn;
if ( Slot )
{
Slot->SetColumn(InColumn);
}
}
void UUniformGridSlot::SetHorizontalAlignment(EHorizontalAlignment InHorizontalAlignment)
{
HorizontalAlignment = InHorizontalAlignment;
if ( Slot )
{
Slot->SetHorizontalAlignment(InHorizontalAlignment);
}
}
void UUniformGridSlot::SetVerticalAlignment(EVerticalAlignment InVerticalAlignment)
{
VerticalAlignment = InVerticalAlignment;
if ( Slot )
{
Slot->SetVerticalAlignment(InVerticalAlignment);
}
}
void UUniformGridSlot::SynchronizeProperties()
{
SetRow(Row);
SetColumn(Column);
SetHorizontalAlignment(HorizontalAlignment);
SetVerticalAlignment(VerticalAlignment);
}
#if WITH_EDITOR
bool UUniformGridSlot::NudgeByDesigner(const FVector2D& NudgeDirection, const TOptional<int32>& GridSnapSize)
{
const FVector2D ClampedDirection = NudgeDirection.ClampAxes(-1.0f, 1.0f);
const int32 NewColumn = Column + ClampedDirection.X;
const int32 NewRow = Row + ClampedDirection.Y;
if (NewColumn < 0 || NewRow < 0 || (NewColumn == Column && NewRow == Row))
{
return false;
}
Modify();
SetRow(NewRow);
SetColumn(NewColumn);
return true;
}
void UUniformGridSlot::SynchronizeFromTemplate(const UPanelSlot* const TemplateSlot)
{
const ThisClass* const TemplateUniformGridSlot = CastChecked<ThisClass>(TemplateSlot);
SetRow(TemplateUniformGridSlot->Row);
SetColumn(TemplateUniformGridSlot->Column);
}
#endif