UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
SSuggestionTextBox.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
8#include "Input/Reply.h"
11#include "Styling/SlateTypes.h"
12#include "Styling/CoreStyle.h"
17
18class SMenuAnchor;
19class SVerticalBox;
20
21template< typename ObjectType > class TAttribute;
22
29
30
37
38
39
44{
45
46public:
47
50 , _BackgroundImage(FCoreStyle::Get().GetBrush("SuggestionTextBox.Background"))
54 , _Font( FCoreStyle::Get().GetFontStyle( TEXT( "NormalFont" ) ) )
55 , _ForegroundColor( FCoreStyle::Get().GetSlateColor( "InvertedForeground" ) )
56 , _HintText()
58 , _MinDesiredWidth(0.0f)
62 , _TextStyle( &FCoreStyle::Get().GetWidgetStyle<FEditableTextBoxStyle>("NormalEditableTextBox") )
63 , _SuggestionTextStyle( &FCoreStyle::Get().GetWidgetStyle<FTextBlockStyle>("SuggestionTextBox.Text") )
65 , _Text()
66 { }
67
69 SLATE_ATTRIBUTE(FSlateColor, BackgroundColor)
70
71
72 SLATE_ARGUMENT(const FSlateBrush*, BackgroundImage)
73
74
75 SLATE_ATTRIBUTE(bool, ClearKeyboardFocusOnCommit)
76
77
79
80
82
83
85
86
87 SLATE_ATTRIBUTE(FSlateColor, ForegroundColor)
88
89
90 SLATE_ATTRIBUTE(FText, HintText)
91
92
93 SLATE_ATTRIBUTE(bool, IsCaretMovedWhenGainFocus)
94
95
96 SLATE_ATTRIBUTE(float, MinDesiredWidth)
97
98
99 SLATE_EVENT(FOnShowingHistory, OnShowingHistory)
100
101
102 SLATE_EVENT(FOnShowingSuggestions, OnShowingSuggestions)
103
104
105 SLATE_EVENT(FOnTextChanged, OnTextChanged)
106
107
108 SLATE_EVENT(FOnTextCommitted, OnTextCommitted)
109
110
111 SLATE_ATTRIBUTE(bool, RevertTextOnEscape)
112
113
114 SLATE_ATTRIBUTE(bool, SelectAllTextOnCommit)
115
116
117 SLATE_ATTRIBUTE(bool, SelectAllTextWhenFocused)
118
119
121
122
123 SLATE_STYLE_ARGUMENT(FTextBlockStyle, SuggestionTextStyle)
124
125
127
128
130
132
133public:
134
137
138public:
139
145 SLATE_API void Construct( const FArguments& InArgs );
146
152 FText GetText( ) const
153 {
154 return TextBox->GetText();
155 }
156
165 void SetError( const FString& InError )
166 {
167 TextBox->SetError(InError);
168 }
169
175 SLATE_API void SetText( const TAttribute< FText >& InNewText );
176
177protected:
178
180 SLATE_API void ClearSuggestions( );
181
183 SLATE_API void FocusTextBox( );
184
190 SLATE_API FString GetSelectedSuggestionString( ) const;
191
193 SLATE_API void MarkActiveSuggestion( );
194
201 SLATE_API void SetSuggestions( TArray<FString>& SuggestionStrings, bool InHistoryMode );
202
203protected:
204
205 // SWidget overrides
206
207 SLATE_API virtual void OnFocusLost( const FFocusEvent& InFocusEvent ) override;
208 SLATE_API virtual FReply OnKeyDown( const FGeometry& MyGeometry, const FKeyEvent& KeyEvent ) override;
209 SLATE_API virtual bool SupportsKeyboardFocus( ) const override;
210
211private:
212
213 // Callback for generating a row widget for the suggestion list view.
214 SLATE_API TSharedRef<ITableRow> HandleSuggestionListViewGenerateRow( TSharedPtr<FString> Message, const TSharedRef<STableViewBase>& OwnerTable );
215
216 // Callback for changing the selected suggestion.
217 SLATE_API void HandleSuggestionListViewSelectionChanged( TSharedPtr<FString> NewValue, ESelectInfo::Type SelectInfo );
218
219 // Callback for getting the highlight string in a suggestion list row widget.
220 SLATE_API FText HandleSuggestionListWidgetHighlightText( ) const;
221
222 // Callback for changing the text box input.
223 SLATE_API void HandleTextBoxTextChanged( const FText& InText );
224
225 // Callback committing the text box input.
226 SLATE_API void HandleTextBoxTextCommitted( const FText& InText, ETextCommit::Type CommitInfo );
227
228 // Called when global focus changes so we can detect when to close the SuggestionList.
229 SLATE_API void OnGlobalFocusChanging(const FFocusEvent& FocusEvent, const FWeakWidgetPath& OldFocusedWidgetPath, const TSharedPtr<SWidget>& OldFocusedWidget, const FWidgetPath& NewFocusedWidgetPath, const TSharedPtr<SWidget>& NewFocusedWidget);
230
231private:
232
233 // Holds a flag to prevent recursive calls in UI callbacks.
234 bool IgnoreUIUpdate;
235
236 // Holds the box for history and auto-complete suggestions.
237 TSharedPtr<SMenuAnchor> MenuAnchor;
238
239 // Holds the current list of suggestions.
240 TArray<TSharedPtr<FString> > Suggestions;
241
242 // Holds the list view that displays the suggestions.
243 TSharedPtr<SListView<TSharedPtr<FString> > > SuggestionListView;
244
245 // Holds the index of the selected suggestion (-1 for no selection).
246 int32 SelectedSuggestion;
247
248 // Holds the editable text box.
250
251 // The styling of the suggestion text.
252 const FTextBlockStyle* SuggestionTextStyle;
253
254 // The VerticalBox containing the SuggestionList.
256
257 // Trigger commit text event as soon as suggestion was selected.
258 bool CommitsOnSuggestionSelected;
259
260private:
261
262 // Holds a delegate that is executed before the input history is shown.
263 FOnShowingHistory OnShowingHistory;
264
265 // Holds a delegate that is executed before the suggestions list is shown.
266 FOnShowingSuggestions OnShowingSuggestions;
267
268 // Holds a delegate that is executed when the text has changed.
269 FOnTextChanged OnTextChanged;
270
271 // Holds a delegate that is executed when the text has been committed.
272 FOnTextCommitted OnTextCommitted;
273};
#define TEXT(x)
Definition Platform.h:1272
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
#define OUT
Definition Platform.h:897
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define SLATE_STYLE_ARGUMENT(ArgType, ArgName)
Definition DeclarativeSyntaxSupport.h:280
#define SLATE_ATTRIBUTE(AttrType, AttrName)
Definition DeclarativeSyntaxSupport.h:192
#define SLATE_EVENT(DelegateName, EventName)
Definition DeclarativeSyntaxSupport.h:458
#define SLATE_END_ARGS()
Definition DeclarativeSyntaxSupport.h:116
#define SLATE_ARGUMENT(ArgType, ArgName)
Definition DeclarativeSyntaxSupport.h:208
#define DECLARE_DELEGATE_TwoParams(DelegateName, Param1Type, Param2Type)
Definition DelegateCombinations.h:57
#define DECLARE_DELEGATE_OneParam(DelegateName, Param1Type)
Definition DelegateCombinations.h:48
return true
Definition ExternalRpcRegistry.cpp:601
void Construct(const FArguments &InArgs)
Definition CoreStyle.h:15
Definition Reply.h:24
Definition Text.h:385
Definition WidgetPath.h:213
Definition WidgetPath.h:51
Definition SCompoundWidget.h:22
Definition SSuggestionTextBox.h:44
void SetError(const FString &InError)
Definition SSuggestionTextBox.h:165
SLATE_BEGIN_ARGS(SSuggestionTextBox)
Definition SSuggestionTextBox.h:48
Definition SBoxPanel.h:322
Definition Array.h:670
Definition Attribute.h:17
const ObjectType & Get() const
Definition Attribute.h:241
Definition SharedPointer.h:692
Definition SharedPointer.h:153
Type
Definition SlateEnums.h:311
Type
Definition SlateEnums.h:291
@ false
Definition radaudio_common.h:23
Definition SlateTypes.h:1019
Definition Events.h:51
Definition Geometry.h:40
Definition Events.h:431
Definition Color.h:48
Definition SlateBrush.h:239
Definition SlateColor.h:42
Definition SlateFontInfo.h:147
Definition SlateTypes.h:326