You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
#rb vincent.gauthier #preflight 627a4e42705bfaf9ae31ee20 #ROBOMERGE-AUTHOR: patrick.boutot #ROBOMERGE-SOURCE: CL 20123512 via CL 20123528 via CL 20123564 #ROBOMERGE-BOT: UE5 (Release-Engine-Staging -> Main) (v943-19904690) [CL 20125750 by patrick boutot in ue5-main branch]
296 lines
7.2 KiB
C++
296 lines
7.2 KiB
C++
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
#include "Components/EditableText.h"
|
|
#include "UObject/ConstructorHelpers.h"
|
|
#include "Engine/Font.h"
|
|
#include "Widgets/DeclarativeSyntaxSupport.h"
|
|
#include "Widgets/Input/SEditableText.h"
|
|
#include "Slate/SlateBrushAsset.h"
|
|
#include "Styling/UMGCoreStyle.h"
|
|
|
|
#define LOCTEXT_NAMESPACE "UMG"
|
|
|
|
/////////////////////////////////////////////////////
|
|
// UEditableText
|
|
|
|
static FEditableTextStyle* DefaultEditableTextStyle = nullptr;
|
|
|
|
#if WITH_EDITOR
|
|
static FEditableTextStyle* EditorEditableTextStyle = nullptr;
|
|
#endif
|
|
|
|
UEditableText::UEditableText(const FObjectInitializer& ObjectInitializer)
|
|
: Super(ObjectInitializer)
|
|
{
|
|
if (DefaultEditableTextStyle == nullptr)
|
|
{
|
|
DefaultEditableTextStyle = new FEditableTextStyle(FUMGCoreStyle::Get().GetWidgetStyle<FEditableTextStyle>("NormalEditableText"));
|
|
|
|
// Unlink UMG default colors.
|
|
DefaultEditableTextStyle->UnlinkColors();
|
|
}
|
|
|
|
WidgetStyle = *DefaultEditableTextStyle;
|
|
|
|
#if WITH_EDITOR
|
|
if (EditorEditableTextStyle == nullptr)
|
|
{
|
|
EditorEditableTextStyle = new FEditableTextStyle(FCoreStyle::Get().GetWidgetStyle<FEditableTextStyle>("NormalEditableText"));
|
|
|
|
// Unlink UMG Editor colors from the editor settings colors.
|
|
EditorEditableTextStyle->UnlinkColors();
|
|
}
|
|
|
|
if (IsEditorWidget())
|
|
{
|
|
WidgetStyle = *EditorEditableTextStyle;
|
|
|
|
// The CDO isn't an editor widget and thus won't use the editor style, call post edit change to mark difference from CDO
|
|
PostEditChange();
|
|
}
|
|
#endif // WITH_EDITOR
|
|
|
|
PRAGMA_DISABLE_DEPRECATION_WARNINGS
|
|
IsReadOnly = false;
|
|
IsPassword = false;
|
|
MinimumDesiredWidth = 0.0f;
|
|
IsCaretMovedWhenGainFocus = true;
|
|
SelectAllTextWhenFocused = false;
|
|
RevertTextOnEscape = false;
|
|
ClearKeyboardFocusOnCommit = true;
|
|
SelectAllTextOnCommit = false;
|
|
AllowContextMenu = true;
|
|
VirtualKeyboardTrigger = EVirtualKeyboardTrigger::OnFocusByPointer;
|
|
VirtualKeyboardDismissAction = EVirtualKeyboardDismissAction::TextChangeOnDismiss;
|
|
SetClipping(EWidgetClipping::ClipToBounds);
|
|
OverflowPolicy = ETextOverflowPolicy::Clip;
|
|
PRAGMA_ENABLE_DEPRECATION_WARNINGS
|
|
|
|
#if WITH_EDITORONLY_DATA
|
|
AccessibleBehavior = ESlateAccessibleBehavior::Auto;
|
|
bCanChildrenBeAccessible = false;
|
|
#endif
|
|
}
|
|
|
|
void UEditableText::ReleaseSlateResources(bool bReleaseChildren)
|
|
{
|
|
Super::ReleaseSlateResources(bReleaseChildren);
|
|
|
|
MyEditableText.Reset();
|
|
}
|
|
|
|
TSharedRef<SWidget> UEditableText::RebuildWidget()
|
|
{
|
|
PRAGMA_DISABLE_DEPRECATION_WARNINGS
|
|
MyEditableText = SNew(SEditableText)
|
|
.Style(&WidgetStyle)
|
|
.MinDesiredWidth(MinimumDesiredWidth)
|
|
.IsCaretMovedWhenGainFocus(IsCaretMovedWhenGainFocus)
|
|
.SelectAllTextWhenFocused(SelectAllTextWhenFocused)
|
|
.RevertTextOnEscape(RevertTextOnEscape)
|
|
.ClearKeyboardFocusOnCommit(ClearKeyboardFocusOnCommit)
|
|
.SelectAllTextOnCommit(SelectAllTextOnCommit)
|
|
.OnTextChanged(BIND_UOBJECT_DELEGATE(FOnTextChanged, HandleOnTextChanged))
|
|
.OnTextCommitted(BIND_UOBJECT_DELEGATE(FOnTextCommitted, HandleOnTextCommitted))
|
|
.VirtualKeyboardType(EVirtualKeyboardType::AsKeyboardType(KeyboardType.GetValue()))
|
|
.VirtualKeyboardOptions(VirtualKeyboardOptions)
|
|
.VirtualKeyboardTrigger(VirtualKeyboardTrigger)
|
|
.VirtualKeyboardDismissAction(VirtualKeyboardDismissAction)
|
|
.Justification(Justification)
|
|
.OverflowPolicy(OverflowPolicy);
|
|
PRAGMA_ENABLE_DEPRECATION_WARNINGS
|
|
|
|
return MyEditableText.ToSharedRef();
|
|
}
|
|
|
|
void UEditableText::SynchronizeProperties()
|
|
{
|
|
Super::SynchronizeProperties();
|
|
|
|
|
|
PRAGMA_DISABLE_DEPRECATION_WARNINGS
|
|
|
|
TAttribute<FText> TextBinding = PROPERTY_BINDING(FText, Text);
|
|
TAttribute<FText> HintTextBinding = PROPERTY_BINDING(FText, HintText);
|
|
|
|
MyEditableText->SetText(TextBinding);
|
|
MyEditableText->SetHintText(HintTextBinding);
|
|
MyEditableText->SetIsReadOnly(IsReadOnly);
|
|
MyEditableText->SetIsPassword(IsPassword);
|
|
MyEditableText->SetAllowContextMenu(AllowContextMenu);
|
|
MyEditableText->SetVirtualKeyboardDismissAction(VirtualKeyboardDismissAction);
|
|
MyEditableText->SetJustification(Justification);
|
|
MyEditableText->SetOverflowPolicy(OverflowPolicy);
|
|
|
|
PRAGMA_ENABLE_DEPRECATION_WARNINGS
|
|
|
|
// TODO UMG Complete making all properties settable on SEditableText
|
|
|
|
ShapedTextOptions.SynchronizeShapedTextProperties(*MyEditableText);
|
|
}
|
|
|
|
|
|
PRAGMA_DISABLE_DEPRECATION_WARNINGS
|
|
|
|
FText UEditableText::GetText() const
|
|
{
|
|
if ( MyEditableText.IsValid() )
|
|
{
|
|
return MyEditableText->GetText();
|
|
}
|
|
|
|
return Text;
|
|
}
|
|
|
|
void UEditableText::SetText(FText InText)
|
|
{
|
|
// We detect if the Text is internal pointing to the same thing if so, nothing to do.
|
|
if (Text.IdenticalTo(InText))
|
|
{
|
|
return;
|
|
}
|
|
|
|
Text = InText;
|
|
|
|
BroadcastFieldValueChanged(FFieldNotificationClassDescriptor::Text);
|
|
|
|
if ( MyEditableText.IsValid() )
|
|
{
|
|
MyEditableText->SetText(Text);
|
|
}
|
|
}
|
|
|
|
void UEditableText::SetIsPassword(bool InbIsPassword)
|
|
{
|
|
IsPassword = InbIsPassword;
|
|
if ( MyEditableText.IsValid() )
|
|
{
|
|
MyEditableText->SetIsPassword(IsPassword);
|
|
}
|
|
}
|
|
|
|
FText UEditableText::GetHintText() const
|
|
{
|
|
if (MyEditableText.IsValid())
|
|
{
|
|
return MyEditableText->GetHintText();
|
|
}
|
|
|
|
return HintText;
|
|
}
|
|
|
|
void UEditableText::SetHintText(FText InHintText)
|
|
{
|
|
HintText = InHintText;
|
|
if ( MyEditableText.IsValid() )
|
|
{
|
|
MyEditableText->SetHintText(HintText);
|
|
}
|
|
}
|
|
|
|
float UEditableText::GetMinimumDesiredWidth() const
|
|
{
|
|
return MinimumDesiredWidth;
|
|
}
|
|
|
|
void UEditableText::SetMinimumDesiredWidth(float InMinDesiredWidth)
|
|
{
|
|
MinimumDesiredWidth = InMinDesiredWidth;
|
|
if (MyEditableText.IsValid())
|
|
{
|
|
MyEditableText->SetMinDesiredWidth(MinimumDesiredWidth);
|
|
}
|
|
}
|
|
|
|
bool UEditableText::GetIsReadOnly() const
|
|
{
|
|
return IsReadOnly;
|
|
}
|
|
|
|
void UEditableText::SetIsReadOnly(bool InbIsReadyOnly)
|
|
{
|
|
IsReadOnly = InbIsReadyOnly;
|
|
if ( MyEditableText.IsValid() )
|
|
{
|
|
MyEditableText->SetIsReadOnly(IsReadOnly);
|
|
}
|
|
}
|
|
|
|
|
|
bool UEditableText::GetIsPassword() const
|
|
{
|
|
return IsPassword;
|
|
}
|
|
|
|
|
|
ETextJustify::Type UEditableText::GetJustification() const
|
|
{
|
|
return Justification;
|
|
}
|
|
|
|
void UEditableText::SetJustification(ETextJustify::Type InJustification)
|
|
{
|
|
Justification = InJustification;
|
|
if (MyEditableText.IsValid())
|
|
{
|
|
MyEditableText->SetJustification(InJustification);
|
|
}
|
|
}
|
|
|
|
ETextOverflowPolicy UEditableText::GetTextOverflowPolicy() const
|
|
{
|
|
return OverflowPolicy;
|
|
}
|
|
|
|
void UEditableText::SetTextOverflowPolicy(ETextOverflowPolicy InOverflowPolicy)
|
|
{
|
|
OverflowPolicy = InOverflowPolicy;
|
|
if (MyEditableText.IsValid())
|
|
{
|
|
MyEditableText->SetOverflowPolicy(InOverflowPolicy);
|
|
}
|
|
}
|
|
|
|
PRAGMA_ENABLE_DEPRECATION_WARNINGS
|
|
|
|
void UEditableText::SetClearKeyboardFocusOnCommit(bool bInClearKeyboardFocusOnCommit)
|
|
{
|
|
ClearKeyboardFocusOnCommit = bInClearKeyboardFocusOnCommit;
|
|
MyEditableText->SetClearKeyboardFocusOnCommit(ClearKeyboardFocusOnCommit);
|
|
}
|
|
|
|
void UEditableText::SetKeyboardType(EVirtualKeyboardType::Type Type)
|
|
{
|
|
KeyboardType = Type;
|
|
}
|
|
|
|
void UEditableText::HandleOnTextChanged(const FText& InText)
|
|
{
|
|
OnTextChanged.Broadcast(InText);
|
|
}
|
|
|
|
void UEditableText::HandleOnTextCommitted(const FText& InText, ETextCommit::Type CommitMethod)
|
|
{
|
|
OnTextCommitted.Broadcast(InText, CommitMethod);
|
|
}
|
|
|
|
#if WITH_ACCESSIBILITY
|
|
TSharedPtr<SWidget> UEditableText::GetAccessibleWidget() const
|
|
{
|
|
return MyEditableText;
|
|
}
|
|
#endif
|
|
|
|
#if WITH_EDITOR
|
|
|
|
const FText UEditableText::GetPaletteCategory()
|
|
{
|
|
return LOCTEXT("Input", "Input");
|
|
}
|
|
|
|
#endif
|
|
|
|
/////////////////////////////////////////////////////
|
|
|
|
#undef LOCTEXT_NAMESPACE
|