UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
SSpinBox.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"
9#include "Input/CursorReply.h"
10#include "Input/Events.h"
11#include "Input/Reply.h"
12#include "InputCoreTypes.h"
13#include "Layout/Margin.h"
14#include "Layout/Visibility.h"
15#include "Misc/Attribute.h"
17#include "Styling/CoreStyle.h"
18#include "Styling/SlateColor.h"
19#include "Styling/SlateTypes.h"
25#include "Widgets/SBoxPanel.h"
28
29#include <limits>
30
31namespace SpinBoxPrivate
32{
34}
35
36/*
37 * This function compute a slider position by simulating two log on both side of the neutral value
38 * Example a slider going from 0.0 to 2.0 with a neutral value of 1.0, the user will have a lot of precision around the neutral value
39 * on both side.
40 |
41 || |
42 | -_ _-
43 | --__ __--
44 | ----__________----
45 ----------------------------------
46 0 1 2
47
48 The function return a float representing the slider fraction used to position the slider handle
49 FractionFilled: this is the value slider position with no exponent
50 StartFractionFilled: this is the neutral value slider position with no exponent
51 SliderExponent: this is the slider exponent
52*/
54
61template<typename NumericType>
63 : public SCompoundWidget
64{
65public:
66
69
72
75
78
106
109
110
111 SLATE_ATTRIBUTE(NumericType, Value)
121 SLATE_ATTRIBUTE(TOptional< int32 >, MinFractionalDigits)
123 SLATE_ATTRIBUTE(TOptional< int32 >, MaxFractionalDigits)
125 SLATE_ATTRIBUTE(bool, AlwaysUsesDeltaSnap)
127 SLATE_ATTRIBUTE(bool, EnableSlider)
129 SLATE_ATTRIBUTE(NumericType, Delta)
131 SLATE_ATTRIBUTE_DEPRECATED(int32, ShiftMouseMovePixelPerDelta, 5.4, "Shift Mouse Move Pixel Per Delta is deprecated and incrementing by a fixed delta per pixel is no longer supported. Please use ShiftMultiplier and CtrlMultiplier which will multiply the step per mouse move")
133 SLATE_ATTRIBUTE(float, ShiftMultiplier)
135 SLATE_ATTRIBUTE(float, CtrlMultiplier)
137 SLATE_ATTRIBUTE(int32, LinearDeltaSensitivity)
139 SLATE_ATTRIBUTE(bool, SupportDynamicSliderMaxValue)
141 SLATE_ATTRIBUTE(bool, SupportDynamicSliderMinValue)
143 SLATE_EVENT(FOnDynamicSliderMinMaxValueChanged, OnDynamicSliderMaxValueChanged)
145 SLATE_EVENT(FOnDynamicSliderMinMaxValueChanged, OnDynamicSliderMinValueChanged)
147 SLATE_ATTRIBUTE(float, SliderExponent)
149 SLATE_ATTRIBUTE(NumericType, SliderExponentNeutralValue)
155 SLATE_ATTRIBUTE(TOptional< NumericType >, WheelStep)
159 SLATE_ATTRIBUTE(FMargin, ContentPadding)
161 SLATE_EVENT(FOnValueChanged, OnValueChanged)
163 SLATE_EVENT(FOnValueCommitted, OnValueCommitted)
165 SLATE_EVENT(FSimpleDelegate, OnBeginSliderMovement)
167 SLATE_EVENT(FOnValueChanged, OnEndSliderMovement)
169 SLATE_EVENT(FOnGetDisplayValue, OnGetDisplayValue)
171 SLATE_EVENT(FOnGetDisplayValue, OnEditEditableText)
173 SLATE_ATTRIBUTE(bool, ClearKeyboardFocusOnCommit)
175 SLATE_ATTRIBUTE(bool, SelectAllTextOnCommit)
177 SLATE_ATTRIBUTE(float, MinDesiredWidth)
179 SLATE_ATTRIBUTE(ETextJustify::Type, Justification)
181 SLATE_ATTRIBUTE(EKeyboardType, KeyboardType)
185 SLATE_ARGUMENT(bool, PreventThrottling)
187 SLATE_ARGUMENT(bool, RevertTextOnEscape)
190
192
194
196
202 SLATE_API void Construct(const FArguments& InArgs);
203
204 SLATE_API virtual int32 OnPaint(const FPaintArgs& Args, const FGeometry& AllottedGeometry, const FSlateRect& MyCullingRect, FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled) const override;
205
206 SLATE_API void Tick(const FGeometry& AlottedGeometry, const double InCurrentTime, const float InDeltaTime);
207
209
218
227
229
231
240
248
250
252
253
255
257
259
261 SLATE_API TAttribute<NumericType> GetValueAttribute() const;
262
264 SLATE_API NumericType GetValue() const;
265
266 SLATE_API void SetValue(const TAttribute<NumericType>& InValueAttribute, const bool bShouldCommit = false);
267
269 SLATE_API NumericType GetMinValue() const;
270
271 SLATE_API void SetMinValue(const TAttribute<TOptional<NumericType>>& InMinValue);
272
274 SLATE_API NumericType GetMaxValue() const;
275
276 SLATE_API void SetMaxValue(const TAttribute<TOptional<NumericType>>& InMaxValue);
277
279 SLATE_API bool IsMinSliderValueBound() const;
280
281 SLATE_API NumericType GetMinSliderValue() const;
282
284
286 SLATE_API bool IsMaxSliderValueBound() const;
287
288 SLATE_API NumericType GetMaxSliderValue() const;
289
291
294
296
299
301
305
307 SLATE_API bool GetEnableSlider() const;
309
311 SLATE_API NumericType GetDelta() const;
312 SLATE_API void SetDelta(NumericType InDelta);
313
315 SLATE_API float GetSliderExponent() const;
317
319 SLATE_API float GetMinDesiredWidth() const;
321
325
331
334
338
340 SLATE_API void ExitTextMode();
341
343 SLATE_API FString GetValueAsString() const;
344
347
350
356 SLATE_API void TextField_OnTextChanged(const FText& NewText);
357
364 SLATE_API void TextField_OnTextCommitted(const FText& NewText, ETextCommit::Type CommitInfo);
365
366
376
385 SLATE_API void CommitValue(NumericType NewValue, double NewSpinValue, ECommitMethod CommitMethod, ETextCommit::Type OriginalCommitInfo, const bool bShouldCommit = false);
386
387 SLATE_API void NotifyValueCommitted(NumericType CurrentValue) const;
388
390 SLATE_API bool IsInTextMode() const;
391
393 SLATE_API static float Fraction(double InValue, double InMinValue, double InMaxValue);
394
395private:
396
397 // New value to be Committed on Tick for MouseMove events
398 // This exists to insulate high-frequency mouse move events which can fire many times during input processing
399 // from the side-effects of committing the spinbox value
400 struct FPendingCommitValue
401 {
402 double NewValue;
403 ECommitMethod CommitMethod;
404 };
405
407 static constexpr int32 DefaultMinFractionalDigits = 1;
408
410 static constexpr int32 DefaultMaxFractionalDigits = 6;
411
412 TAttribute<NumericType> ValueAttribute;
413 FOnValueChanged OnValueChanged;
414 FOnValueCommitted OnValueCommitted;
415 FSimpleDelegate OnBeginSliderMovement;
416 FOnValueChanged OnEndSliderMovement;
417 TSharedPtr<STextBlock> TextBlock;
418 TSharedPtr<SEditableText> EditableText;
419
422
424 bool bUnlimitedSpinRange;
425 void UpdateIsSpinRangeUnlimited();
426
427 const FSpinBoxStyle* Style;
428
429 const FSlateBrush* BackgroundHoveredBrush;
430 const FSlateBrush* BackgroundActiveBrush;
431 const FSlateBrush* BackgroundBrush;
432 const FSlateBrush* ActiveFillBrush;
433 const FSlateBrush* HoveredFillBrush;
434 const FSlateBrush* InactiveFillBrush;
435
436 float DistanceDragged;
438 TAttribute<float> ShiftMultiplier;
439 TAttribute<float> CtrlMultiplier;
440 TAttribute<int32> LinearDeltaSensitivity;
441 TAttribute<float> SliderExponent;
442 TAttribute<NumericType> SliderExponentNeutralValue;
445 TAttribute< TOptional<NumericType> > MinSliderValue;
446 TAttribute< TOptional<NumericType> > MaxSliderValue;
447 TAttribute< TOptional<int32> > MinFractionalDigits;
448 TAttribute< TOptional<int32> > MaxFractionalDigits;
449 TAttribute<bool> AlwaysUsesDeltaSnap;
450 TAttribute<bool> EnableSlider;
451 TAttribute<bool> SupportDynamicSliderMaxValue;
452 TAttribute<bool> SupportDynamicSliderMinValue;
454 FOnDynamicSliderMinMaxValueChanged OnDynamicSliderMaxValueChanged;
455 FOnDynamicSliderMinMaxValueChanged OnDynamicSliderMinValueChanged;
456 FOnGetDisplayValue OnGetDisplayValue;
457 FOnGetDisplayValue OnEditEditableText;
458
460 TAttribute<float> MinDesiredWidth;
461 float GetTextMinDesiredWidth() const;
462
464 bool IsCharacterValid(TCHAR InChar) const;
465
471 NumericType RoundIfIntegerValue(double ValueToRound) const;
472
473 void CancelMouseCapture();
474
476 int32 PointerDraggingSliderIndex;
477
479 FIntPoint CachedMousePosition;
480
486 double InternalValue;
487
489 NumericType PreDragValue;
490
495 NumericType CachedExternalValue;
496
498 FString CachedValueString;
499
501 mutable bool bCachedValueStringDirty;
502
504 bool bDragging;
505
507 bool bIsTextChanging;
508
509 /*
510 * Holds whether or not to prevent throttling during mouse capture
511 * When true, the viewport will be updated with every single change to the value during dragging
512 */
513 bool bPreventThrottling;
514
516 bool bEnableWheel = true;
517
519 bool bBroadcastValueChangesPerKey = false;
520
521 TOptional<FPendingCommitValue> PendingCommitValue;
522
523 /*
524 * Gets the default amount to change the slider when delta is not applicable.
525 * Control takes priority over shift
526 */
527 double GetDefaultStepSize(const FInputEvent& InputEvent);
528
530 const double StepSize = 1.f;
531
533 const double SmallStepSize = .1f;
534
536 const double SmallStepSizeMax = 10.f;
537};
#define TEXT(x)
Definition Platform.h:1272
FPlatformTypes::TCHAR TCHAR
Either ANSICHAR or WIDECHAR, depending on whether the platform supports wide characters or the requir...
Definition Platform.h:1135
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
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_ATTRIBUTE_DEPRECATED(AttrType, AttrName, DeprecationVersion, DeprecationMessage)
Definition DeclarativeSyntaxSupport.h:199
#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
return true
Definition ExternalRpcRegistry.cpp:601
EKeyboardType
Definition IVirtualKeyboardEntry.h:12
@ Keyboard_Default
Definition IVirtualKeyboardEntry.h:13
SLATE_API float SpinBoxComputeExponentSliderFraction(float FractionFilled, float StartFractionFilled, float SliderExponent)
Definition SSpinBox.cpp:15
Definition CoreStyle.h:15
Definition CursorReply.h:16
Definition PaintArgs.h:23
Definition Reply.h:24
Definition SlateRect.h:26
Definition DrawElements.h:220
Definition Text.h:385
Definition WidgetStyle.h:15
Definition SCompoundWidget.h:22
Definition SSpinBox.h:64
SLATE_API NumericType GetMinSliderValue() const
Definition SSpinBox.cpp:736
virtual SLATE_API FReply OnMouseButtonUp(const FGeometry &MyGeometry, const FPointerEvent &MouseEvent) override
Definition SSpinBox.cpp:316
SLATE_API void NotifyValueCommitted(NumericType CurrentValue) const
Definition SSpinBox.cpp:1061
SLATE_API void ResetCachedValueString()
Definition SSpinBox.cpp:1151
SLATE_API void SetEnableSlider(bool bNewValue)
Definition SSpinBox.cpp:796
SLATE_API void CommitValue(NumericType NewValue, double NewSpinValue, ECommitMethod CommitMethod, ETextCommit::Type OriginalCommitInfo, const bool bShouldCommit=false)
Definition SSpinBox.cpp:970
virtual SLATE_API bool SupportsKeyboardFocus() const override
Definition SSpinBox.cpp:627
SLATE_API TAttribute< NumericType > GetValueAttribute() const
Definition SSpinBox.cpp:694
SLATE_API int32 GetMinFractionalDigits() const
Definition SSpinBox.cpp:762
SLATE_API NumericType GetMaxValue() const
Definition SSpinBox.cpp:721
SLATE_API float GetSliderExponent() const
Definition SSpinBox.cpp:808
SLATE_API void SetWidgetStyle(const FSpinBoxStyle *InStyle)
Definition SSpinBox.cpp:828
SLATE_API void Construct(const FArguments &InArgs)
Definition SSpinBox.cpp:49
SLATE_API FText GetDisplayValue() const
Definition SSpinBox.cpp:900
virtual SLATE_API bool HasKeyboardFocus() const override
Definition SSpinBox.cpp:687
SLATE_API void SetMinSliderValue(const TAttribute< TOptional< NumericType > > &InMinSliderValue)
Definition SSpinBox.cpp:740
SLATE_API bool GetAlwaysUsesDeltaSnap() const
Definition SSpinBox.cpp:784
SLATE_API void SetTextSelectAllTextOnCommit(bool bNewValue)
Definition SSpinBox.cpp:848
SLATE_API void SetDelta(NumericType InDelta)
Definition SSpinBox.cpp:804
SLATE_API void SetMaxValue(const TAttribute< TOptional< NumericType > > &InMaxValue)
Definition SSpinBox.cpp:725
DECLARE_DELEGATE_OneParam(FOnValueChanged, NumericType)
SLATE_API void SetAlwaysUsesDeltaSnap(bool bNewValue)
Definition SSpinBox.cpp:788
SLATE_API void TextField_OnTextCommitted(const FText &NewText, ETextCommit::Type CommitInfo)
Definition SSpinBox.cpp:954
SLATE_API FString GetValueAsString() const
Definition SSpinBox.cpp:881
SLATE_API bool IsMaxSliderValueBound() const
Definition SSpinBox.cpp:747
virtual SLATE_API FCursorReply OnCursorQuery(const FGeometry &MyGeometry, const FPointerEvent &CursorEvent) const override
Definition SSpinBox.cpp:612
SLATE_API void ApplySliderMaxValueChanged(float SliderDeltaToAdd, bool UpdateOnlyIfHigher)
Definition SSpinBox.cpp:364
virtual SLATE_API FReply OnFocusReceived(const FGeometry &MyGeometry, const FFocusEvent &InFocusEvent) override
Definition SSpinBox.cpp:634
SLATE_API bool IsInTextMode() const
Definition SSpinBox.cpp:1070
SLATE_BEGIN_ARGS(SSpinBox< NumericType >)
Definition SSpinBox.h:79
virtual SLATE_API FReply OnKeyDown(const FGeometry &MyGeometry, const FKeyEvent &InKeyEvent) override
Definition SSpinBox.cpp:648
SLATE_API NumericType GetValue() const
Definition SSpinBox.cpp:698
SLATE_API void EnterTextMode()
Definition SSpinBox.cpp:856
SLATE_API void SetValue(const TAttribute< NumericType > &InValueAttribute, const bool bShouldCommit=false)
Definition SSpinBox.cpp:702
virtual SLATE_API FReply OnMouseWheel(const FGeometry &MyGeometry, const FPointerEvent &MouseEvent) override
Definition SSpinBox.cpp:572
SLATE_API void SetMinDesiredWidth(const TAttribute< float > &InMinDesiredWidth)
Definition SSpinBox.cpp:820
SLATE_API void SetTextJustification(ETextJustify::Type InJustification)
Definition SSpinBox.cpp:840
SLATE_API NumericType GetMaxSliderValue() const
Definition SSpinBox.cpp:751
SLATE_API void SetMaxFractionalDigits(const TAttribute< TOptional< int32 > > &InMaxFractionalDigits)
Definition SSpinBox.cpp:777
SLATE_API const bool CommitWithMultiplier(const FPointerEvent &MouseEvent)
Definition SSpinBox.cpp:285
DECLARE_DELEGATE_FourParams(FOnDynamicSliderMinMaxValueChanged, NumericType, TWeakPtr< SWidget >, bool, bool)
SLATE_API void SetMinFractionalDigits(const TAttribute< TOptional< int32 > > &InMinFractionalDigits)
Definition SSpinBox.cpp:766
SLATE_API void InvalidateStyle()
Definition SSpinBox.cpp:832
ECommitMethod
Definition SSpinBox.h:369
@ CommittedViaSpin
Definition SSpinBox.h:370
@ CommittedViaTypeIn
Definition SSpinBox.h:371
@ CommittedViaSpinMultiplier
Definition SSpinBox.h:374
@ CommittedViaArrowKey
Definition SSpinBox.h:372
@ CommittedViaCode
Definition SSpinBox.h:373
SLATE_API float GetMinDesiredWidth() const
Definition SSpinBox.cpp:816
SLATE_API FText GetValueAsText() const
Definition SSpinBox.cpp:894
SLATE_API void SetSliderExponent(const TAttribute< float > &InSliderExponent)
Definition SSpinBox.cpp:812
SLATE_API void SetMaxSliderValue(const TAttribute< TOptional< NumericType > > &InMaxSliderValue)
Definition SSpinBox.cpp:755
SLATE_API NumericType GetDelta() const
Definition SSpinBox.cpp:800
DECLARE_DELEGATE_TwoParams(FOnValueCommitted, NumericType, ETextCommit::Type)
virtual SLATE_API int32 OnPaint(const FPaintArgs &Args, const FGeometry &AllottedGeometry, const FSlateRect &MyCullingRect, FSlateWindowElementList &OutDrawElements, int32 LayerId, const FWidgetStyle &InWidgetStyle, bool bParentEnabled) const override
Definition SSpinBox.cpp:200
static SLATE_API float Fraction(double InValue, double InMinValue, double InMaxValue)
Definition SSpinBox.cpp:1076
DECLARE_DELEGATE_RetVal_OneParam(TOptional< FText >, FOnGetDisplayValue, NumericType)
SLATE_API void SetTextRevertTextOnEscape(bool bNewValue)
Definition SSpinBox.cpp:852
SLATE_API int32 GetMaxFractionalDigits() const
Definition SSpinBox.cpp:773
SLATE_API void SetTextBlockFont(FSlateFontInfo InFont)
Definition SSpinBox.cpp:836
SLATE_API void SetTextClearKeyboardFocusOnCommit(bool bNewValue)
Definition SSpinBox.cpp:844
SLATE_API void TextField_OnTextChanged(const FText &NewText)
Definition SSpinBox.cpp:914
SLATE_API bool IsMinSliderValueBound() const
Definition SSpinBox.cpp:732
SLATE_API void ApplySliderMinValueChanged(float SliderDeltaToAdd, bool UpdateOnlyIfLower)
Definition SSpinBox.cpp:392
SLATE_API NumericType GetMinValue() const
Definition SSpinBox.cpp:710
SLATE_API void SetMinValue(const TAttribute< TOptional< NumericType > > &InMinValue)
Definition SSpinBox.cpp:714
virtual SLATE_API FReply OnMouseButtonDown(const FGeometry &MyGeometry, const FPointerEvent &MouseEvent) override
Definition SSpinBox.cpp:291
SLATE_API void ExitTextMode()
Definition SSpinBox.cpp:874
virtual SLATE_API FReply OnMouseMove(const FGeometry &MyGeometry, const FPointerEvent &MouseEvent) override
Definition SSpinBox.cpp:420
SLATE_API const FSpinBoxStyle * GetWidgetStyle() const
Definition SSpinBox.cpp:824
SLATE_API bool GetEnableSlider() const
Definition SSpinBox.cpp:792
Definition Attribute.h:17
Definition SharedPointer.h:692
Definition SharedPointer.h:1295
Definition SlateEnums.h:289
Type
Definition SlateEnums.h:291
Definition TextLayout.h:26
Definition SSpinBox.cpp:5
bool bUseSpinBoxMouseMoveOptimization
Definition SSpinBox.cpp:6
@ false
Definition radaudio_common.h:23
Definition Events.h:51
Definition Geometry.h:40
Definition Events.h:155
Definition Events.h:431
Definition Margin.h:17
Definition Events.h:695
Definition SlateBrush.h:239
Definition SlateFontInfo.h:147
Definition SlateTypes.h:1489
Definition NumericTypeInterface.h:21
Definition Optional.h:131
Definition IntPoint.h:25