A Demo Project for the UnrealEngineSDK
Loading...
Searching...
No Matches
SDialogueTextPropertyEditableTextBox.h
Go to the documentation of this file.
1// Copyright Csaba Molnar, Daniel Butum. All Rights Reserved.
2#pragma once
3#include "CoreMinimal.h"
4#include "Widgets/SCompoundWidget.h"
5#include "Styling/CoreStyle.h"
6#include "STextPropertyEditableTextBox.h"
7#include "PropertyHandle.h"
8
9DECLARE_MULTICAST_DELEGATE_TwoParams(FDialogueTextCommitedDelegate, const FText&, ETextCommit::Type);
10DECLARE_MULTICAST_DELEGATE_OneParam(FDialogueTextChangedDelegate, const FText&);
11
12
13// Own STextPropertyEditableTextBox version with custom modifications
14// Used to edit FText multiline FText instances
16{
18
20 : _Style(&FCoreStyle::Get().GetWidgetStyle<FEditableTextBoxStyle>("NormalEditableTextBox"))
21 , _Font()
22 , _ForegroundColor()
23 , _ReadOnlyForegroundColor()
24 , _WrapTextAt(0.0f)
25 , _AutoWrapText(true)
26 , _SelectAllTextWhenFocused(false)
27 , _ClearKeyboardFocusOnCommit(false)
28 , _SelectAllTextOnCommit(false)
29 , _AddResetToDefaultWidget(true)
30 , _ModiferKeyForNewLine(EModifierKey::None)
31
32 // Similar to TextProperty, see FTextCustomization
33 , _MinDesiredWidth(209.f)
34 , _MaxDesiredHeight(600.f)
35 {}
37 SLATE_STYLE_ARGUMENT(FEditableTextBoxStyle, Style)
38
39
40 SLATE_ATTRIBUTE(FSlateFontInfo, Font)
41
42
43 SLATE_ATTRIBUTE(FSlateColor, ForegroundColor)
44
45
46 SLATE_ATTRIBUTE(FSlateColor, ReadOnlyForegroundColor)
47
48
49 SLATE_ATTRIBUTE(float, WrapTextAt)
50
51
52 SLATE_ATTRIBUTE(bool, AutoWrapText)
53
54
55 SLATE_ATTRIBUTE(bool, SelectAllTextWhenFocused)
56
57
58 SLATE_ATTRIBUTE(bool, ClearKeyboardFocusOnCommit)
59
60
61 SLATE_ATTRIBUTE(bool, SelectAllTextOnCommit)
62
63 // Add reset to default buton
64 SLATE_ARGUMENT(bool, AddResetToDefaultWidget)
65
66
67 SLATE_ARGUMENT(EModifierKey::Type, ModiferKeyForNewLine)
68
69
70 SLATE_ATTRIBUTE(FOptionalSize, MinDesiredWidth)
71
72
73 SLATE_ATTRIBUTE(FOptionalSize, MaxDesiredHeight)
74 SLATE_END_ARGS()
75
76public:
77 void Construct(
78 const FArguments& Arguments,
79 const TSharedRef<IEditableTextProperty>& InEditableTextProperty,
80 const TSharedRef<IPropertyHandle>& InPropertyHandle
81 );
82 bool SupportsKeyboardFocus() const override;
83 FReply OnFocusReceived(const FGeometry& MyGeometry, const FFocusEvent& InFocusEvent) override;
84 void Tick(const FGeometry& AllottedGeometry, double InCurrentTime, float InDeltaTime) override;
85
86 FText GetTextValue() const;
87 void SetTextValue(const FText& NewValue);
88
89 FDialogueTextCommitedDelegate& OnTextCommittedEvent() { return TextCommittedEvent; }
90 FDialogueTextChangedDelegate& OnTextChangedEvent() { return TextChangedEvent; }
91
92private:
93 void GetDesiredWidth(float& OutMinDesiredWidth, float& OutMaxDesiredWidth);
94 bool CanEdit() const;
96 bool IsSourceTextReadOnly() const;
97
98 bool WillNamespaceBeUpdated() const;
99 bool IsNamespaceReadOnly() const;
100 bool IsKeyReadOnly() const { return IsIdentityReadOnly(); }
101 bool IsIdentityReadOnly() const;
102
103 FText GetToolTipText() const;
104 EVisibility GetLocalizableVisibility() const;
105
106 void OnTextChanged(const FText& NewText);
107 void OnTextCommitted(const FText& NewText, ETextCommit::Type CommitInfo);
108 void SetTextError(const FText& InErrorMsg);
109
110 FText GetNamespaceValue() const;
111 void OnNamespaceChanged(const FText& NewText);
112 void OnNamespaceCommitted(const FText& NewText, ETextCommit::Type CommitInfo);
113
114 FText GetKeyValue() const;
115#if USE_STABLE_LOCALIZATION_KEYS
116 void OnKeyChanged(const FText& NewText);
117 void OnKeyCommitted(const FText& NewText, ETextCommit::Type CommitInfo);
118
119 FText GetPackageValue() const;
120#endif // USE_STABLE_LOCALIZATION_KEYS
121
122 ECheckBoxState GetLocalizableCheckState(bool bActiveState) const;
123
124 void HandleLocalizableCheckStateChanged(ECheckBoxState InCheckboxState, bool bActiveState);
125
127 EVisibility GetTextWarningImageVisibility() const;
128
129 bool IsValidIdentity(const FText& InIdentity, FText* OutReason = nullptr, const FText* InErrorCtx = nullptr) const;
130
131 // Reset to default
132 FText GetResetToolTip() const;
133 EVisibility GetDiffersFromDefaultAsVisibility() const;
134 FReply OnResetClicked();
135
136protected:
137 // Events
138 FDialogueTextCommitedDelegate TextCommittedEvent;
139 FDialogueTextChangedDelegate TextChangedEvent;
140
141 // Property variables
142 TSharedPtr<IEditableTextProperty> EditableTextProperty;
143 TSharedPtr<IPropertyHandle> PropertyHandle;
144
145 TSharedPtr<SWidget> PrimaryWidget;
146 TSharedPtr<SMultiLineEditableTextBox> MultiLineWidget;
147
148 // TSharedPtr<SEditableTextBox> SingleLineWidget;
149
150 TSharedPtr<SEditableTextBox> NamespaceEditableTextBox;
151 TSharedPtr<SEditableTextBox> KeyEditableTextBox;
152
153 TOptional<float> PreviousHeight;
154
155 bool bIsMultiLine = true;
157
159};
DECLARE_MULTICAST_DELEGATE_TwoParams(FDialogueTextCommitedDelegate, const FText &, ETextCommit::Type)
DECLARE_MULTICAST_DELEGATE_OneParam(FDialogueTextChangedDelegate, const FText &)
TSharedPtr< SMultiLineEditableTextBox > MultiLineWidget
void Tick(const FGeometry &AllottedGeometry, double InCurrentTime, float InDeltaTime) override
void OnTextCommitted(const FText &NewText, ETextCommit::Type CommitInfo)
void OnNamespaceCommitted(const FText &NewText, ETextCommit::Type CommitInfo)
SLATE_BEGIN_ARGS(SDialogueTextPropertyEditableTextBox)
TSharedPtr< IEditableTextProperty > EditableTextProperty
ECheckBoxState GetLocalizableCheckState(bool bActiveState) const
void HandleLocalizableCheckStateChanged(ECheckBoxState InCheckboxState, bool bActiveState)
bool IsValidIdentity(const FText &InIdentity, FText *OutReason=nullptr, const FText *InErrorCtx=nullptr) const
void GetDesiredWidth(float &OutMinDesiredWidth, float &OutMaxDesiredWidth)
FReply OnFocusReceived(const FGeometry &MyGeometry, const FFocusEvent &InFocusEvent) override
void Construct(const FArguments &Arguments, const TSharedRef< IEditableTextProperty > &InEditableTextProperty, const TSharedRef< IPropertyHandle > &InPropertyHandle)