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 621cc32a9a5676d19a301114 #ROBOMERGE-OWNER: patrick.boutot #ROBOMERGE-AUTHOR: patrick.boutot #ROBOMERGE-SOURCE: CL 19172743 via CL 19172838 via CL 19172865 via CL 19173039 via CL 19173047 via CL 19173891 #ROBOMERGE-BOT: UE5 (Release-Engine-Staging -> Main) (v921-19075845) [CL 19174092 by patrick boutot in ue5-main branch]
256 lines
6.8 KiB
C++
256 lines
6.8 KiB
C++
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
#include "Components/EditableTextBox.h"
|
|
#include "UObject/ConstructorHelpers.h"
|
|
#include "Engine/Font.h"
|
|
#include "Widgets/DeclarativeSyntaxSupport.h"
|
|
#include "Widgets/Input/SEditableTextBox.h"
|
|
#include "Styling/UMGCoreStyle.h"
|
|
|
|
#define LOCTEXT_NAMESPACE "UMG"
|
|
|
|
/////////////////////////////////////////////////////
|
|
// UEditableTextBox
|
|
|
|
static FEditableTextBoxStyle* DefaultEditableTextBoxStyle = nullptr;
|
|
|
|
#if WITH_EDITOR
|
|
static FEditableTextBoxStyle* EditorEditableTextBoxStyle = nullptr;
|
|
#endif
|
|
|
|
UEditableTextBox::UEditableTextBox(const FObjectInitializer& ObjectInitializer)
|
|
: Super(ObjectInitializer)
|
|
{
|
|
IsReadOnly = false;
|
|
IsPassword = false;
|
|
MinimumDesiredWidth = 0.0f;
|
|
IsCaretMovedWhenGainFocus = true;
|
|
SelectAllTextWhenFocused = false;
|
|
RevertTextOnEscape = false;
|
|
ClearKeyboardFocusOnCommit = true;
|
|
SelectAllTextOnCommit = false;
|
|
AllowContextMenu = true;
|
|
VirtualKeyboardDismissAction = EVirtualKeyboardDismissAction::TextChangeOnDismiss;
|
|
OverflowPolicy = ETextOverflowPolicy::Clip;
|
|
|
|
if (DefaultEditableTextBoxStyle == nullptr)
|
|
{
|
|
DefaultEditableTextBoxStyle = new FEditableTextBoxStyle(FUMGCoreStyle::Get().GetWidgetStyle<FEditableTextBoxStyle>("NormalEditableTextBox"));
|
|
|
|
// Unlink UMG default colors.
|
|
DefaultEditableTextBoxStyle->UnlinkColors();
|
|
}
|
|
|
|
WidgetStyle = *DefaultEditableTextBoxStyle;
|
|
|
|
#if WITH_EDITOR
|
|
if (EditorEditableTextBoxStyle == nullptr)
|
|
{
|
|
EditorEditableTextBoxStyle = new FEditableTextBoxStyle(FCoreStyle::Get().GetWidgetStyle<FEditableTextBoxStyle>("NormalEditableTextBox"));
|
|
|
|
// Unlink UMG Editor colors from the editor settings colors.
|
|
EditorEditableTextBoxStyle->UnlinkColors();
|
|
}
|
|
|
|
if (IsEditorWidget())
|
|
{
|
|
WidgetStyle = *EditorEditableTextBoxStyle;
|
|
|
|
// 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
|
|
|
|
#if WITH_EDITORONLY_DATA
|
|
AccessibleBehavior = ESlateAccessibleBehavior::Auto;
|
|
bCanChildrenBeAccessible = false;
|
|
#endif
|
|
}
|
|
|
|
void UEditableTextBox::ReleaseSlateResources(bool bReleaseChildren)
|
|
{
|
|
Super::ReleaseSlateResources(bReleaseChildren);
|
|
|
|
MyEditableTextBlock.Reset();
|
|
}
|
|
|
|
TSharedRef<SWidget> UEditableTextBox::RebuildWidget()
|
|
{
|
|
MyEditableTextBlock = SNew(SEditableTextBox)
|
|
.Style(&WidgetStyle)
|
|
.MinDesiredWidth(MinimumDesiredWidth)
|
|
.IsCaretMovedWhenGainFocus(IsCaretMovedWhenGainFocus)
|
|
.SelectAllTextWhenFocused(SelectAllTextWhenFocused)
|
|
.RevertTextOnEscape(RevertTextOnEscape)
|
|
.ClearKeyboardFocusOnCommit(ClearKeyboardFocusOnCommit)
|
|
.SelectAllTextOnCommit(SelectAllTextOnCommit)
|
|
.AllowContextMenu(AllowContextMenu)
|
|
.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);
|
|
|
|
return MyEditableTextBlock.ToSharedRef();
|
|
}
|
|
|
|
void UEditableTextBox::SynchronizeProperties()
|
|
{
|
|
Super::SynchronizeProperties();
|
|
|
|
TAttribute<FText> TextBinding = PROPERTY_BINDING(FText, Text);
|
|
TAttribute<FText> HintTextBinding = PROPERTY_BINDING(FText, HintText);
|
|
|
|
MyEditableTextBlock->SetStyle(&WidgetStyle);
|
|
MyEditableTextBlock->SetText(TextBinding);
|
|
MyEditableTextBlock->SetHintText(HintTextBinding);
|
|
MyEditableTextBlock->SetIsReadOnly(IsReadOnly);
|
|
MyEditableTextBlock->SetIsPassword(IsPassword);
|
|
MyEditableTextBlock->SetMinimumDesiredWidth(MinimumDesiredWidth);
|
|
MyEditableTextBlock->SetIsCaretMovedWhenGainFocus(IsCaretMovedWhenGainFocus);
|
|
MyEditableTextBlock->SetSelectAllTextWhenFocused(SelectAllTextWhenFocused);
|
|
MyEditableTextBlock->SetRevertTextOnEscape(RevertTextOnEscape);
|
|
MyEditableTextBlock->SetClearKeyboardFocusOnCommit(ClearKeyboardFocusOnCommit);
|
|
MyEditableTextBlock->SetSelectAllTextOnCommit(SelectAllTextOnCommit);
|
|
MyEditableTextBlock->SetAllowContextMenu(AllowContextMenu);
|
|
MyEditableTextBlock->SetVirtualKeyboardDismissAction(VirtualKeyboardDismissAction);
|
|
MyEditableTextBlock->SetJustification(Justification);
|
|
MyEditableTextBlock->SetOverflowPolicy(OverflowPolicy);
|
|
|
|
ShapedTextOptions.SynchronizeShapedTextProperties(*MyEditableTextBlock);
|
|
}
|
|
|
|
FText UEditableTextBox::GetText() const
|
|
{
|
|
if ( MyEditableTextBlock.IsValid() )
|
|
{
|
|
return MyEditableTextBlock->GetText();
|
|
}
|
|
|
|
return Text;
|
|
}
|
|
|
|
void UEditableTextBox::SetText(FText InText)
|
|
{
|
|
Text = InText;
|
|
if ( MyEditableTextBlock.IsValid() )
|
|
{
|
|
MyEditableTextBlock->SetText(Text);
|
|
}
|
|
}
|
|
|
|
void UEditableTextBox::SetHintText(FText InText)
|
|
{
|
|
HintText = InText;
|
|
if (MyEditableTextBlock.IsValid())
|
|
{
|
|
MyEditableTextBlock->SetHintText(HintText);
|
|
}
|
|
}
|
|
|
|
void UEditableTextBox::SetForegroundColor(FLinearColor color)
|
|
{
|
|
WidgetStyle.ForegroundColor = color;
|
|
if ( MyEditableTextBlock.IsValid() )
|
|
{
|
|
MyEditableTextBlock->SetForegroundColor(color);
|
|
}
|
|
}
|
|
|
|
void UEditableTextBox::SetError(FText InError)
|
|
{
|
|
if ( MyEditableTextBlock.IsValid() )
|
|
{
|
|
MyEditableTextBlock->SetError(InError);
|
|
}
|
|
}
|
|
|
|
void UEditableTextBox::SetIsReadOnly(bool bReadOnly)
|
|
{
|
|
IsReadOnly = bReadOnly;
|
|
if ( MyEditableTextBlock.IsValid() )
|
|
{
|
|
MyEditableTextBlock->SetIsReadOnly(IsReadOnly);
|
|
}
|
|
}
|
|
|
|
void UEditableTextBox::SetIsPassword(bool bIsPassword)
|
|
{
|
|
IsPassword = bIsPassword;
|
|
if (MyEditableTextBlock.IsValid())
|
|
{
|
|
MyEditableTextBlock->SetIsPassword(IsPassword);
|
|
}
|
|
}
|
|
|
|
void UEditableTextBox::ClearError()
|
|
{
|
|
if ( MyEditableTextBlock.IsValid() )
|
|
{
|
|
MyEditableTextBlock->SetError(FText::GetEmpty());
|
|
}
|
|
}
|
|
|
|
bool UEditableTextBox::HasError() const
|
|
{
|
|
if ( MyEditableTextBlock.IsValid() )
|
|
{
|
|
return MyEditableTextBlock->HasError();
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
void UEditableTextBox::SetJustification(ETextJustify::Type InJustification)
|
|
{
|
|
Justification = InJustification;
|
|
if (MyEditableTextBlock.IsValid())
|
|
{
|
|
MyEditableTextBlock->SetJustification(InJustification);
|
|
}
|
|
}
|
|
|
|
void UEditableTextBox::SetTextOverflowPolicy(ETextOverflowPolicy InOverflowPolicy)
|
|
{
|
|
OverflowPolicy = InOverflowPolicy;
|
|
if (MyEditableTextBlock.IsValid())
|
|
{
|
|
MyEditableTextBlock->SetOverflowPolicy(InOverflowPolicy);
|
|
}
|
|
}
|
|
|
|
void UEditableTextBox::HandleOnTextChanged(const FText& InText)
|
|
{
|
|
Text = InText;
|
|
OnTextChanged.Broadcast(InText);
|
|
}
|
|
|
|
void UEditableTextBox::HandleOnTextCommitted(const FText& InText, ETextCommit::Type CommitMethod)
|
|
{
|
|
Text = InText;
|
|
OnTextCommitted.Broadcast(InText, CommitMethod);
|
|
}
|
|
|
|
#if WITH_ACCESSIBILITY
|
|
TSharedPtr<SWidget> UEditableTextBox::GetAccessibleWidget() const
|
|
{
|
|
return MyEditableTextBlock;
|
|
}
|
|
#endif
|
|
|
|
#if WITH_EDITOR
|
|
|
|
const FText UEditableTextBox::GetPaletteCategory()
|
|
{
|
|
return LOCTEXT("Input", "Input");
|
|
}
|
|
|
|
#endif
|
|
|
|
/////////////////////////////////////////////////////
|
|
|
|
#undef LOCTEXT_NAMESPACE
|