From f237d5d87d2c19b3c435adb3c966fabb234e4fa2 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Wed, 9 Jun 2021 12:16:50 +0200 Subject: [PATCH] Post merge fixes to font reference as class #420 --- Source/Engine/Render2D/FontReference.cs | 22 +++++++++++++--------- Source/Engine/UI/GUI/Common/Label.cs | 8 ++++---- Source/Engine/UI/GUI/Common/RichTextBox.cs | 18 ++++++++++++------ Source/Engine/UI/GUI/Style.cs | 8 ++++---- 4 files changed, 33 insertions(+), 23 deletions(-) diff --git a/Source/Engine/Render2D/FontReference.cs b/Source/Engine/Render2D/FontReference.cs index 449134b94..22b0e02c8 100644 --- a/Source/Engine/Render2D/FontReference.cs +++ b/Source/Engine/Render2D/FontReference.cs @@ -18,6 +18,16 @@ namespace FlaxEngine [NoSerialize] private Font _cachedFont; + /// + /// Initializes a new instance of the struct. + /// + public FontReference() + { + _font = null; + _size = 30; + _cachedFont = null; + } + /// /// Initializes a new instance of the struct. /// @@ -61,9 +71,7 @@ namespace FlaxEngine if (_font != value) { _font = value; - - if (_cachedFont) - _cachedFont = null; + _cachedFont = null; } } } @@ -80,9 +88,7 @@ namespace FlaxEngine if (_size != value) { _size = value; - - if (_cachedFont) - _cachedFont = null; + _cachedFont = null; } } } @@ -104,9 +110,7 @@ namespace FlaxEngine /// Determines whether the specified is equal to this instance. /// /// The to compare with this instance. - /// - /// true if the specified is equal to this instance; otherwise, false. - /// + /// true if the specified is equal to this instance; otherwise, false. [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(FontReference other) { diff --git a/Source/Engine/UI/GUI/Common/Label.cs b/Source/Engine/UI/GUI/Common/Label.cs index 1b06e1867..ba5763f31 100644 --- a/Source/Engine/UI/GUI/Common/Label.cs +++ b/Source/Engine/UI/GUI/Common/Label.cs @@ -185,8 +185,8 @@ namespace FlaxEngine.GUI AutoFocus = false; var style = Style.Current; Font = new FontReference(style.FontMedium); - TextColor = Style.Current.Foreground; - TextColorHighlighted = Style.Current.Foreground; + TextColor = style.Foreground; + TextColorHighlighted = style.Foreground; } /// @@ -196,8 +196,8 @@ namespace FlaxEngine.GUI AutoFocus = false; var style = Style.Current; Font = new FontReference(style.FontMedium); - TextColor = Style.Current.Foreground; - TextColorHighlighted = Style.Current.Foreground; + TextColor = style.Foreground; + TextColorHighlighted = style.Foreground; } /// diff --git a/Source/Engine/UI/GUI/Common/RichTextBox.cs b/Source/Engine/UI/GUI/Common/RichTextBox.cs index 837ec0ec7..8b2cc5cb3 100644 --- a/Source/Engine/UI/GUI/Common/RichTextBox.cs +++ b/Source/Engine/UI/GUI/Common/RichTextBox.cs @@ -9,12 +9,7 @@ namespace FlaxEngine.GUI /// public class RichTextBox : RichTextBoxBase { - private TextBlockStyle _textStyle = new TextBlockStyle - { - Font = new FontReference(Style.Current.FontMedium), - Color = Style.Current.Foreground, - BackgroundSelectedBrush = new SolidColorBrush(Style.Current.BackgroundSelected), - }; + private TextBlockStyle _textStyle; /// /// The text style applied to the whole text. @@ -30,6 +25,17 @@ namespace FlaxEngine.GUI } } + public RichTextBox() + { + var style = Style.Current; + _textStyle = new TextBlockStyle + { + Font = new FontReference(style.FontMedium), + Color = style.Foreground, + BackgroundSelectedBrush = new SolidColorBrush(style.BackgroundSelected), + }; + } + /// protected override void OnParseTextBlocks() { diff --git a/Source/Engine/UI/GUI/Style.cs b/Source/Engine/UI/GUI/Style.cs index a945d1602..5b77e8682 100644 --- a/Source/Engine/UI/GUI/Style.cs +++ b/Source/Engine/UI/GUI/Style.cs @@ -22,7 +22,7 @@ namespace FlaxEngine.GUI [EditorOrder(10)] public Font FontTitle { - get => _fontTitle.GetFont(); + get => _fontTitle?.GetFont(); set => _fontTitle = new FontReference(value); } @@ -36,7 +36,7 @@ namespace FlaxEngine.GUI [EditorOrder(20)] public Font FontLarge { - get => _fontLarge.GetFont(); + get => _fontLarge?.GetFont(); set => _fontLarge = new FontReference(value); } @@ -50,7 +50,7 @@ namespace FlaxEngine.GUI [EditorOrder(30)] public Font FontMedium { - get => _fontMedium.GetFont(); + get => _fontMedium?.GetFont(); set => _fontMedium = new FontReference(value); } @@ -64,7 +64,7 @@ namespace FlaxEngine.GUI [EditorOrder(40)] public Font FontSmall { - get => _fontSmall.GetFont(); + get => _fontSmall?.GetFont(); set => _fontSmall = new FontReference(value); }