Files
UnrealEngineUWP/Engine/Source/Programs/CrashReportClient/Private/CrashReportClientStyle.cpp
yohann dossantos 59b5769eca -Text font size changes in Text Box (Multy-Line) widget applies only after moving the text widget
It was the initial bug, but while looking at it, I noticed that the MultilineEditableTextBox was containing both a Font via FEditableTextBoxStyle, and another one via FTextBlockStyle, thus being error prone / inconsistent.
In order to fix the underlying issue (in addition to fix the initial bug), I removed the Font from FEditableTextBoxStyle, and moved the FTextBlockStyle from MultilineEditableTextBox to FEditableTextBoxStyle.
It solves the duplication issue and so make it clear where the Font should be set/read from.
However, as the text block style is now embedded in the editable text box style, it cannot be initialized the exact same way, and I had to do some changes to ensure there was no regression, by configuring various FEditableTextBoxStyle in some style files. I also change the default value for TextBlockStyle to better match our default theme.

-Default font is not set for text widgets.
EditableWidget: ensure to have a default font, and to set the style when calling SynchronizeProperties to ensure it reacts directly without having to force a refresh (by moving the widget for instance)

Bonus:
-Move to cpp some private methods that where 'forced' inline (and we were using function pointer on them). It will avoid some noise in public interface and speed up iteration / compile time when playing with them.

#jira UE-96464
#jira UE-137126

[RN] MultilineEditableTextBox was containing both a Font via FEditableTextBoxStyle, and another one via FTextBlockStyle, thus being error prone / inconsistent.The Font from FEditableTextBoxStyle has been removed, and the FTextBlockStyle moved from MultilineEditableTextBox to FEditableTextBoxStyle. It solves the duplication issue and so make it clear where the Font should be set/read from.
However, as the FTextBlockStyle is now embedded in the FEditableTextBoxStyle, it cannot be initialized the exact same way, and you can now configure the FTextBlockStyle of FEditableTextBoxStyle when creating one from scratch, by calling SetTextStyle on it.


Test
- created a Widget blueprint with different editable types combination: multiline or single line, box or no box.
    -Validated that everything was reacting live as expected now.
    -Created a blue print to set the text style and validated it was working.
    -Create data with old version, then open it with updated version to validate that the visual was still the same and deprecation of style working as expected.
-checked different places in the editor using variation of editable text to ensure they were behaving as before (detail view, console command entry, comment on blueprint node).
#preflight 63344b9f110bb3721ef8aa77

[CL 22232366 by yohann dossantos in ue5-main branch]
2022-09-28 17:59:29 -04:00

138 lines
4.8 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "CrashReportClientStyle.h"
#include "Misc/AssertionMacros.h"
#include "Containers/UnrealString.h"
#include "Misc/Paths.h"
#include "Math/Color.h"
#include "Math/Vector2D.h"
#include "CrashReportClientApp.h"
#include "Styling/StyleColors.h"
#if !CRASH_REPORT_UNATTENDED_ONLY
#include "Styling/SlateStyleRegistry.h"
#include "Styling/SlateTypes.h"
#include "Styling/CoreStyle.h"
TSharedPtr< FSlateStyleSet > FCrashReportClientStyle::StyleSet = nullptr;
void FCrashReportClientStyle::Initialize()
{
if(!StyleSet.IsValid())
{
StyleSet = Create();
FSlateStyleRegistry::RegisterSlateStyle(*StyleSet);
}
}
void FCrashReportClientStyle::Shutdown()
{
FSlateStyleRegistry::UnRegisterSlateStyle(*StyleSet);
ensure(StyleSet.IsUnique());
StyleSet.Reset();
}
#define IMAGE_BRUSH( RelativePath, ... ) FSlateImageBrush(ContentFromEngine(TEXT(RelativePath), TEXT(".png")), __VA_ARGS__)
#define BOX_BRUSH( RelativePath, ... ) FSlateBoxBrush(ContentFromEngine(TEXT(RelativePath), TEXT(".png")), __VA_ARGS__)
#define BORDER_BRUSH( RelativePath, ... ) FSlateBorderBrush(ContentFromEngine(RelativePath, TEXT(".png")), __VA_ARGS__)
#define DEFAULT_FONT(...) FCoreStyle::GetDefaultFontStyle(__VA_ARGS__)
namespace
{
FString ContentFromEngine(const FString& RelativePath, const TCHAR* Extension)
{
static const FString ContentDir = FPaths::EngineDir() / TEXT("Content/Slate");
return ContentDir / RelativePath + Extension;
}
}
TSharedRef< FSlateStyleSet > FCrashReportClientStyle::Create()
{
TSharedRef<FSlateStyleSet> StyleRef = MakeShareable(new FSlateStyleSet("CrashReportClientStyle"));
FSlateStyleSet& Style = StyleRef.Get();
const FTextBlockStyle DefaultText = FTextBlockStyle()
.SetFont(DEFAULT_FONT("Bold", 10))
.SetColorAndOpacity(FSlateColor::UseForeground())
.SetShadowOffset(FVector2D::ZeroVector)
.SetShadowColorAndOpacity(FLinearColor::Black);
// Set the client app styles
Style.Set(TEXT("Code"), FTextBlockStyle(DefaultText)
.SetFont(DEFAULT_FONT("Regular", 8))
.SetColorAndOpacity(FSlateColor(FLinearColor::White * 0.8f))
);
Style.Set(TEXT("Title"), FTextBlockStyle(DefaultText)
.SetFont(DEFAULT_FONT("Bold", 12))
);
Style.Set(TEXT("Status"), FTextBlockStyle(DefaultText)
.SetColorAndOpacity(FSlateColor::UseSubduedForeground())
);
const FVector2D Icon16x16( 16.0f, 16.0f );
FSlateBrush* GenericWhiteBox = new IMAGE_BRUSH( "Old/White", Icon16x16 );
// Scrollbar
const FScrollBarStyle ScrollBar = FScrollBarStyle()
.SetVerticalTopSlotImage(IMAGE_BRUSH("Common/Scrollbar_Background_Vertical", FVector2D(8, 8)))
.SetVerticalBottomSlotImage(IMAGE_BRUSH("Common/Scrollbar_Background_Vertical", FVector2D(8, 8)))
.SetHorizontalTopSlotImage(IMAGE_BRUSH("Common/Scrollbar_Background_Horizontal", FVector2D(8, 8)))
.SetHorizontalBottomSlotImage(IMAGE_BRUSH("Common/Scrollbar_Background_Horizontal", FVector2D(8, 8)))
.SetNormalThumbImage(BOX_BRUSH("Common/Scrollbar_Thumb", FMargin(4.f / 16.f)))
.SetDraggedThumbImage(BOX_BRUSH("Common/Scrollbar_Thumb", FMargin(4.f / 16.f)))
.SetHoveredThumbImage(BOX_BRUSH("Common/Scrollbar_Thumb", FMargin(4.f / 16.f)));
// SEditableTextBox defaults...
const FTextBlockStyle& NormalText = FAppStyle::Get().GetWidgetStyle<FTextBlockStyle>("NormalText");
const FEditableTextBoxStyle NormalEditableTextBoxStyle = FEditableTextBoxStyle()
.SetTextStyle(NormalText)
.SetBackgroundImageNormal(*GenericWhiteBox)
.SetBackgroundImageHovered(*GenericWhiteBox)
.SetBackgroundImageFocused(*GenericWhiteBox)
.SetBackgroundImageReadOnly(*GenericWhiteBox)
.SetScrollBarStyle(ScrollBar);
{
Style.Set( "NormalEditableTextBox", NormalEditableTextBoxStyle );
}
// RichText
const FTextBlockStyle CrashReportDataStyle = FTextBlockStyle()
.SetFont( DEFAULT_FONT( "Italic", 9 ) )
.SetColorAndOpacity( FSlateColor( FLinearColor::White * 0.5f ) )
.SetShadowOffset( FVector2D::ZeroVector )
.SetShadowColorAndOpacity( FLinearColor::Black );
Style.Set( "CrashReportDataStyle", CrashReportDataStyle );
FButtonStyle DarkHyperlinkButton = FButtonStyle()
.SetNormal( BORDER_BRUSH( "Old/HyperlinkDotted", FMargin( 0, 0, 0, 3 / 16.0f ), FSlateColor( FLinearColor::White * 0.5f ) ) )
.SetPressed( FSlateNoResource() )
.SetHovered( BORDER_BRUSH( "Old/HyperlinkUnderline", FMargin( 0, 0, 0, 3 / 16.0f ), FSlateColor( FLinearColor::White * 0.5f ) ) );
const FHyperlinkStyle DarkHyperlink = FHyperlinkStyle()
.SetUnderlineStyle( DarkHyperlinkButton )
.SetTextStyle( CrashReportDataStyle )
.SetPadding( FMargin( 0.0f ) );
Style.Set( "RichText.Hyperlink", DarkHyperlink );
Style.Set("ToolPanel.GroupBorder", new FSlateColorBrush(FStyleColors::Panel));
return StyleRef;
}
#undef IMAGE_BRUSH
#undef BOX_BRUSH
#undef BORDER_BRUSH
#undef DEFAULT_FONT
const ISlateStyle& FCrashReportClientStyle::Get()
{
return *StyleSet;
}
#endif // !CRASH_REPORT_UNATTENDED_ONLY