UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
SEditableComboBox.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"
6#include "Input/Events.h"
7#include "Input/Reply.h"
8#include "Layout/Visibility.h"
10#include "Styling/SlateColor.h"
11#include "Layout/Margin.h"
13#include "Widgets/SBoxPanel.h"
14#include "Styling/SlateTypes.h"
15#include "Styling/CoreStyle.h"
18#include "Widgets/SOverlay.h"
22
23#define LOCTEXT_NAMESPACE "SEditableComboBox"
24
25
30
31
32
35template<typename OptionType>
37 : public SCompoundWidget
38{
39public:
40
41 typedef typename TSlateDelegates<OptionType>::FOnGenerateWidget FOnGenerateWidget;
42 typedef typename TSlateDelegates<OptionType>::FOnSelectionChanged FOnSelectionChanged;
43
46 , _Content()
47 , _ContentPadding(FMargin(4.0, 2.0))
48 , _InitiallySelectedItem(nullptr)
49 , _MaxListHeight(450.0f)
56 { }
57
59
61
62 SLATE_NAMED_SLOT(FArguments, Content)
63
64 SLATE_ATTRIBUTE(FMargin, ContentPadding)
65
67
69
71
73
74 SLATE_EVENT(FOnGenerateWidget, OnGenerateWidget)
75
77
79
80 SLATE_EVENT(FOnSelectionChanged, OnSelectionChanged)
81
83
85
87
89
91
92
93public:
94
96 void ClearSelection( )
97 {
98 ComboBox->ClearSelection();
99 }
100
106 void Construct( const FArguments& InArgs )
107 {
108 OnSelectionRenamed = InArgs._OnSelectionRenamed;
109 OnGetEditableText = InArgs._OnGetEditableText;
110
111 ChildSlot
112 [
114
116 .FillWidth(1.0)
117 [
119
121 [
123 .Visibility(this, &SEditableComboBox::HandleNormalModeBoxVisibility)
124
126 .FillWidth(1.0)
127 [
128 // combo box
130 .ButtonStyle(InArgs._ButtonStyle)
131 .ContentPadding(InArgs._ContentPadding)
132 .InitiallySelectedItem(InArgs._InitiallySelectedItem)
133 .MaxListHeight(InArgs._MaxListHeight)
134 .OptionsSource(InArgs._OptionsSource)
135 .OnGenerateWidget(InArgs._OnGenerateWidget)
136 .OnSelectionChanged(InArgs._OnSelectionChanged)
137 .Content()
138 [
139 InArgs._Content.Widget
140 ]
141 ]
142
144 .AutoWidth()
145 .Padding(1.0)
146 [
147 // rename button
149 .ContentPadding(2.f)
150 .ForegroundColor(FSlateColor::UseForeground())
151 .IsEnabled(this, &SEditableComboBox::HandleRemoveRenameButtonIsEnabled)
152 .ButtonStyle( FCoreStyle::Get(), "NoBorder" )
153 .OnClicked(this, &SEditableComboBox::HandleRenameButtonClicked)
154 .ToolTipText(InArgs._RenameButtonToolTip)
155 .VAlign(VAlign_Center)
156 .Visibility(InArgs._IsRenameVisible)
157 .Content()
158 [
159 SNew(SImage)
160 .Image(FCoreStyle::Get().GetBrush("EditableComboBox.Rename"))
161 .ColorAndOpacity(FSlateColor::UseForeground())
162 ]
163 ]
164 ]
165
167 [
169 .Visibility(this, &SEditableComboBox::HandleEditModeBoxVisibility)
170
172 .FillWidth(1.0)
173 .Padding(0.0, 0.0, 0.0, 3.0)
174 [
175 // text box
177 .OnTextCommitted(this, &SEditableComboBox::HandleTextBoxTextCommitted)
178 ]
179
181 .AutoWidth()
182 .Padding(1.0)
183 [
184 // accept button
186 .ContentPadding(2.f)
187 .ForegroundColor(FSlateColor::UseForeground())
188 .ButtonStyle( FCoreStyle::Get(), "NoBorder" )
189 .OnClicked(this, &SEditableComboBox::HandleAcceptButtonClicked)
190 .ToolTipText(LOCTEXT("AcceptButtonTooltip", "Accept"))
191 .VAlign(VAlign_Center)
192 .Content()
193 [
194 SNew(SImage)
195 .Image(FCoreStyle::Get().GetBrush("EditableComboBox.Accept"))
196 .ColorAndOpacity(FSlateColor::UseForeground())
197 ]
198 ]
199 ]
200 ]
201
203 .AutoWidth()
204 .Padding(1.0)
205 [
206 // add button
208 .ContentPadding(2.f)
209 .ForegroundColor(FSlateColor::UseForeground())
210 .IsEnabled(this, &SEditableComboBox::HandleAddButtonIsEnabled)
211 .ButtonStyle( FCoreStyle::Get(), "NoBorder" )
212 .OnClicked(InArgs._OnAddClicked)
213 .ToolTipText(InArgs._AddButtonToolTip)
214 .VAlign(VAlign_Center)
215 .Content()
216 [
217 SNew(SImage)
218 .Image(FCoreStyle::Get().GetBrush("EditableComboBox.Add"))
219 .ColorAndOpacity(FSlateColor::UseForeground())
220 ]
221 ]
222
224 .AutoWidth()
225 .Padding(1.0)
226 [
227 // remove button
229 .ContentPadding(2.f)
230 .ForegroundColor(FSlateColor::UseForeground())
231 .IsEnabled(this, &SEditableComboBox::HandleRemoveRenameButtonIsEnabled)
232 .ButtonStyle( FCoreStyle::Get(), "NoBorder" )
233 .OnClicked(InArgs._OnRemoveClicked)
234 .ToolTipText(InArgs._RemoveButtonToolTip)
235 .VAlign(VAlign_Center)
236 .Content()
237 [
238 SNew(SImage)
239 .Image(FCoreStyle::Get().GetBrush("EditableComboBox.Delete"))
240 .ColorAndOpacity(FSlateColor::UseForeground())
241 ]
242 ]
243 ];
244 }
245
251 OptionType GetSelectedItem( )
252 {
253 return ComboBox->GetSelectedItem();
254 }
255
263 void RefreshOptions( )
264 {
265 EditedItem.Reset();
266
267 ComboBox->RefreshOptions();
268 }
269
275 void SetSelectedItem( OptionType InSelectedItem )
276 {
277 EditedItem.Reset();
278
279 ComboBox->SetSelectedItem(InSelectedItem);
280 }
281
282private:
283
284 // Callback for getting the enabled state of the 'Add' button.
285 bool HandleAddButtonIsEnabled( ) const
286 {
287 return !EditedItem.IsValid();
288 }
289
290 // Callback for clicking the 'Accept' button.
292 {
294 }
295
296 // Callback for getting the visibility of the edit mode box.
298 {
300 }
301
302 // Callback for getting the visibility of the normal mode box.
304 {
306 }
307
308 // Callback for getting the enabled state of the 'Remove' and 'Rename' buttons.
310 {
311 return (!EditedItem.IsValid() && ComboBox->GetSelectedItem().IsValid());
312 }
313
314 // Callback for clicking the 'Rename' button.
316 {
317 if (OnGetEditableText.IsBound())
318 {
319 EditedItem = ComboBox->GetSelectedItem();
320
321 TextBox->SetText( FText::FromString( OnGetEditableText.Execute() ));
322 }
323
324 return FReply::Handled().SetUserFocus(TextBox->AsShared(), EFocusCause::Mouse);
325 }
326
327 // Callback for committing the text in the text box.
328 void HandleTextBoxTextCommitted( const FText& CommittedText, ETextCommit::Type CommitType )
329 {
330 if (EditedItem.IsValid())
331 {
333 {
334 OnSelectionRenamed.ExecuteIfBound(TextBox->GetText(), CommitType);
335 }
336
337 EditedItem.Reset();
338 }
339 }
340
341private:
342
343 // Holds the combo box.
345
346 // Holds the currently edited item.
348
349 // Holds the text box.
351
352private:
353
354 // Holds a delegate to be invoked before the editable text box is populated and shown.
356
357 // Holds a delegate to be invoked after the text changes have been committed.
359};
360
361
362#undef LOCTEXT_NAMESPACE
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define SLATE_NAMED_SLOT(DeclarationType, SlotName)
Definition DeclarativeSyntaxSupport.h:437
#define SLATE_STYLE_ARGUMENT(ArgType, ArgName)
Definition DeclarativeSyntaxSupport.h:280
#define SAssignNew(ExposeAs, WidgetType,...)
Definition DeclarativeSyntaxSupport.h:41
#define SNew(WidgetType,...)
Definition DeclarativeSyntaxSupport.h:37
#define SLATE_ATTRIBUTE(AttrType, AttrName)
Definition DeclarativeSyntaxSupport.h:192
#define SLATE_BEGIN_ARGS(InWidgetType)
Definition DeclarativeSyntaxSupport.h:63
#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_RetVal(ReturnValueType, DelegateName)
Definition DelegateCombinations.h:41
#define LOCTEXT(InKey, InTextLiteral)
Definition Internationalization.h:295
void Construct(const FArguments &InArgs)
static const ISlateStyle & Get()
Definition CoreStyle.h:33
Definition Reply.h:24
SLATECORE_API FReply & SetUserFocus(TSharedRef< SWidget > GiveMeFocus, EFocusCause ReasonFocusIsChanging=EFocusCause::SetDirectly, bool bInAllUsers=false)
Definition Reply.cpp:40
static FReply Handled()
Definition Reply.h:233
Definition Text.h:385
static CORE_API FText FromString(const ANSICHAR *String)
Definition Text.cpp:1081
Definition SButton.h:33
Definition SComboBox.h:97
Definition SCompoundWidget.h:22
Definition SlateFwd.h:34
Definition SEditableTextBox.h:29
Definition SBoxPanel.h:171
static FSlot::FSlotArguments Slot()
Definition SBoxPanel.h:272
Definition SImage.h:29
Definition SOverlay.h:44
static SLATECORE_API FOverlaySlot::FSlotArguments Slot(int32 ZOrder=0)
Definition SOverlay.cpp:120
Definition Array.h:670
Definition SharedPointer.h:692
Definition SlateDelegates.h:134
Type
Definition SlateEnums.h:291
@ OnCleared
Definition SlateEnums.h:299
Definition Visibility.h:12
static SLATECORE_API const EVisibility Hidden
Definition Visibility.h:20
static SLATECORE_API const EVisibility Visible
Definition Visibility.h:14
Definition SlateTypes.h:509
Definition Margin.h:17
static FSlateColor UseForeground()
Definition SlateColor.h:198