Files
UnrealEngineUWP/Engine/Source/Editor/DetailCustomizations/Private/KeyStructCustomization.cpp
ryan durand 627baf970a Updating copyright for Engine Editor.
#rnx
#rb none


#ROBOMERGE-SOURCE: CL 10869241 via CL 10869527 via CL 10869904
#ROBOMERGE-BOT: (v613-10869866)

[CL 10870586 by ryan durand in Main branch]
2019-12-26 15:33:43 -05:00

77 lines
2.0 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "KeyStructCustomization.h"
#include "DetailWidgetRow.h"
#include "SKeySelector.h"
#include "UObject/UnrealType.h"
#define LOCTEXT_NAMESPACE "FKeyStructCustomization"
/* FKeyStructCustomization static interface
*****************************************************************************/
TSharedRef<IPropertyTypeCustomization> FKeyStructCustomization::MakeInstance( )
{
return MakeShareable(new FKeyStructCustomization);
}
/* IPropertyTypeCustomization interface
*****************************************************************************/
void FKeyStructCustomization::CustomizeHeader( TSharedRef<class IPropertyHandle> StructPropertyHandle, class FDetailWidgetRow& HeaderRow, IPropertyTypeCustomizationUtils& StructCustomizationUtils )
{
PropertyHandle = StructPropertyHandle;
// create struct header
HeaderRow.NameContent()
[
StructPropertyHandle->CreatePropertyNameWidget()
]
.ValueContent()
.MinDesiredWidth(125.0f)
.MaxDesiredWidth(325.0f)
[
SNew(SKeySelector)
.CurrentKey(this, &FKeyStructCustomization::GetCurrentKey)
.OnKeyChanged(this, &FKeyStructCustomization::OnKeyChanged)
.Font(StructCustomizationUtils.GetRegularFont())
.AllowClear(!StructPropertyHandle->GetProperty()->HasAnyPropertyFlags(CPF_NoClear))
.FilterBlueprintBindable(false)
];
}
TOptional<FKey> FKeyStructCustomization::GetCurrentKey() const
{
TArray<void*> StructPtrs;
PropertyHandle->AccessRawData(StructPtrs);
if (StructPtrs.Num() > 0)
{
FKey* SelectedKey = (FKey*)StructPtrs[0];
if (SelectedKey)
{
for(int32 StructPtrIndex = 1; StructPtrIndex < StructPtrs.Num(); ++StructPtrIndex)
{
if (*(FKey*)StructPtrs[StructPtrIndex] != *SelectedKey)
{
return TOptional<FKey>();
}
}
return *SelectedKey;
}
}
return FKey();
}
void FKeyStructCustomization::OnKeyChanged(TSharedPtr<FKey> SelectedKey)
{
PropertyHandle->SetValueFromFormattedString(SelectedKey->ToString());
}
#undef LOCTEXT_NAMESPACE