UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
SNumericDropDown.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 "Misc/Attribute.h"
7#include "Layout/Visibility.h"
8#include "Input/Events.h"
9#include "Widgets/SWidget.h"
10#include "Textures/SlateIcon.h"
11#include "Layout/Margin.h"
14#include "Widgets/SBoxPanel.h"
21
23template<typename NumericType>
25{
26public:
28
29public:
32 {
33 public:
39 {
40 Value = InValue;
41 Name = InName;
42 Description = InDescription;
43 }
44
45 NumericType GetValue() const
46 {
47 return Value;
48 }
49
50 FText GetName() const
51 {
52 return Name;
53 }
54
56 {
57 return Description;
58 }
59
60 private:
61 NumericType Value;
62 FText Name;
63 FText Description;
64 };
65
66public:
74
76 SLATE_ARGUMENT( TArray<FNamedValue>, DropDownValues )
78 SLATE_ATTRIBUTE( FText, LabelText )
80 SLATE_ATTRIBUTE( EOrientation, Orientation )
82 SLATE_ATTRIBUTE( float, MinDesiredValueWidth )
84 SLATE_ATTRIBUTE( bool, bShowNamedValue )
86 SLATE_ATTRIBUTE( NumericType, Value )
88 SLATE_EVENT( FOnValueChanged, OnValueChanged )
89
91
92 void Construct( const FArguments& InArgs )
93 {
94 DropDownValues = InArgs._DropDownValues;
95 LabelText = InArgs._LabelText;
96 Orientation = InArgs._Orientation;
97 bShowNamedValue = InArgs._bShowNamedValue;
98 Value = InArgs._Value;
99 OnValueChanged = InArgs._OnValueChanged;
100
102 [
104 // Vertical Label
106 .AutoHeight()
107 .Padding( FMargin( 0, 0, 0, 3 ) )
108 [
110 .Text(LabelText)
111 .Visibility(this, &SNumericDropDown<NumericType>::GetLabelVisibility, EOrientation::Orient_Vertical)
112 ]
114 .AutoHeight()
115 [
117 // Horizontal Icon Label
119 .VAlign( EVerticalAlignment::VAlign_Center )
120 .AutoWidth()
121 .Padding( FMargin( 0, 0, 3, 0 ) )
122 [
123
125 .Text(LabelText)
126 .Visibility( this, &SNumericDropDown<NumericType>::GetLabelVisibility, EOrientation::Orient_Horizontal )
127 ]
129 [
131 .ContentPadding( 1 )
132 .OnGetMenuContent( this, &SNumericDropDown<NumericType>::BuildMenu )
133 .ButtonContent()
134 [
136 .MinDesiredWidth( InArgs._MinDesiredValueWidth )
137 .RevertTextOnEscape(true)
138 .SelectAllTextWhenFocused(true)
140 .OnTextCommitted( this, &SNumericDropDown<NumericType>::ValueTextComitted )
141 ]
142 ]
143 ]
144 ];
145 }
146
147private:
148 EVisibility GetLabelVisibility( EOrientation LabelOrientation ) const
149 {
150 return Orientation.Get() == LabelOrientation
153 }
154
155 FText GetValueText() const
156 {
157 if (bShowNamedValue.Get())
158 {
159 for ( FNamedValue DropDownValue : DropDownValues )
160 {
161 if (FMath::IsNearlyEqual(DropDownValue.GetValue(), Value.Get()))
162 {
163 return DropDownValue.GetName();
164 }
165 }
166 }
167 return FText::AsNumber( Value.Get() );
168 }
169
170 void ValueTextComitted( const FText& InNewText, ETextCommit::Type InTextCommit )
171 {
172 if ( InNewText.IsNumeric() )
173 {
174 NumericType NewValue;
176 OnValueChanged.ExecuteIfBound(NewValue);
177 }
178 }
179
180 TSharedRef<SWidget> BuildMenu()
181 {
182 FMenuBuilder MenuBuilder( true, NULL );
183
184 for ( FNamedValue DropDownValue : DropDownValues )
185 {
186 FUIAction MenuAction(FExecuteAction::CreateSP(this, &SNumericDropDown::SetValue, DropDownValue.GetValue()));
187 MenuBuilder.AddMenuEntry(DropDownValue.GetName(), DropDownValue.GetDescription(), FSlateIcon(), MenuAction);
188 }
189
190 return MenuBuilder.MakeWidget();
191 }
192
193 void SetValue( NumericType InValue )
194 {
196 OnValueChanged.ExecuteIfBound(InValue);
197 }
198
199private:
200 TArray<FNamedValue> DropDownValues;
201 TAttribute<FText> LabelText;
202 TAttribute<EOrientation> Orientation;
203 TAttribute<bool> bShowNamedValue;
205 FOnValueChanged OnValueChanged;
206};
OODEFFUNC typedef void(OODLE_CALLBACK t_fp_OodleCore_Plugin_Free)(void *ptr)
#define NULL
Definition oodle2base.h:134
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define SNew(WidgetType,...)
Definition DeclarativeSyntaxSupport.h:37
#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
EOrientation
Definition SlateEnums.h:261
Definition MultiBoxBuilder.h:310
static FSlateApplication & Get()
Definition SlateApplication.h:319
SLATE_API void ClearKeyboardFocus(const EFocusCause ReasonFocusIsChanging=EFocusCause::SetDirectly)
Definition SlateApplication.cpp:2761
Definition Text.h:385
static CORE_API FText AsNumber(float Val, const FNumberFormattingOptions *const Options=NULL, const FCulturePtr &TargetCulture=NULL)
Definition SComboButton.h:25
Definition SCompoundWidget.h:22
FCompoundWidgetOneChildSlot ChildSlot
Definition SCompoundWidget.h:113
Definition SEditableTextBox.h:29
Definition SBoxPanel.h:171
static FSlot::FSlotArguments Slot()
Definition SBoxPanel.h:272
Definition SNumericDropDown.h:32
FText GetName() const
Definition SNumericDropDown.h:50
NumericType GetValue() const
Definition SNumericDropDown.h:45
FText GetDescription() const
Definition SNumericDropDown.h:55
FNamedValue(NumericType InValue, FText InName, FText InDescription)
Definition SNumericDropDown.h:38
Definition SNumericDropDown.h:25
DECLARE_DELEGATE_OneParam(FOnValueChanged, NumericType)
void Construct(const FArguments &InArgs)
Definition SNumericDropDown.h:92
SLATE_BEGIN_ARGS(SNumericDropDown< NumericType >)
Definition SNumericDropDown.h:67
Definition STextBlock.h:45
Definition SBoxPanel.h:322
static FSlot::FSlotArguments Slot()
Definition SBoxPanel.h:424
Definition Array.h:670
Definition Attribute.h:17
const ObjectType & Get() const
Definition Attribute.h:241
Definition SharedPointer.h:153
Type
Definition SlateEnums.h:291
@ false
Definition radaudio_common.h:23
Definition Visibility.h:12
static SLATECORE_API const EVisibility Visible
Definition Visibility.h:14
static SLATECORE_API const EVisibility Collapsed
Definition Visibility.h:17
Definition Margin.h:17
static UE_FORCEINLINE_HINT bool IsNearlyEqual(float A, float B, float ErrorTolerance=UE_SMALL_NUMBER)
Definition UnrealMathUtility.h:388
Definition SlateIcon.h:13
Definition UIAction.h:37
static void FromString(T &Value, const CharType *Buffer)
Definition UnrealString.h:221