๐จ Style Registration System
Short Description
Gorgeous Things includes a style registration system that allows you to easily register custom icons and thumbnails for your editor assets and classes, using a shared Slate style set. This system provides helper macros to streamline the registration process and ensure consistent styling across your editor utilities.
Long Description
The style registration system in Gorgeous Things is designed to simplify the process of adding custom icons and thumbnails for your editor assets and classes. By using a shared FSlateStyleSet, you can centralize all your style definitions in one place per plugin, making it easier to manage and maintain your editor's visual identity.
The main macro, GORGEOUS_REGISTER_STYLE_SET, allows you to define a new style set for your plugin, specifying the content root for your resources. Within the scope of this macro, you can use helper macros like GORGEOUS_STYLE_SET_BRUSHES, GORGEOUS_STYLE_SET_NATIVE_CLASS_BRUSHES, GORGEOUS_STYLE_MAP_PARENT_CLASS_BRUSHES, and GORGEOUS_STYLE_MAP_ENGINE_SVG_BRUSHES to brushes for your assets and classes with minimal boilerplate.
This system not only streamlines the registration process but also promotes consistency in how styles are defined and applied across your editor utilities. By leveraging Unreal's Slate styling framework, you can ensure that your custom icons and thumbnails integrate seamlessly with the overall look and feel of the Unreal Editor.
Getting the Styleset
IGorgeousThingsModuleInterface defines a GetModuleStyleSet() function that returns a reference to the shared pointer of the style set defined in your module implementation file. This allows you to access the registered styles from anywhere in your code by including the appropriate header and calling this function. The documentation for this function can be found in the IGorgeousThingsModuleInterface documentation. @TODO
๐ Features (Macro Side)
GORGEOUS_REGISTER_STYLE_SET
Registers a new style set for the editor utilities. It takes in a shared pointer variable that will hold the created style set instance, the name of the style set, the name of the plugin for resource location, and a block of code containing calls to helper macros for setting brushes. The macro checks if the style set is already valid to prevent duplicate registrations, creates a new FSlateStyleSet, sets its content root based on the plugin's base directory, executes the provided block of code to register brushes, and finally registers the style set with the Slate style registry.
| Parameter | Type | Description |
|---|---|---|
GGorgeousStyle |
TSharedPtr<FSlateStyleSet>& |
A reference to a shared pointer variable that will hold the created style set instance. This variable should be defined in the module implementation file. |
StyleName |
FString |
The name of the style set, which will be used as a prefix for all brushes registered to this style set. |
PluginName |
FString |
The name of the plugin that this style set belongs to, used to locate the resources for the style set. |
StyleScopeCalls |
Code Block | A block of code containing calls to the helper macros for setting brushes, which will be executed within the scope of the style set registration, allowing the brushes to be registered to the style set before it is registered to the Slate style registry. |
// In your module implementation file (e.g., MyPluginModule.cpp)
// Define the shared pointer variable for the style set
TSharedPtr<FSlateStyleSet> GMyPluginStyleSet;
void FMyPluginModule::StartupModule()
{
// Register the style set using the macro
GORGEOUS_REGISTER_STYLE_SET(GMyPluginStyleSet, "MyPluginStyle", "MyPlugin",
{
// Register brushes using helper macros within the scope of the style set registration
GORGEOUS_STYLE_SET_BRUSHES(TEXT("ObjectVariable"), TEXT("variable-cube"), TEXT("GorgeousObjectVariableBlueprint"));
GORGEOUS_STYLE_SET_NATIVE_CLASS_BRUSHES(TEXT("variable-cube"), TEXT("GorgeousObjectVariable"));
GORGEOUS_STYLE_MAP_PARENT_CLASS_BRUSHES(TEXT("GorgeousGameInstanceBlueprint"), TEXT("Object"));
GORGEOUS_STYLE_MAP_ENGINE_SVG_BRUSHES(TEXT("GorgeousPlayerStateBlueprint"), TEXT("AssetIcons/Actor_64.svg"));
});
}
GORGEOUS_STYLE_SET_BRUSHES
Used within the scope of a style set registration to set both icon and thumbnail brushes for a given key and class name, using the same file name for both. It takes in the style set to which the brushes will be added, a unique key that identifies the asset or class these brushes represent, the base file name of the image to be used for both the icon and thumbnail, and the name of the class for which the brushes are being set. The macro constructs the appropriate brush names and registers new FSlateImageBrush instances for both the icon and thumbnail using the provided file name.
| Parameter | Type | Description |
|---|---|---|
Key |
FString |
A unique key that identifies the asset or class these brushes represent. This key is used to construct the brush names for registration. |
FileName |
FString |
The base file name (without extension) of the image to be used for both the icon and thumbnail. The macro will append ".png" to this file name when creating the brushes. |
ClassName |
FString |
The name of the class for which the brushes are being set, used for class icon and thumbnail registration. This is also used to construct the brush names for registration. |
// Within the scope of a style set registration (e.g., inside GORGEOUS_REGISTER_STYLE_SET)
// Register brushes for a custom asset or class
GORGEOUS_STYLE_SET_BRUSHES(TEXT("ObjectVariable"), TEXT("variable-cube"), TEXT("GorgeousObjectVariableBlueprint"));
GORGEOUS_STYLE_SET_NATIVE_CLASS_BRUSHES
Used within the scope of a style set registration to set both icon and thumbnail brushes for a native class, using the same file name for both. It takes in the style set to which the brushes will be added, the base file name of the image to be used for both the icon and thumbnail, and the name of the native class for which the brushes are being set. The macro constructs the appropriate brush names and registers new FSlateImageBrush instances for both the icon and thumbnail using the provided file name.
| Parameter | Type | Description |
|---|---|---|
FileName |
FString |
The base file name (without extension) of the image to be used for both the icon and thumbnail. The macro will append ".png" to this file name when creating the brushes. |
NativeClassName |
FString |
The name of the native class for which the brushes are being set, used for class icon and thumbnail registration. This is also used to construct the brush names for registration. |
// Within the scope of a style set registration (e.g., inside GORGEOUS_REGISTER_STYLE_SET)
// Register brushes for a native class
GORGEOUS_STYLE_SET_NATIVE_CLASS_BRUSHES(TEXT("variable-cube"), TEXT("GorgeousObjectVariable"));
GORGEOUS_STYLE_MAP_PARENT_CLASS_BRUSHES
Used within the scope of a style set registration to map the brushes of a parent class to a child class, which allows the child class to use the same icon and thumbnail as the parent class without needing to set new brushes. It takes in the style set to which the brushes will be added, the name of the child class for which the brushes are being mapped, and the name of the parent class from which to copy the brushes. The macro retrieves the brushes for both the icon and thumbnail from the parent class using FAppStyle::Get().GetBrush() and registers them for the child class.
| Parameter | Type | Description |
|---|---|---|
ClassName |
FString |
The name of the child class for which the brushes are being mapped, used for class icon and thumbnail registration. This is also used to construct the brush names for registration. |
ParentClassName |
FString |
The name of the parent class from which to copy the brushes, used to retrieve the brushes for both the icon and thumbnail. This is also used to construct the brush names for retrieval. |
// Within the scope of a style set registration (e.g., inside GORGEOUS_REGISTER_STYLE_SET)
// Map the brushes of a parent class to a child class
GORGEOUS_STYLE_MAP_PARENT_CLASS_BRUSHES(TEXT("GorgeousGameInstanceBlueprint"), TEXT("Object"));
GORGEOUS_STYLE_MAP_ENGINE_SVG_BRUSHES
Used within the scope of a style set registration to set both icon and thumbnail brushes for a class, using an SVG file from the engine content directory. It takes in the style set to which the brushes will be added, the name of the class for which the brushes are being set, and the relative path to the SVG file within the engine content directory. The macro constructs the full path to the SVG file, creates new FSlateVectorImageBrush instances for both the icon and thumbnail using the SVG file, and registers them for the specified class.
| Parameter | Type | Description |
|---|---|---|
ClassName |
FString |
The name of the class for which the brushes are being set, used for class icon and thumbnail registration. This is also used to construct the brush names for registration. |
RelativeSvgPath |
FString |
The relative path to the SVG file within the engine content directory, without the file extension, used to locate the SVG file for both the icon and thumbnail. The macro will combine this with the engine content directory path and append ".svg" when creating the brushes. |
// Within the scope of a style set registration (e.g., inside GORGEOUS_REGISTER_STYLE_SET)
// Set brushes for a class using an SVG file from the engine content directory
GORGEOUS_STYLE_MAP_ENGINE_SVG_BRUSHES(TEXT("GorgeousPlayerStateBlueprint"), TEXT("AssetIcons/Actor_64"));
GORGEOUS_STYLE_REGISTER_FONT
Registers a TrueType or OpenType font file into the current Gorgeous style set. The macro takes in a style key that can be used to look up the font at runtime, the relative path to the font file within the plugin's Resources directory (without the file extension), and a default point size for the font. The macro calls a helper function to perform the actual registration of the font into the style set.
| Parameter | Type | Description |
|---|---|---|
FontKey |
FString |
The style key used to look up the font at runtime (e.g., "GorgeousCore.EmojiFont"). This key is used when retrieving the font from the style set. |
RelativePath |
FString |
The path to the font file relative to the plugin's Resources directory, without the file extension. This is used to locate the font file for registration. |
DefaultSize |
int |
The default point size stored in the FSlateFontInfo for this font (e.g., 14). This defines the default size of the font when it is retrieved and used in Slate widgets. |
// Within the scope of a style set registration (e.g., inside GORGEOUS_REGISTER_STYLE_SET)
// Register a font for use in the style set
GORGEOUS_STYLE_REGISTER_FONT(TEXT("GorgeousCore.EmojiFont"), TEXT("Fonts/EmojiFont"), 14);
๐ Features (Namespace Side)
Helper Functions
The GorgeousStyleRegistration namespace contains underlying forceinline helper functions that are called by the macros to perform the actual work of setting brushes for the style set. These functions take in the necessary parameters to construct the brush names and create the appropriate FSlateBrush instances, allowing the macros to provide a clean and simple interface for registering styles while keeping the implementation details encapsulated within these helper functions.
SetBrushes
Used to set both icon and thumbnail brushes for a given key and class name, using the same file name for both. It takes in the style set to which the brushes will be added, a unique key that identifies the asset or class these brushes represent, the base file name of the image to be used for both the icon and thumbnail, and the name of the class for which the brushes are being set. The function constructs the appropriate brush names and registers new FSlateImageBrush instances for both the icon and thumbnail using the provided file name.
| Parameter | Type | Description |
|---|---|---|
Style |
TSharedPtr<FSlateStyleSet>& |
The style set to which the brushes will be added. This is typically the shared pointer variable defined in the module implementation file that holds the style set instance. |
Key |
FString |
A unique key that identifies the asset or class these brushes represent. This key is used to construct the brush names for registration. |
FileName |
FString |
The base file name (without extension) of the image to be used for both the icon and thumbnail. The function will append ".png" to this file name when creating the brushes. |
ClassName |
FString |
The name of the class for which the brushes are being set, used for class icon and thumbnail registration. This is also used to construct the brush names for registration. |
// Example of using the SetBrushes helper function directly (though typically you would use the macro that calls this function)
// Assume Style is a valid TSharedPtr<FSlateStyleSet> instance
GorgeousStyleRegistration::SetBrushes(Style, TEXT("ObjectVariable"), TEXT("variable-cube"), TEXT("GorgeousObjectVariableBlueprint"));
SetNativeClassBrushes
Used to set both icon and thumbnail brushes for a native class, using the same file name for both. It takes in the style set to which the brushes will be added, the base file name of the image to be used for both the icon and thumbnail, and the name of the native class for which the brushes are being set. The function constructs the appropriate brush names and registers new FSlateImageBrush instances for both the icon and thumbnail using the provided file name.
| Parameter | Type | Description |
|---|---|---|
Style |
TSharedPtr<FSlateStyleSet>& |
The style set to which the brushes will be added. This is typically the shared pointer variable defined in the module implementation file that holds the style set instance. |
FileName |
FString |
The base file name (without extension) of the image to be used for both the icon and thumbnail. The function will append ".png" to this file name when creating the brushes. |
NativeClassName |
FString |
The name of the native class for which the brushes are being set, used for class icon and thumbnail registration. This is also used to construct the brush names for registration. |
// Example of using the SetNativeClassBrushes helper function directly (though typically you would use the macro that calls this function)
// Assume Style is a valid TSharedPtr<FSlateStyleSet> instance
GorgeousStyleRegistration::SetNativeClassBrushes(Style, TEXT("variable-cube"), TEXT("GorgeousObjectVariable"));
MapParentClassBrushes
Used to map the brushes of a parent class to a child class, which allows the child class to use the same icon and thumbnail as the parent class without needing to set new brushes. It takes in the style set to which the brushes will be added, the name of the child class for which the brushes are being mapped, and the name of the parent class from which to copy the brushes. The function retrieves the brushes for both the icon and thumbnail from the parent class using FAppStyle::Get().GetBrush() and registers them for the child class.
| Parameter | Type | Description |
|---|---|---|
Style |
TSharedPtr<FSlateStyleSet>& |
The style set to which the brushes will be added. This is typically the shared pointer variable defined in the module implementation file that holds the style set instance. |
ClassName |
FString |
The name of the child class for which the brushes are being mapped, used for class icon and thumbnail registration. This is also used to construct the brush names for registration. |
ParentClassName |
FString |
The name of the parent class from which to copy the brushes, used to retrieve the brushes for both the icon and thumbnail. This is also used to construct the brush names for retrieval. |
// Example of using the MapParentClassBrushes helper function directly (though typically you would use the macro that calls this function)
// Assume Style is a valid TSharedPtr<FSlateStyleSet> instance
GorgeousStyleRegistration::MapParentClassBrushes(Style, TEXT("GorgeousGameInstanceBlueprint"), TEXT("Object"));
MapEngineSvgBrushes
Used to set both icon and thumbnail brushes for a class, using an SVG file from the engine content directory. It takes in the style set to which the brushes will be added, the name of the class for which the brushes are being set, and the relative path to the SVG file within the engine content directory. The function constructs the full path to the SVG file, creates new FSlateVectorImageBrush instances for both the icon and thumbnail using the SVG file, and registers them for the specified class.
| Parameter | Type | Description |
|---|---|---|
Style |
TSharedPtr<FSlateStyleSet>& |
The style set to which the brushes will be added. This is typically the shared pointer variable defined in the module implementation file that holds the style set instance. |
ClassName |
FString |
The name of the class for which the brushes are being set, used for class icon and thumbnail registration. This is also used to construct the brush names for registration. |
RelativeSvgPath |
FString |
The relative path to the SVG file within the engine content directory, without the file extension, used to locate the SVG file for both the icon and thumbnail. The function will combine this with the engine content directory path and append ".svg" when creating the brushes. |
// Example of using the MapEngineSvgBrushes helper function directly (though typically you would use the macro that calls this function)
// Assume Style is a valid TSharedPtr<FSlateStyleSet> instance
GorgeousStyleRegistration::MapEngineSvgBrushes(Style, TEXT("GorgeousPlayerStateBlueprint"), TEXT("AssetIcons/Actor_64"));
RegisterFont
Helper function to register a TrueType or OpenType font file into a Slate style set. The font is stored under a specified style key and can be retrieved using the style set's GetFontStyle method or the ISlateStyle::GetFontStyle interface. The function takes in the style set to register the font into, the style key used to look up the font, the relative path to the font file within the style set's content root (without the file extension), and an optional default point size for the font.
| Parameter | Type | Description |
|---|---|---|
Style |
TSharedPtr<FSlateStyleSet>& |
The style set to register the font into. This is typically the shared pointer variable defined in the module implementation file that holds the style set instance. |
FontKey |
FString |
The style key used to look up the font at runtime (e.g., "GorgeousCore.EmojiFont"). This key is used when retrieving the font from the style set. |
RelativePath |
FString |
The path to the font file relative to the plugin's Resources directory, without the file extension. This is used to locate the font file for registration. |
DefaultSize |
int |
The default point size stored in the FSlateFontInfo for this font (e.g., 14). This defines the default size of the font when it is retrieved and used in Slate widgets. |
// Example of using the RegisterFont helper function directly (though typically you would use the macro that calls this function)
// Assume Style is a valid TSharedPtr<FSlateStyleSet> instance
GorgeousStyleRegistration::RegisterFont(Style, TEXT("GorgeousCore.EmojiFont"), TEXT("Fonts/EmojiFont"), 14);