Files
UnrealEngineUWP/Engine/Source/Runtime/UMG/Private/Components/VerticalBoxSlot.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

120 lines
2.9 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "Components/VerticalBoxSlot.h"
#include "Components/Widget.h"
#include "Components/VerticalBox.h"
/////////////////////////////////////////////////////
// UVerticalBoxSlot
UVerticalBoxSlot::UVerticalBoxSlot(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
, Slot(nullptr)
{
HorizontalAlignment = HAlign_Fill;
VerticalAlignment = VAlign_Fill;
Size = FSlateChildSize(ESlateSizeRule::Automatic);
}
void UVerticalBoxSlot::ReleaseSlateResources(bool bReleaseChildren)
{
Super::ReleaseSlateResources(bReleaseChildren);
Slot = nullptr;
}
void UVerticalBoxSlot::BuildSlot(TSharedRef<SVerticalBox> VerticalBox)
{
VerticalBox->AddSlot()
.Expose(Slot)
.Padding(Padding)
.HAlign(HorizontalAlignment)
.VAlign(VerticalAlignment)
.SizeParam(UWidget::ConvertSerializedSizeParamToRuntime(Size))
.Expose(Slot)
[
Content == nullptr ? SNullWidget::NullWidget : Content->TakeWidget()
];
}
void UVerticalBoxSlot::SetPadding(FMargin InPadding)
{
Padding = InPadding;
if ( Slot )
{
Slot->SetPadding(InPadding);
}
}
void UVerticalBoxSlot::SetSize(FSlateChildSize InSize)
{
Size = InSize;
if ( Slot )
{
Slot->SetSizeParam(UWidget::ConvertSerializedSizeParamToRuntime(InSize));
}
}
void UVerticalBoxSlot::SetHorizontalAlignment(EHorizontalAlignment InHorizontalAlignment)
{
HorizontalAlignment = InHorizontalAlignment;
if ( Slot )
{
Slot->SetHorizontalAlignment(InHorizontalAlignment);
}
}
void UVerticalBoxSlot::SetVerticalAlignment(EVerticalAlignment InVerticalAlignment)
{
VerticalAlignment = InVerticalAlignment;
if ( Slot )
{
Slot->SetVerticalAlignment(InVerticalAlignment);
}
}
void UVerticalBoxSlot::SynchronizeProperties()
{
SetPadding(Padding);
SetSize(Size);
SetHorizontalAlignment(HorizontalAlignment);
SetVerticalAlignment(VerticalAlignment);
}
#if WITH_EDITOR
bool UVerticalBoxSlot::NudgeByDesigner(const FVector2D& NudgeDirection, const TOptional<int32>& GridSnapSize)
{
if (NudgeDirection.Y == 0)
{
return false;
}
const FVector2D ClampedDirection = NudgeDirection.ClampAxes(-1, 1);
UVerticalBox* ParentVerticalBox = CastChecked<UVerticalBox>(Parent);
const int32 CurrentIndex = ParentVerticalBox->GetChildIndex(Content);
if ((CurrentIndex == 0 && ClampedDirection.Y < 0.0f) ||
(CurrentIndex + 1 >= ParentVerticalBox->GetChildrenCount() && ClampedDirection.Y > 0.0f))
{
return false;
}
ParentVerticalBox->Modify();
ParentVerticalBox->ShiftChild(CurrentIndex + ClampedDirection.Y, Content);
return true;
}
void UVerticalBoxSlot::SynchronizeFromTemplate(const UPanelSlot* const TemplateSlot)
{
const ThisClass* const TemplateVerticalBoxSlot = CastChecked<ThisClass>(TemplateSlot);
const int32 CurrentIndex = TemplateVerticalBoxSlot->Parent->GetChildIndex(TemplateVerticalBoxSlot->Content);
UVerticalBox* ParentVerticalBox = CastChecked<UVerticalBox>(Parent);
ParentVerticalBox->ShiftChild(CurrentIndex, Content);
}
#endif