UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
SlateColor.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"
7#include "UObject/Class.h"
9#include "SlateColor.generated.h"
10
16UENUM(BlueprintType)
18{
20 UseColor_Specified UMETA(DisplayName = "Specified Color"),
21
24
26 UseColor_Foreground UMETA(DisplayName = "Foreground Color"),
27
30
33};
34
35enum class EStyleColor : uint8;
36
40USTRUCT(BlueprintType)
42{
44
45public:
46
53 : SpecifiedColor(FLinearColor(1.0f, 0.0f, 1.0f))
55 { }
56
62 FSlateColor(const FLinearColor& InColor)
63 : SpecifiedColor(InColor)
65 { }
66
67
73 FSlateColor(const FColor InColor)
74 : SpecifiedColor(InColor.ReinterpretAsLinear())
76 { }
77
78
79 /*
80 * Creates a new Slate color that is linked to the given values.
81 *
82 * @param InColor The color value to assign.
83 */
85 : SpecifiedColor(*InColor)
87 { }
88
90 : SpecifiedColor()
92 , ColorTableId(InColorTableId)
93 { }
94
95public:
96
104 const FLinearColor& GetColor( const FWidgetStyle& InWidgetStyle ) const
105 {
106 switch(ColorUseRule)
107 {
108 default:
109 case ESlateColorStylingMode::UseColor_Foreground:
110 case ESlateColorStylingMode::UseColor_UseStyle:
111 return InWidgetStyle.GetForegroundColor();
112 break;
113
114 case ESlateColorStylingMode::UseColor_Specified:
115 return SpecifiedColor;
116 break;
117
118 case ESlateColorStylingMode::UseColor_ColorTable:
119 return GetColorFromTable();
120 break;
121
122 case ESlateColorStylingMode::UseColor_Foreground_Subdued:
123 return InWidgetStyle.GetSubduedForegroundColor();
124 break;
125 };
126 }
127
135 {
136 if (ColorUseRule == ESlateColorStylingMode::UseColor_ColorTable)
137 {
138 return GetColorFromTable();
139 }
140
141 return SpecifiedColor;
142 }
143
150 bool IsColorSpecified( ) const
151 {
152 return (ColorUseRule == ESlateColorStylingMode::UseColor_Specified) || (ColorUseRule == ESlateColorStylingMode::UseColor_ColorTable);
153 }
154
160 void Unlink()
161 {
162 if (ColorUseRule == ESlateColorStylingMode::UseColor_ColorTable)
163 {
164 SpecifiedColor = GetColorFromTable();
165 ColorUseRule = ESlateColorStylingMode::UseColor_Specified;
166 }
167 }
168
176 bool operator==( const FSlateColor& Other ) const
177 {
178 return SpecifiedColor == Other.SpecifiedColor
179 && ColorUseRule == Other.ColorUseRule
180 && (ColorUseRule != ESlateColorStylingMode::UseColor_ColorTable || ColorTableId == Other.ColorTableId);
181 }
182
190 bool operator!=( const FSlateColor& Other ) const
191 {
192 return !(*this == Other);
193 }
194
195public:
196
199 {
200 return FSlateColor( ESlateColorStylingMode::UseColor_Foreground );
201 }
202
205 {
206 return FSlateColor( ESlateColorStylingMode::UseColor_Foreground_Subdued );
207 }
208
211 {
212 return FSlateColor(ESlateColorStylingMode::UseColor_UseStyle);
213 }
214
215
217 SLATECORE_API bool SerializeFromMismatchedTag(const struct FPropertyTag& Tag, FStructuredArchive::FSlot Slot);
218
219protected:
220
221 // Private constructor to prevent construction of invalid FSlateColors
223 : SpecifiedColor(FLinearColor(1.0f, 0.0f, 1.0f))
224 , ColorUseRule(InColorUseRule)
225 , ColorTableId()
226 { }
227
228 SLATECORE_API const FLinearColor& GetColorFromTable() const;
229protected:
230
231 // The current specified color; only meaningful when ColorToUse == UseColor_Specified.
232 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Color)
233 FLinearColor SpecifiedColor;
234
235 // The rule for which color to pick.
236 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Color)
238
239private:
240 // Id to a color in a color table to be used with ESlateColorStylingMode::UseColor_ColorTable
241 EStyleColor ColorTableId;
242};
243
244template<>
247{
248 enum
249 {
250 WithStructuredSerializeFromMismatchedTag = true,
251 };
252};
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define UPROPERTY(...)
UObject definition macros.
Definition ObjectMacros.h:744
#define UENUM(...)
Definition ObjectMacros.h:749
#define USTRUCT(...)
Definition ObjectMacros.h:746
#define GENERATED_USTRUCT_BODY(...)
Definition ObjectMacros.h:767
ESlateColorStylingMode
Definition SlateColor.h:18
EStyleColor
Definition StyleColors.h:32
uint8_t uint8
Definition binka_ue_file_header.h:8
Definition StructuredArchiveSlots.h:52
Definition WidgetStyle.h:15
const FLinearColor & GetForegroundColor() const
Definition WidgetStyle.h:98
const FLinearColor & GetSubduedForegroundColor() const
Definition WidgetStyle.h:109
Definition Color.h:486
Definition Color.h:48
Definition PropertyTag.h:38
Definition SlateColor.h:42
static FSlateColor UseSubduedForeground()
Definition SlateColor.h:204
FSlateColor()
Definition SlateColor.h:52
FSlateColor(const FLinearColor &InColor)
Definition SlateColor.h:62
FSlateColor(const FColor InColor)
Definition SlateColor.h:73
bool operator==(const FSlateColor &Other) const
Definition SlateColor.h:176
FSlateColor(EStyleColor InColorTableId)
Definition SlateColor.h:89
FSlateColor(ESlateColorStylingMode InColorUseRule)
Definition SlateColor.h:222
FLinearColor GetSpecifiedColor() const
Definition SlateColor.h:134
bool IsColorSpecified() const
Definition SlateColor.h:150
bool operator!=(const FSlateColor &Other) const
Definition SlateColor.h:190
const FLinearColor & GetColor(const FWidgetStyle &InWidgetStyle) const
Definition SlateColor.h:104
static FSlateColor UseForeground()
Definition SlateColor.h:198
void Unlink()
Definition SlateColor.h:160
FSlateColor(const TSharedRef< FLinearColor > &InColor)
Definition SlateColor.h:84
static FSlateColor UseStyle()
Definition SlateColor.h:210
Definition StructOpsTypeTraits.h:11
Definition StructOpsTypeTraits.h:46