Add fallback settings to CSharp

This commit is contained in:
ExMatics HydrogenC
2023-11-30 23:12:56 +08:00
parent d3840bb1f3
commit cdbe59a3fb
54 changed files with 357 additions and 273 deletions

View File

@@ -39,7 +39,7 @@ namespace FlaxEditor.Content.Create
AnchorPreset = AnchorPresets.HorizontalStretchTop, AnchorPreset = AnchorPresets.HorizontalStretchTop,
Offsets = new Margin(0, 0, 0, 40), Offsets = new Margin(0, 0, 0, 40),
Parent = this, Parent = this,
Font = new MultiFontReference(Style.Current.FontTitle) Font = new FontReference(Style.Current.FontTitle)
}; };
var infoLabel = new Label var infoLabel = new Label
{ {

View File

@@ -60,7 +60,7 @@ namespace FlaxEditor.Content.Import
AnchorPreset = AnchorPresets.HorizontalStretchTop, AnchorPreset = AnchorPresets.HorizontalStretchTop,
Offsets = new Margin(0, 0, 0, 40), Offsets = new Margin(0, 0, 0, 40),
Parent = this, Parent = this,
Font = new MultiFontReference(Style.Current.FontTitle) Font = new FontReference(Style.Current.FontTitle)
}; };
var infoLabel = new Label var infoLabel = new Label
{ {

View File

@@ -81,7 +81,7 @@ namespace FlaxEditor.CustomEditors.Dedicated
// Title // Title
var title = new Label(2, 2, width - 4, 23.0f) var title = new Label(2, 2, width - 4, 23.0f)
{ {
Font = new MultiFontReference(FlaxEngine.GUI.Style.Current.FontLarge), Font = new FontReference(FlaxEngine.GUI.Style.Current.FontLarge),
Text = "Ragdoll Options", Text = "Ragdoll Options",
Parent = this Parent = this
}; };

View File

@@ -43,7 +43,7 @@ namespace FlaxEditor.CustomEditors.Dedicated
// Add script button // Add script button
var buttonText = "Add script"; var buttonText = "Add script";
var textSize = Style.Current.FontMedium.MeasureText(buttonText); var textSize = Render2D.MeasureText(Style.Current.FontMedium, buttonText);
float addScriptButtonWidth = (textSize.X < 60.0f) ? 60.0f : textSize.X + 4; float addScriptButtonWidth = (textSize.X < 60.0f) ? 60.0f : textSize.X + 4;
var buttonHeight = (textSize.Y < 18) ? 18 : textSize.Y + 4; var buttonHeight = (textSize.Y < 18) ? 18 : textSize.Y + 4;
_addScriptsButton = new Button _addScriptsButton = new Button

View File

@@ -239,7 +239,7 @@ namespace FlaxEditor.CustomEditors.Dedicated
// Title // Title
var title = new Label(2, 2, DialogWidth - 4, TitleHeight) var title = new Label(2, 2, DialogWidth - 4, TitleHeight)
{ {
Font = new MultiFontReference(style.FontLarge), Font = new FontReference(style.FontLarge),
Text = "Anchor Presets", Text = "Anchor Presets",
Parent = this Parent = this
}; };
@@ -247,7 +247,7 @@ namespace FlaxEditor.CustomEditors.Dedicated
// Info // Info
var info = new Label(0, title.Bottom, DialogWidth, InfoHeight) var info = new Label(0, title.Bottom, DialogWidth, InfoHeight)
{ {
Font = new MultiFontReference(style.FontSmall), Font = new FontReference(style.FontSmall),
Text = "Shift: also set bounds\nControl: also set pivot", Text = "Shift: also set bounds\nControl: also set pivot",
Parent = this Parent = this
}; };
@@ -423,7 +423,7 @@ namespace FlaxEditor.CustomEditors.Dedicated
// Set control type button // Set control type button
var space = layout.Space(20); var space = layout.Space(20);
var buttonText = "Set Type"; var buttonText = "Set Type";
var textSize = FlaxEngine.GUI.Style.Current.FontMedium.MeasureText(buttonText); var textSize = Render2D.MeasureText(FlaxEngine.GUI.Style.Current.FontMedium, buttonText);
float setTypeButtonWidth = (textSize.X < 60.0f) ? 60.0f : textSize.X + 4; float setTypeButtonWidth = (textSize.X < 60.0f) ? 60.0f : textSize.X + 4;
var setTypeButton = new Button var setTypeButton = new Button
{ {

View File

@@ -101,7 +101,7 @@ namespace FlaxEditor.CustomEditors.Editors
_linkButton.Clicked += ToggleLink; _linkButton.Clicked += ToggleLink;
ToggleEnabled(); ToggleEnabled();
SetLinkStyle(); SetLinkStyle();
var textSize = FlaxEngine.GUI.Style.Current.FontMedium.MeasureText(LinkedLabel.Text.Value); var textSize = Render2D.MeasureText(FlaxEngine.GUI.Style.Current.FontMedium, LinkedLabel.Text.Value);
_linkButton.LocalX += textSize.X + 10; _linkButton.LocalX += textSize.X + 10;
LinkedLabel.SetupContextMenu += (label, menu, editor) => LinkedLabel.SetupContextMenu += (label, menu, editor) =>
{ {

View File

@@ -631,7 +631,7 @@ namespace FlaxEditor.CustomEditors.Editors
TooltipText = "Edit...", TooltipText = "Edit...",
Parent = _label, Parent = _label,
}; };
var textSize = FlaxEngine.GUI.Style.Current.FontMedium.MeasureText(buttonText); var textSize = Render2D.MeasureText(FlaxEngine.GUI.Style.Current.FontMedium, buttonText);
if (textSize.Y > button.Width) if (textSize.Y > button.Width)
button.Width = textSize.Y + 2; button.Width = textSize.Y + 2;

View File

@@ -276,7 +276,7 @@ namespace FlaxEditor.CustomEditors
public LabelElement Header(string text) public LabelElement Header(string text)
{ {
var element = Label(text); var element = Label(text);
element.Label.Font = new MultiFontReference(Style.Current.FontLarge); element.Label.Font = new FontReference(Style.Current.FontLarge);
return element; return element;
} }
@@ -284,7 +284,7 @@ namespace FlaxEditor.CustomEditors
{ {
var element = Header(header.Text); var element = Header(header.Text);
if (header.FontSize != -1) if (header.FontSize != -1)
element.Label.Font = new MultiFontReference(element.Label.Font, header.FontSize); element.Label.Font = new FontReference(element.Label.Font.Font, header.FontSize);
if (header.Color != 0) if (header.Color != 0)
element.Label.TextColor = Color.FromRGBA(header.Color); element.Label.TextColor = Color.FromRGBA(header.Color);
return element; return element;

View File

@@ -35,7 +35,7 @@ namespace FlaxEditor.GUI
/// <summary> /// <summary>
/// The title font. /// The title font.
/// </summary> /// </summary>
public MultiFont TitleFont; public Font TitleFont;
/// <summary> /// <summary>
/// The column title text color. /// The column title text color.

View File

@@ -191,7 +191,7 @@ namespace FlaxEditor.GUI
/// Gets or sets the font used to draw text. /// Gets or sets the font used to draw text.
/// </summary> /// </summary>
[EditorDisplay("Style"), EditorOrder(2000)] [EditorDisplay("Style"), EditorOrder(2000)]
public MultiFontReference Font { get; set; } public FontReference Font { get; set; }
/// <summary> /// <summary>
/// Gets or sets the color of the text. /// Gets or sets the color of the text.
@@ -273,7 +273,7 @@ namespace FlaxEditor.GUI
MaximumItemsInViewCount = 20; MaximumItemsInViewCount = 20;
var style = Style.Current; var style = Style.Current;
Font = new MultiFontReference(style.FontMedium); Font = new FontReference(style.FontMedium);
TextColor = style.Foreground; TextColor = style.Foreground;
BackgroundColor = style.BackgroundNormal; BackgroundColor = style.BackgroundNormal;
BackgroundColorHighlighted = BackgroundColor; BackgroundColorHighlighted = BackgroundColor;
@@ -554,7 +554,7 @@ namespace FlaxEditor.GUI
var textRect = new Rectangle(margin, 0, clientRect.Width - boxSize - 2.0f * margin, clientRect.Height); var textRect = new Rectangle(margin, 0, clientRect.Width - boxSize - 2.0f * margin, clientRect.Height);
Render2D.PushClip(textRect); Render2D.PushClip(textRect);
var textColor = TextColor; var textColor = TextColor;
Render2D.DrawText(Font.GetMultiFont(), text, textRect, enabled ? textColor : textColor * 0.5f, TextAlignment.Near, TextAlignment.Center, TextWrapping.NoWrap, 1.0f, textScale); Render2D.DrawText(Font.GetFont(), text, textRect, enabled ? textColor : textColor * 0.5f, TextAlignment.Near, TextAlignment.Center, TextWrapping.NoWrap, 1.0f, textScale);
Render2D.PopClip(); Render2D.PopClip();
} }

View File

@@ -236,9 +236,9 @@ namespace FlaxEditor.GUI.ContextMenu
float width = 20; float width = 20;
if (style.FontMedium) if (style.FontMedium)
{ {
width += style.FontMedium.MeasureText(Text).X; width += Render2D.MeasureText(style.FontMedium, Text).X;
if (!string.IsNullOrEmpty(ShortKeys)) if (!string.IsNullOrEmpty(ShortKeys))
width += 40 + style.FontMedium.MeasureText(ShortKeys).X; width += 40 + Render2D.MeasureText(style.FontMedium, ShortKeys).X;
} }
return Mathf.Max(width, base.MinimumWidth); return Mathf.Max(width, base.MinimumWidth);

View File

@@ -317,7 +317,7 @@ namespace FlaxEditor.GUI
private Color _contentsColor; private Color _contentsColor;
private Color _linesColor; private Color _linesColor;
private Color _labelsColor; private Color _labelsColor;
private MultiFont _labelsFont; private Font _labelsFont;
/// <summary> /// <summary>
/// The keyframe UI points. /// The keyframe UI points.

View File

@@ -489,7 +489,7 @@ namespace FlaxEditor.GUI.Docking
{ {
var style = Style.Current; var style = Style.Current;
if (style?.FontMedium != null) if (style?.FontMedium != null)
_titleSize = style.FontMedium.MeasureText(_title); _titleSize = Render2D.MeasureText(style.FontMedium, _title);
} }
base.PerformLayoutBeforeChildren(); base.PerformLayoutBeforeChildren();

View File

@@ -76,7 +76,7 @@ namespace FlaxEditor.GUI
var windowIcon = FlaxEngine.Content.LoadAsyncInternal<Texture>(EditorAssets.WindowIcon); var windowIcon = FlaxEngine.Content.LoadAsyncInternal<Texture>(EditorAssets.WindowIcon);
FontAsset windowIconsFont = FlaxEngine.Content.LoadAsyncInternal<FontAsset>(EditorAssets.WindowIconsFont); FontAsset windowIconsFont = FlaxEngine.Content.LoadAsyncInternal<FontAsset>(EditorAssets.WindowIconsFont);
MultiFont iconFont = new MultiFontReference([windowIconsFont], 9).GetMultiFont(); Font iconFont = windowIconsFont?.CreateFont(9);
_window = mainWindow.RootWindow.Window; _window = mainWindow.RootWindow.Window;
_window.HitTest += OnHitTest; _window.HitTest += OnHitTest;
@@ -108,7 +108,7 @@ namespace FlaxEditor.GUI
_closeButton = new Button _closeButton = new Button
{ {
Text = ((char)EditorAssets.SegMDL2Icons.ChromeClose).ToString(), Text = ((char)EditorAssets.SegMDL2Icons.ChromeClose).ToString(),
Font = new MultiFontReference(iconFont), Font = new FontReference(iconFont),
BackgroundColor = Color.Transparent, BackgroundColor = Color.Transparent,
BorderColor = Color.Transparent, BorderColor = Color.Transparent,
BorderColorHighlighted = Color.Transparent, BorderColorHighlighted = Color.Transparent,
@@ -124,7 +124,7 @@ namespace FlaxEditor.GUI
_minimizeButton = new Button _minimizeButton = new Button
{ {
Text = ((char)EditorAssets.SegMDL2Icons.ChromeMinimize).ToString(), Text = ((char)EditorAssets.SegMDL2Icons.ChromeMinimize).ToString(),
Font = new MultiFontReference(iconFont), Font = new FontReference(iconFont),
BackgroundColor = Color.Transparent, BackgroundColor = Color.Transparent,
BorderColor = Color.Transparent, BorderColor = Color.Transparent,
BorderColorHighlighted = Color.Transparent, BorderColorHighlighted = Color.Transparent,
@@ -139,7 +139,7 @@ namespace FlaxEditor.GUI
_maximizeButton = new Button _maximizeButton = new Button
{ {
Text = ((char)(_window.IsMaximized ? EditorAssets.SegMDL2Icons.ChromeRestore : EditorAssets.SegMDL2Icons.ChromeMaximize)).ToString(), Text = ((char)(_window.IsMaximized ? EditorAssets.SegMDL2Icons.ChromeRestore : EditorAssets.SegMDL2Icons.ChromeMaximize)).ToString(),
Font = new MultiFontReference(iconFont), Font = new FontReference(iconFont),
BackgroundColor = Color.Transparent, BackgroundColor = Color.Transparent,
BorderColor = Color.Transparent, BorderColor = Color.Transparent,
BorderColorHighlighted = Color.Transparent, BorderColorHighlighted = Color.Transparent,

View File

@@ -103,7 +103,7 @@ namespace FlaxEditor.GUI
float width = 18; float width = 18;
if (style.FontMedium) if (style.FontMedium)
width += style.FontMedium.MeasureText(Text).X; width += Render2D.MeasureText(style.FontMedium, Text).X;
Width = width; Width = width;
} }

View File

@@ -68,7 +68,7 @@ namespace FlaxEditor.GUI
if (style.FontMedium) if (style.FontMedium)
{ {
Width = style.FontMedium.MeasureText(Text).X + 2 * DefaultMargin; Width = Render2D.MeasureText(style.FontMedium, Text).X + 2 * DefaultMargin;
} }
} }
} }

View File

@@ -39,8 +39,8 @@ namespace FlaxEditor.GUI
{ {
Depth = -1; Depth = -1;
if (Height < Style.Current.FontMedium.MaxHeight) if (Height < Style.Current.FontMedium.Height)
Height = Style.Current.FontMedium.MaxHeight + 4; Height = Style.Current.FontMedium.Height + 4;
} }
/// <inheritdoc /> /// <inheritdoc />

View File

@@ -345,7 +345,7 @@ namespace FlaxEditor.GUI.Timeline.Tracks
if (_previewValue != null) if (_previewValue != null)
{ {
// Based on Track.Draw for track text placement // Based on Track.Draw for track text placement
var left = _xOffset + 16 + Style.Current.FontSmall.MeasureText(Title ?? Name).X; var left = _xOffset + 16 + Render2D.MeasureText(Style.Current.FontSmall, Title ?? Name).X;
if (Icon.IsValid) if (Icon.IsValid)
left += 18; left += 18;
if (IsExpanded) if (IsExpanded)

View File

@@ -152,7 +152,7 @@ namespace FlaxEditor.GUI
if (hasSprite) if (hasSprite)
width += iconSize; width += iconSize;
if (!string.IsNullOrEmpty(_text) && style.FontMedium) if (!string.IsNullOrEmpty(_text) && style.FontMedium)
width += style.FontMedium.MeasureText(_text).X + (hasSprite ? DefaultMargin : 0); width += Render2D.MeasureText(style.FontMedium, _text).X + (hasSprite ? DefaultMargin : 0);
Width = width; Width = width;
} }

View File

@@ -115,7 +115,7 @@ namespace FlaxEditor.GUI.Tree
/// Gets or sets the font used to render text. /// Gets or sets the font used to render text.
/// </summary> /// </summary>
[EditorDisplay("Style"), EditorOrder(2000)] [EditorDisplay("Style"), EditorOrder(2000)]
public MultiFontReference TextFont { get; set; } public FontReference TextFont { get; set; }
/// <summary> /// <summary>
/// Gets or sets the color of the background when tree node is selected. /// Gets or sets the color of the background when tree node is selected.
@@ -318,7 +318,7 @@ namespace FlaxEditor.GUI.Tree
BackgroundColorSelected = style.BackgroundSelected; BackgroundColorSelected = style.BackgroundSelected;
BackgroundColorHighlighted = style.BackgroundHighlighted; BackgroundColorHighlighted = style.BackgroundHighlighted;
BackgroundColorSelectedUnfocused = style.LightBackground; BackgroundColorSelectedUnfocused = style.LightBackground;
TextFont = new MultiFontReference(style.FontSmall); TextFont = new FontReference(style.FontSmall);
} }
/// <summary> /// <summary>
@@ -573,10 +573,10 @@ namespace FlaxEditor.GUI.Tree
{ {
if (_textChanged) if (_textChanged)
{ {
var font = TextFont.GetMultiFont(); var font = TextFont.GetFont();
if (font) if (font)
{ {
_textWidth = font.MeasureText(_text).X; _textWidth = Render2D.MeasureText(font, _text).X;
_textChanged = false; _textChanged = false;
} }
} }
@@ -657,7 +657,7 @@ namespace FlaxEditor.GUI.Tree
} }
// Draw text // Draw text
Render2D.DrawText(TextFont.GetMultiFont(), _text, textRect, _cachedTextColor, TextAlignment.Near, TextAlignment.Center); Render2D.DrawText(TextFont.GetFont(), _text, textRect, _cachedTextColor, TextAlignment.Near, TextAlignment.Center);
// Draw drag and drop effect // Draw drag and drop effect
if (IsDragOver && _tree.DraggedOverNode == this) if (IsDragOver && _tree.DraggedOverNode == this)

View File

@@ -171,8 +171,10 @@ namespace FlaxEditor.Options
get => _outputLogFont; get => _outputLogFont;
set set
{ {
if (value == null || !value.Font) if (value == null)
_outputLogFont = new FontReference(ConsoleFont, 10); _outputLogFont = new FontReference(FlaxEngine.Content.LoadAsyncInternal<FontAsset>(EditorAssets.InconsolataRegularFont), 10);
else if (!value.Font)
_outputLogFont.Font = FlaxEngine.Content.LoadAsyncInternal<FontAsset>(EditorAssets.InconsolataRegularFont);
else else
_outputLogFont = value; _outputLogFont = value;
} }
@@ -234,30 +236,34 @@ namespace FlaxEditor.Options
[EditorDisplay("Cook & Run"), EditorOrder(500)] [EditorDisplay("Cook & Run"), EditorOrder(500)]
public int NumberOfGameClientsToLaunch = 1; public int NumberOfGameClientsToLaunch = 1;
private static FontAsset[] DefaultFonts => private static FontAsset DefaultFont => FlaxEngine.Content.LoadAsyncInternal<FontAsset>(EditorAssets.PrimaryFont);
[FlaxEngine.Content.LoadAsyncInternal<FontAsset>(EditorAssets.PrimaryFont),
FlaxEngine.Content.LoadAsyncInternal<FontAsset>(EditorAssets.CjkFont)];
private static FontAsset ConsoleFont => FlaxEngine.Content.LoadAsyncInternal<FontAsset>(EditorAssets.PrimaryFont); private static FontAsset ConsoleFont => FlaxEngine.Content.LoadAsyncInternal<FontAsset>(EditorAssets.PrimaryFont);
private MultiFontReference _titleFont = new MultiFontReference(DefaultFonts, 18); private FontReference _titleFont = new FontReference(DefaultFont, 18);
private MultiFontReference _largeFont = new MultiFontReference(DefaultFonts, 14); private FontReference _largeFont = new FontReference(DefaultFont, 14);
private MultiFontReference _mediumFont = new MultiFontReference(DefaultFonts, 9); private FontReference _mediumFont = new FontReference(DefaultFont, 9);
private MultiFontReference _smallFont = new MultiFontReference(DefaultFonts, 9); private FontReference _smallFont = new FontReference(DefaultFont, 9);
private FontReference _outputLogFont = new FontReference(ConsoleFont, 10); private FontReference _outputLogFont = new FontReference(ConsoleFont, 10);
/// <summary>
/// The fallback fonts.
/// </summary>
public FontAsset[] Fallbacks = [FlaxEngine.Content.LoadAsyncInternal<FontAsset>(EditorAssets.CjkFont)];
/// <summary> /// <summary>
/// Gets or sets the title font for editor UI. /// Gets or sets the title font for editor UI.
/// </summary> /// </summary>
[EditorDisplay("Fonts"), EditorOrder(600), Tooltip("The title font for editor UI.")] [EditorDisplay("Fonts"), EditorOrder(600), Tooltip("The title font for editor UI.")]
public MultiFontReference TitleFont public FontReference TitleFont
{ {
get => _titleFont; get => _titleFont;
set set
{ {
if (value == null || !value.Verify()) if (value == null)
_titleFont = new MultiFontReference(DefaultFonts, 18); _titleFont = new FontReference(DefaultFont, 18);
else if (!value.Font)
_titleFont.Font = DefaultFont;
else else
_titleFont = value; _titleFont = value;
} }
@@ -267,13 +273,15 @@ namespace FlaxEditor.Options
/// Gets or sets the large font for editor UI. /// Gets or sets the large font for editor UI.
/// </summary> /// </summary>
[EditorDisplay("Fonts"), EditorOrder(610), Tooltip("The large font for editor UI.")] [EditorDisplay("Fonts"), EditorOrder(610), Tooltip("The large font for editor UI.")]
public MultiFontReference LargeFont public FontReference LargeFont
{ {
get => _largeFont; get => _largeFont;
set set
{ {
if (value == null || !value.Verify()) if (value == null)
_largeFont = new MultiFontReference(DefaultFonts, 14); _largeFont = new FontReference(DefaultFont, 14);
else if (!value.Font)
_largeFont.Font = DefaultFont;
else else
_largeFont = value; _largeFont = value;
} }
@@ -283,13 +291,15 @@ namespace FlaxEditor.Options
/// Gets or sets the medium font for editor UI. /// Gets or sets the medium font for editor UI.
/// </summary> /// </summary>
[EditorDisplay("Fonts"), EditorOrder(620), Tooltip("The medium font for editor UI.")] [EditorDisplay("Fonts"), EditorOrder(620), Tooltip("The medium font for editor UI.")]
public MultiFontReference MediumFont public FontReference MediumFont
{ {
get => _mediumFont; get => _mediumFont;
set set
{ {
if (value == null || !value.Verify()) if (value == null)
_mediumFont = new MultiFontReference(DefaultFonts, 9); _mediumFont = new FontReference(DefaultFont, 9);
else if (!value.Font)
_mediumFont.Font = DefaultFont;
else else
_mediumFont = value; _mediumFont = value;
} }
@@ -299,13 +309,15 @@ namespace FlaxEditor.Options
/// Gets or sets the small font for editor UI. /// Gets or sets the small font for editor UI.
/// </summary> /// </summary>
[EditorDisplay("Fonts"), EditorOrder(630), Tooltip("The small font for editor UI.")] [EditorDisplay("Fonts"), EditorOrder(630), Tooltip("The small font for editor UI.")]
public MultiFontReference SmallFont public FontReference SmallFont
{ {
get => _smallFont; get => _smallFont;
set set
{ {
if (value == null || !value.Verify()) if (value == null)
_smallFont = new MultiFontReference(DefaultFonts, 9); _smallFont = new FontReference(DefaultFont, 9);
else if (!value.Font)
_smallFont.Font = DefaultFont;
else else
_smallFont = value; _smallFont = value;
} }

View File

@@ -217,12 +217,14 @@ namespace FlaxEditor.Options
if (styleName == ThemeOptions.LightDefault) if (styleName == ThemeOptions.LightDefault)
{ {
Style.Current = CreateLightStyle(); Style.Current = CreateLightStyle();
} }
else else
{ {
Style.Current = CreateDefaultStyle(); Style.Current = CreateDefaultStyle();
} }
} }
Render2D.Fallbacks = FallbackFonts.Create(Options.Interface.Fallbacks);
} }
/// <summary> /// <summary>
@@ -259,10 +261,10 @@ namespace FlaxEditor.Options
}, },
// Fonts // Fonts
FontTitle = options.Interface.TitleFont.GetMultiFont(), FontTitle = options.Interface.TitleFont.GetFont(),
FontLarge = options.Interface.LargeFont.GetMultiFont(), FontLarge = options.Interface.LargeFont.GetFont(),
FontMedium = options.Interface.MediumFont.GetMultiFont(), FontMedium = options.Interface.MediumFont.GetFont(),
FontSmall = options.Interface.SmallFont.GetMultiFont(), FontSmall = options.Interface.SmallFont.GetFont(),
// Icons // Icons
ArrowDown = Editor.Icons.ArrowDown12, ArrowDown = Editor.Icons.ArrowDown12,
@@ -312,10 +314,10 @@ namespace FlaxEditor.Options
ProgressNormal = new Color(0.03f, 0.65f, 0.12f, 1f), ProgressNormal = new Color(0.03f, 0.65f, 0.12f, 1f),
// Fonts // Fonts
FontTitle = options.Interface.TitleFont.GetMultiFont(), FontTitle = options.Interface.TitleFont.GetFont(),
FontLarge = options.Interface.LargeFont.GetMultiFont(), FontLarge = options.Interface.LargeFont.GetFont(),
FontMedium = options.Interface.MediumFont.GetMultiFont(), FontMedium = options.Interface.MediumFont.GetFont(),
FontSmall = options.Interface.SmallFont.GetMultiFont(), FontSmall = options.Interface.SmallFont.GetFont(),
// Icons // Icons
ArrowDown = Editor.Icons.ArrowDown12, ArrowDown = Editor.Icons.ArrowDown12,

View File

@@ -337,7 +337,7 @@ namespace FlaxEditor.Surface.Archetypes
_textRect = new Rectangle(Float2.Zero, Size); _textRect = new Rectangle(Float2.Zero, Size);
var style = Style.Current; var style = Style.Current;
var titleSize = style.FontLarge.MeasureText(Title); var titleSize = Render2D.MeasureText(style.FontLarge, Title);
var width = Mathf.Max(100, titleSize.X + 50); var width = Mathf.Max(100, titleSize.X + 50);
Resize(width, 0); Resize(width, 0);
titleSize.X += 8.0f; titleSize.X += 8.0f;
@@ -1402,7 +1402,7 @@ namespace FlaxEditor.Surface.Archetypes
{ {
Title = StateTitle; Title = StateTitle;
var style = Style.Current; var style = Style.Current;
var titleSize = style.FontLarge.MeasureText(Title); var titleSize = Render2D.MeasureText(style.FontLarge, Title);
var width = Mathf.Max(100, titleSize.X + 50); var width = Mathf.Max(100, titleSize.X + 50);
Resize(width, 0); Resize(width, 0);
titleSize.X += 8.0f; titleSize.X += 8.0f;

View File

@@ -39,7 +39,7 @@ namespace FlaxEditor.Surface.Archetypes
// Title // Title
var title = new Label(2, 2, width - 4, 23.0f) var title = new Label(2, 2, width - 4, 23.0f)
{ {
Font = new MultiFontReference(Style.Current.FontLarge), Font = new FontReference(Style.Current.FontLarge),
Text = transition.SurfaceName, Text = transition.SurfaceName,
Parent = this Parent = this
}; };

View File

@@ -77,7 +77,7 @@ namespace FlaxEditor.Surface.Archetypes
Title = asset?.ShortName ?? "Animation"; Title = asset?.ShortName ?? "Animation";
var style = Style.Current; var style = Style.Current;
Resize(Mathf.Max(230, style.FontLarge.MeasureText(Title).X + 30), 160); Resize(Mathf.Max(230, Render2D.MeasureText(style.FontLarge, Title).X + 30), 160);
} }
/// <inheritdoc /> /// <inheritdoc />

View File

@@ -101,7 +101,7 @@ namespace FlaxEditor.Surface.Archetypes
_debugRelevant = Behavior.GetNodeDebugRelevancy(instance, behavior); _debugRelevant = Behavior.GetNodeDebugRelevancy(instance, behavior);
_debugInfo = Behavior.GetNodeDebugInfo(instance, behavior); _debugInfo = Behavior.GetNodeDebugInfo(instance, behavior);
if (!string.IsNullOrEmpty(_debugInfo)) if (!string.IsNullOrEmpty(_debugInfo))
_debugInfoSize = Style.Current.FontSmall.MeasureText(_debugInfo); _debugInfoSize = Render2D.MeasureText(Style.Current.FontSmall, _debugInfo);
} }
} }
@@ -488,7 +488,7 @@ namespace FlaxEditor.Surface.Archetypes
var height = 0.0f; var height = 0.0f;
var titleLabelFont = Style.Current.FontLarge; var titleLabelFont = Style.Current.FontLarge;
width = Mathf.Max(width, 100.0f); width = Mathf.Max(width, 100.0f);
width = Mathf.Max(width, titleLabelFont.MeasureText(Title).X + 30); width = Mathf.Max(width, Render2D.MeasureText(titleLabelFont, Title).X + 30);
if (_debugInfoSize.X > 0) if (_debugInfoSize.X > 0)
{ {
width = Mathf.Max(width, _debugInfoSize.X + 8.0f); width = Mathf.Max(width, _debugInfoSize.X + 8.0f);

View File

@@ -1407,7 +1407,7 @@ namespace FlaxEditor.Surface.Archetypes
// Title // Title
var title = new Label(2, 2, width - 4, 23.0f) var title = new Label(2, 2, width - 4, 23.0f)
{ {
Font = new MultiFontReference(Style.Current.FontLarge), Font = new FontReference(Style.Current.FontLarge),
Text = "Edit function signature", Text = "Edit function signature",
Parent = this Parent = this
}; };

View File

@@ -83,7 +83,7 @@ namespace FlaxEditor.Surface
// Title // Title
var title = new Label(2, 2, width - 4, 23.0f) var title = new Label(2, 2, width - 4, 23.0f)
{ {
Font = new MultiFontReference(Style.Current.FontLarge), Font = new FontReference(Style.Current.FontLarge),
Text = "Edit attributes", Text = "Edit attributes",
Parent = this Parent = this
}; };

View File

@@ -141,7 +141,7 @@ namespace FlaxEditor.Surface.ContextMenu
}; };
// Title bar // Title bar
var titleFontReference = new MultiFontReference(Style.Current.FontLarge); var titleFontReference = new FontReference(Style.Current.FontLarge);
var titleLabel = new Label var titleLabel = new Label
{ {
Width = Width * 0.5f - 8f, Width = Width * 0.5f - 8f,

View File

@@ -286,7 +286,7 @@ namespace FlaxEditor.Surface.ContextMenu
Render2D.DrawText(style.FontSmall, _archetype.Title, textRect, Enabled ? style.Foreground : style.ForegroundDisabled, TextAlignment.Near, TextAlignment.Center); Render2D.DrawText(style.FontSmall, _archetype.Title, textRect, Enabled ? style.Foreground : style.ForegroundDisabled, TextAlignment.Near, TextAlignment.Center);
if (_archetype.SubTitle != null) if (_archetype.SubTitle != null)
{ {
var titleLength = style.FontSmall.MeasureText(_archetype.Title).X; var titleLength = Render2D.MeasureText(style.FontSmall, _archetype.Title).X;
var subTitleRect = new Rectangle(textRect.X + titleLength, textRect.Y, textRect.Width - titleLength, textRect.Height); var subTitleRect = new Rectangle(textRect.X + titleLength, textRect.Y, textRect.Width - titleLength, textRect.Height);
Render2D.DrawText(style.FontSmall, _archetype.SubTitle, subTitleRect, style.ForegroundDisabled, TextAlignment.Near, TextAlignment.Center); Render2D.DrawText(style.FontSmall, _archetype.SubTitle, subTitleRect, style.ForegroundDisabled, TextAlignment.Near, TextAlignment.Center);
} }

View File

@@ -1428,7 +1428,7 @@ namespace FlaxEditor.Surface.Elements
if (_defaultValueEditor != null) if (_defaultValueEditor != null)
{ {
_defaultValueEditor.Location = new Float2(X + Width + 8 + Style.Current.FontSmall.MeasureText(Text).X, Y); _defaultValueEditor.Location = new Float2(X + Width + 8 + Render2D.MeasureText(Style.Current.FontSmall, Text).X, Y);
} }
} }
@@ -1635,7 +1635,7 @@ namespace FlaxEditor.Surface.Elements
{ {
if (DefaultValueEditors[i].CanUse(this, ref _currentType)) if (DefaultValueEditors[i].CanUse(this, ref _currentType))
{ {
var bounds = new Rectangle(X + Width + 8 + Style.Current.FontSmall.MeasureText(Text).X, Y, 90, Height); var bounds = new Rectangle(X + Width + 8 + Render2D.MeasureText(Style.Current.FontSmall, Text).X, Y, 90, Height);
_editor = DefaultValueEditors[i]; _editor = DefaultValueEditors[i];
try try
{ {

View File

@@ -200,7 +200,7 @@ namespace FlaxEditor.Surface
continue; continue;
if (child is InputBox inputBox) if (child is InputBox inputBox)
{ {
var boxWidth = boxLabelFont.MeasureText(inputBox.Text).X + 20; var boxWidth = Render2D.MeasureText(boxLabelFont, inputBox.Text).X + 20;
if (inputBox.DefaultValueEditor != null) if (inputBox.DefaultValueEditor != null)
boxWidth += inputBox.DefaultValueEditor.Width + 4; boxWidth += inputBox.DefaultValueEditor.Width + 4;
leftWidth = Mathf.Max(leftWidth, boxWidth); leftWidth = Mathf.Max(leftWidth, boxWidth);
@@ -208,7 +208,7 @@ namespace FlaxEditor.Surface
} }
else if (child is OutputBox outputBox) else if (child is OutputBox outputBox)
{ {
rightWidth = Mathf.Max(rightWidth, boxLabelFont.MeasureText(outputBox.Text).X + 20); rightWidth = Mathf.Max(rightWidth, Render2D.MeasureText(boxLabelFont, outputBox.Text).X + 20);
rightHeight = Mathf.Max(rightHeight, outputBox.Archetype.Position.Y - Constants.NodeMarginY - Constants.NodeHeaderSize + 20.0f); rightHeight = Mathf.Max(rightHeight, outputBox.Archetype.Position.Y - Constants.NodeMarginY - Constants.NodeHeaderSize + 20.0f);
} }
else if (child is Control control) else if (child is Control control)
@@ -226,7 +226,7 @@ namespace FlaxEditor.Surface
} }
} }
width = Mathf.Max(width, leftWidth + rightWidth + 10); width = Mathf.Max(width, leftWidth + rightWidth + 10);
width = Mathf.Max(width, titleLabelFont.MeasureText(Title).X + 30); width = Mathf.Max(width, Render2D.MeasureText(titleLabelFont, Title).X + 30);
height = Mathf.Max(height, Mathf.Max(leftHeight, rightHeight)); height = Mathf.Max(height, Mathf.Max(leftHeight, rightHeight));
Resize(width, height); Resize(width, height);
} }

View File

@@ -148,7 +148,7 @@ namespace FlaxEditor.Tools.Foliage
Parent = _noFoliagePanel, Parent = _noFoliagePanel,
Enabled = false Enabled = false
}; };
var textSize = Style.Current.FontMedium.MeasureText(buttonText); var textSize = Render2D.MeasureText(Style.Current.FontMedium, buttonText);
if (_createNewFoliage.Width < textSize.X) if (_createNewFoliage.Width < textSize.X)
{ {
_createNewFoliage.LocalX -= (textSize.X - _createNewFoliage.Width) / 2; _createNewFoliage.LocalX -= (textSize.X - _createNewFoliage.Width) / 2;

View File

@@ -106,7 +106,7 @@ namespace FlaxEditor.Tools.Terrain
Parent = _noTerrainPanel, Parent = _noTerrainPanel,
Enabled = false Enabled = false
}; };
var textSize = Style.Current.FontMedium.MeasureText(buttonText); var textSize = Render2D.MeasureText(Style.Current.FontMedium, buttonText);
if (_createTerrainButton.Width < textSize.X) if (_createTerrainButton.Width < textSize.X)
{ {
_createTerrainButton.LocalX -= (textSize.X - _createTerrainButton.Width) / 2; _createTerrainButton.LocalX -= (textSize.X - _createTerrainButton.Width) / 2;

View File

@@ -96,7 +96,7 @@ namespace FlaxEditor.Tools.Terrain
AnchorPreset = AnchorPresets.HorizontalStretchTop, AnchorPreset = AnchorPresets.HorizontalStretchTop,
Offsets = new Margin(0, 0, 0, 40), Offsets = new Margin(0, 0, 0, 40),
Parent = this, Parent = this,
Font = new MultiFontReference(Style.Current.FontTitle) Font = new FontReference(Style.Current.FontTitle)
}; };
var infoLabel = new Label var infoLabel = new Label
{ {

View File

@@ -0,0 +1,108 @@
using FlaxEngine.GUI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FlaxEngine
{
public static class TextRenderUtils
{
/// <summary>
/// Draws a text using the global fallback defined in styles.
/// </summary>
/// <param name="font">The font to use.</param>
/// <param name="text">The text to render.</param>
/// <param name="layoutRect">The size and position of the area in which the text is drawn.</param>
/// <param name="color">The text color.</param>
/// <param name="horizontalAlignment">The horizontal alignment of the text in a layout rectangle.</param>
/// <param name="verticalAlignment">The vertical alignment of the text in a layout rectangle.</param>
/// <param name="textWrapping">Describes how wrap text inside a layout rectangle.</param>
/// <param name="baseLinesGapScale">The scale for distance one baseline from another. Default is 1.</param>
/// <param name="scale">The text drawing scale. Default is 1.</param>
public static void DrawTextWithFallback(Font font, string text, Rectangle layoutRect, Color color, TextAlignment horizontalAlignment = TextAlignment.Near, TextAlignment verticalAlignment = TextAlignment.Near, TextWrapping textWrapping = TextWrapping.NoWrap, float baseLinesGapScale = 1.0f, float scale = 1.0f)
{
var layout = new TextLayoutOptions
{
Bounds = layoutRect,
HorizontalAlignment = horizontalAlignment,
VerticalAlignment = verticalAlignment,
TextWrapping = textWrapping,
Scale = scale,
BaseLinesGapScale = baseLinesGapScale,
};
Render2D.DrawText(font, Style.Current.Fallbacks, text, color, ref layout);
}
/// <summary>
/// Draws a text using the global fallback defined in styles. Given material must have GUI domain and a public parameter named Font (texture parameter used for a font atlas sampling).
/// </summary>
/// <param name="font">The font to use.</param>
/// <param name="customMaterial">Custom material for font characters rendering. It must contain texture parameter named Font used to sample font texture.</param>
/// <param name="text">The text to render.</param>
/// <param name="layoutRect">The size and position of the area in which the text is drawn.</param>
/// <param name="color">The text color.</param>
/// <param name="horizontalAlignment">The horizontal alignment of the text in a layout rectangle.</param>
/// <param name="verticalAlignment">The vertical alignment of the text in a layout rectangle.</param>
/// <param name="textWrapping">Describes how wrap text inside a layout rectangle.</param>
/// <param name="baseLinesGapScale">The scale for distance one baseline from another. Default is 1.</param>
/// <param name="scale">The text drawing scale. Default is 1.</param>
public static void DrawTextWithFallback(Font font, MaterialBase customMaterial, string text, Rectangle layoutRect, Color color, TextAlignment horizontalAlignment = TextAlignment.Near, TextAlignment verticalAlignment = TextAlignment.Near, TextWrapping textWrapping = TextWrapping.NoWrap, float baseLinesGapScale = 1.0f, float scale = 1.0f)
{
var layout = new TextLayoutOptions
{
Bounds = layoutRect,
HorizontalAlignment = horizontalAlignment,
VerticalAlignment = verticalAlignment,
TextWrapping = textWrapping,
Scale = scale,
BaseLinesGapScale = baseLinesGapScale,
};
Render2D.DrawText(font, Style.Current.Fallbacks, text, color, ref layout, customMaterial);
}
public static Float2 MeasureTextWithFallback(Font font, string text)
{
return font.MeasureText(Style.Current.Fallbacks, text);
}
public static Float2 MeasureTextWithFallback(Font font, string text, ref TextRange textRange)
{
return font.MeasureText(Style.Current.Fallbacks, text, ref textRange);
}
public static Float2 MeasureTextWithFallback(Font font, string text, ref TextLayoutOptions layout)
{
return font.MeasureText(Style.Current.Fallbacks, text, ref layout);
}
public static Float2 MeasureTextWithFallback(Font font, string text, ref TextRange textRange, ref TextLayoutOptions layout)
{
return font.MeasureText(Style.Current.Fallbacks, text, ref textRange, ref layout);
}
public static Float2 GetCharPositionWithFallback(Font font, string text, int index)
{
return font.GetCharPosition(Style.Current.Fallbacks, text, index);
}
public static Float2 GetCharPositionWithFallback(Font font, string text, ref TextRange textRange, int index)
{
return font.GetCharPosition(Style.Current.Fallbacks, text, ref textRange, index);
}
public static Float2 GetCharPositionWithFallback(Font font, string text, int index, ref TextLayoutOptions layout)
{
return font.GetCharPosition(Style.Current.Fallbacks, text, index, ref layout);
}
public static Float2 GetCharPositionWithFallback(Font font, string text, ref TextRange textRange, int index, ref TextLayoutOptions layout)
{
return font.GetCharPosition(Style.Current.Fallbacks, text, ref textRange, index, ref layout);
}
}
}

View File

@@ -548,9 +548,9 @@ namespace FlaxEditor.Viewport
#region Camera settings widget #region Camera settings widget
var largestText = "Relative Panning"; var largestText = "Relative Panning";
var textSize = Style.Current.FontMedium.MeasureText(largestText); var textSize = Render2D.MeasureText(Style.Current.FontMedium, largestText);
var xLocationForExtras = textSize.X + 5; var xLocationForExtras = textSize.X + 5;
var cameraSpeedTextWidth = Style.Current.FontMedium.MeasureText("0.00").X; var cameraSpeedTextWidth = Render2D.MeasureText(Style.Current.FontMedium, "0.00").X;
// Camera Settings Widget // Camera Settings Widget
_cameraWidget = new ViewportWidgetsContainer(ViewportWidgetLocation.UpperRight); _cameraWidget = new ViewportWidgetsContainer(ViewportWidgetLocation.UpperRight);
@@ -801,7 +801,7 @@ namespace FlaxEditor.Viewport
#region View mode widget #region View mode widget
largestText = "Brightness"; largestText = "Brightness";
textSize = Style.Current.FontMedium.MeasureText(largestText); textSize = Render2D.MeasureText(Style.Current.FontMedium, largestText);
xLocationForExtras = textSize.X + 5; xLocationForExtras = textSize.X + 5;
var viewMode = new ViewportWidgetsContainer(ViewportWidgetLocation.UpperLeft); var viewMode = new ViewportWidgetsContainer(ViewportWidgetLocation.UpperLeft);

View File

@@ -164,7 +164,7 @@ namespace FlaxEditor.Viewport.Widgets
var style = Style.Current; var style = Style.Current;
if (style != null && style.FontMedium) if (style != null && style.FontMedium)
Width = CalculateButtonWidth(_forcedTextWidth > 0.0f ? _forcedTextWidth : style.FontMedium.MeasureText(_text).X, Icon.IsValid); Width = CalculateButtonWidth(_forcedTextWidth > 0.0f ? _forcedTextWidth : Render2D.MeasureText(style.FontMedium, _text).X, Icon.IsValid);
} }
} }
} }

View File

@@ -41,7 +41,7 @@ namespace FlaxEditor.Windows
var nameLabel = new Label(icon.Right + 10, icon.Top, 200, 34) var nameLabel = new Label(icon.Right + 10, icon.Top, 200, 34)
{ {
Text = "Flax Engine", Text = "Flax Engine",
Font = new MultiFontReference(Style.Current.FontTitle), Font = new FontReference(Style.Current.FontTitle),
HorizontalAlignment = TextAlignment.Near, HorizontalAlignment = TextAlignment.Near,
VerticalAlignment = TextAlignment.Center, VerticalAlignment = TextAlignment.Center,
Parent = this Parent = this
@@ -54,7 +54,7 @@ namespace FlaxEditor.Windows
Parent = this Parent = this
}; };
var buttonText = "Copy version info"; var buttonText = "Copy version info";
var fontSize = Style.Current.FontMedium.MeasureText(buttonText); var fontSize = Render2D.MeasureText(Style.Current.FontMedium, buttonText);
var copyVersionButton = new Button(Width - fontSize.X - 8, 6, fontSize.X + 4, 20) var copyVersionButton = new Button(Width - fontSize.X - 8, 6, fontSize.X + 4, 20)
{ {
Text = buttonText, Text = buttonText,

View File

@@ -144,7 +144,7 @@ namespace FlaxEditor.Windows.Assets
protected override void OnAssetLinked() protected override void OnAssetLinked()
{ {
Asset.WaitForLoaded(); Asset.WaitForLoaded();
_textPreview.Font = new MultiFontReference([Asset], 30); _textPreview.Font = new FontReference(Asset, 30);
_inputText.Text = string.Format("This is a sample text using font {0}.", Asset.FamilyName); _inputText.Text = string.Format("This is a sample text using font {0}.", Asset.FamilyName);
var options = Asset.Options; var options = Asset.Options;
_proxy.Set(ref options); _proxy.Set(ref options);

View File

@@ -57,7 +57,7 @@ namespace FlaxEditor.Windows
var textRect = new Rectangle(margin, 0, clientRect.Width - boxSize - 2.0f * margin, clientRect.Height); var textRect = new Rectangle(margin, 0, clientRect.Width - boxSize - 2.0f * margin, clientRect.Height);
Render2D.PushClip(textRect); Render2D.PushClip(textRect);
var textColor = TextColor; var textColor = TextColor;
Render2D.DrawText(Font.GetMultiFont(), "View", textRect, enabled ? textColor : textColor * 0.5f, TextAlignment.Near, TextAlignment.Center, TextWrapping.NoWrap, 1.0f, textScale); Render2D.DrawText(Font.GetFont(), "View", textRect, enabled ? textColor : textColor * 0.5f, TextAlignment.Near, TextAlignment.Center, TextWrapping.NoWrap, 1.0f, textScale);
Render2D.PopClip(); Render2D.PopClip();
// Arrow // Arrow

View File

@@ -79,7 +79,7 @@ namespace FlaxEditor.Windows
HorizontalAlignment = TextAlignment.Near, HorizontalAlignment = TextAlignment.Near,
AnchorPreset = AnchorPresets.HorizontalStretchTop, AnchorPreset = AnchorPresets.HorizontalStretchTop,
Text = desc.Name, Text = desc.Name,
Font = new MultiFontReference(Style.Current.FontLarge), Font = new FontReference(Style.Current.FontLarge),
Parent = this, Parent = this,
Bounds = new Rectangle(tmp1, margin, Width - tmp1 - margin, 28), Bounds = new Rectangle(tmp1, margin, Width - tmp1 - margin, 28),
}; };
@@ -120,9 +120,9 @@ namespace FlaxEditor.Windows
url = desc.HomepageUrl; url = desc.HomepageUrl;
else if (!string.IsNullOrEmpty(desc.RepositoryUrl)) else if (!string.IsNullOrEmpty(desc.RepositoryUrl))
url = desc.RepositoryUrl; url = desc.RepositoryUrl;
versionLabel.Font.ForEach(x => x.Font.WaitForLoaded()); versionLabel.Font.Font.WaitForLoaded();
var font = versionLabel.Font.GetMultiFont(); var font = versionLabel.Font.GetFont();
var authorWidth = font.MeasureText(desc.Author).X + 8; var authorWidth = Render2D.MeasureText(font, desc.Author).X + 8;
var authorLabel = new ClickableLabel var authorLabel = new ClickableLabel
{ {
HorizontalAlignment = TextAlignment.Far, HorizontalAlignment = TextAlignment.Far,
@@ -392,7 +392,6 @@ namespace FlaxEditor.Windows
} }
Editor.Log("Plugin project has been cloned."); Editor.Log("Plugin project has been cloned.");
try try
{ {
// Start git submodule clone // Start git submodule clone

View File

@@ -86,7 +86,7 @@ namespace FlaxEditor.Windows.Profiler
Render2D.DrawRectangle(bounds, color * 0.5f); Render2D.DrawRectangle(bounds, color * 0.5f);
if (_nameLength < 0 && style.FontMedium) if (_nameLength < 0 && style.FontMedium)
_nameLength = style.FontMedium.MeasureText(_name).X; _nameLength = Render2D.MeasureText(style.FontMedium, _name).X;
if (_nameLength < bounds.Width + 4) if (_nameLength < bounds.Width + 4)
{ {

View File

@@ -39,7 +39,7 @@ public:
/// <summary> /// <summary>
/// Combine the primary fonts with the fallback fonts to get a font list /// Combine the primary fonts with the fallback fonts to get a font list
/// </summary> /// </summary>
API_PROPERTY() FORCE_INLINE Array<Font*>& GetFontList(float size) { API_FUNCTION() FORCE_INLINE Array<Font*>& GetFontList(float size) {
Array<Font*>* result; Array<Font*>* result;
if (_cache.TryGet(size, result)) { if (_cache.TryGet(size, result)) {
return *result; return *result;

View File

@@ -1,74 +0,0 @@
using System.Collections.Generic;
using System.Linq;
namespace FlaxEngine
{
/// <summary>
/// Reference to multiple font references
/// </summary>
public class MultiFontReference : List<FontReference>
{
public MultiFontReference()
{
_cachedFont = null;
}
public MultiFontReference(IEnumerable<FontReference> other)
{
AddRange(other);
_cachedFont = null;
}
public MultiFontReference(MultiFontReference other)
{
AddRange(other);
_cachedFont = other._cachedFont;
}
public MultiFontReference(MultiFontReference other, float size)
{
AddRange(other.Select(x => new FontReference(x) { Size = size }));
_cachedFont = null;
}
public MultiFontReference(MultiFont other)
{
AddRange(other.Fonts.Select(x => new FontReference(x)));
_cachedFont = other;
}
public MultiFontReference(FontAsset[] assets, float size)
{
AddRange(assets.Select(x => new FontReference(x, size)));
_cachedFont = null;
}
[EditorOrder(0), Tooltip("The font asset to use as characters source.")]
public MultiFont GetMultiFont()
{
if (_cachedFont)
return _cachedFont;
var fontList = this.Where(x => x.Font).Select(x => x.GetFont()).ToArray();
_cachedFont = MultiFont.Create(fontList);
return _cachedFont;
}
public bool Verify()
{
foreach (var i in this)
{
if (!i.Font)
{
return false;
}
}
return true;
}
[NoSerialize]
private MultiFont _cachedFont;
}
}

View File

@@ -1,11 +1,17 @@
// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved. // Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
using FlaxEngine.GUI;
using System; using System;
namespace FlaxEngine namespace FlaxEngine
{ {
partial class Render2D partial class Render2D
{ {
public static FallbackFonts Fallbacks
{
get; set;
} = null;
/// <summary> /// <summary>
/// Pushes transformation layer. /// Pushes transformation layer.
/// </summary> /// </summary>
@@ -111,7 +117,8 @@ namespace FlaxEngine
/// <param name="textWrapping">Describes how wrap text inside a layout rectangle.</param> /// <param name="textWrapping">Describes how wrap text inside a layout rectangle.</param>
/// <param name="baseLinesGapScale">The scale for distance one baseline from another. Default is 1.</param> /// <param name="baseLinesGapScale">The scale for distance one baseline from another. Default is 1.</param>
/// <param name="scale">The text drawing scale. Default is 1.</param> /// <param name="scale">The text drawing scale. Default is 1.</param>
public static void DrawText(Font font, string text, Rectangle layoutRect, Color color, TextAlignment horizontalAlignment = TextAlignment.Near, TextAlignment verticalAlignment = TextAlignment.Near, TextWrapping textWrapping = TextWrapping.NoWrap, float baseLinesGapScale = 1.0f, float scale = 1.0f) /// <param name="useFallback">Whether to use fallback fonts for chars not renderable by the font.</param>
public static void DrawText(Font font, string text, Rectangle layoutRect, Color color, TextAlignment horizontalAlignment = TextAlignment.Near, TextAlignment verticalAlignment = TextAlignment.Near, TextWrapping textWrapping = TextWrapping.NoWrap, float baseLinesGapScale = 1.0f, float scale = 1.0f, bool useFallback = true)
{ {
var layout = new TextLayoutOptions var layout = new TextLayoutOptions
{ {
@@ -122,7 +129,15 @@ namespace FlaxEngine
Scale = scale, Scale = scale,
BaseLinesGapScale = baseLinesGapScale, BaseLinesGapScale = baseLinesGapScale,
}; };
DrawText(font, text, color, ref layout);
if (useFallback && Fallbacks != null)
{
DrawText(font, Fallbacks, text, color, ref layout);
}
else
{
DrawText(font, text, color, ref layout);
}
} }
/// <summary> /// <summary>
@@ -138,7 +153,8 @@ namespace FlaxEngine
/// <param name="textWrapping">Describes how wrap text inside a layout rectangle.</param> /// <param name="textWrapping">Describes how wrap text inside a layout rectangle.</param>
/// <param name="baseLinesGapScale">The scale for distance one baseline from another. Default is 1.</param> /// <param name="baseLinesGapScale">The scale for distance one baseline from another. Default is 1.</param>
/// <param name="scale">The text drawing scale. Default is 1.</param> /// <param name="scale">The text drawing scale. Default is 1.</param>
public static void DrawText(Font font, MaterialBase customMaterial, string text, Rectangle layoutRect, Color color, TextAlignment horizontalAlignment = TextAlignment.Near, TextAlignment verticalAlignment = TextAlignment.Near, TextWrapping textWrapping = TextWrapping.NoWrap, float baseLinesGapScale = 1.0f, float scale = 1.0f) /// <param name="useFallback">Whether to use fallback fonts for chars not renderable by the font.</param>
public static void DrawText(Font font, MaterialBase customMaterial, string text, Rectangle layoutRect, Color color, TextAlignment horizontalAlignment = TextAlignment.Near, TextAlignment verticalAlignment = TextAlignment.Near, TextWrapping textWrapping = TextWrapping.NoWrap, float baseLinesGapScale = 1.0f, float scale = 1.0f, bool useFallback = true)
{ {
var layout = new TextLayoutOptions var layout = new TextLayoutOptions
{ {
@@ -149,63 +165,63 @@ namespace FlaxEngine
Scale = scale, Scale = scale,
BaseLinesGapScale = baseLinesGapScale, BaseLinesGapScale = baseLinesGapScale,
}; };
DrawText(font, text, color, ref layout, customMaterial);
if (useFallback && Fallbacks != null)
{
DrawText(font, Fallbacks, text, color, ref layout, customMaterial);
}
else
{
DrawText(font, text, color, ref layout, customMaterial);
}
} }
/// <summary> public static Float2 MeasureText(Font font, string text, bool useFallback = true)
/// Draws a text.
/// </summary>
/// <param name="fonts">The fonts to use, ordered by priority.</param>
/// <param name="text">The text to render.</param>
/// <param name="layoutRect">The size and position of the area in which the text is drawn.</param>
/// <param name="color">The text color.</param>
/// <param name="horizontalAlignment">The horizontal alignment of the text in a layout rectangle.</param>
/// <param name="verticalAlignment">The vertical alignment of the text in a layout rectangle.</param>
/// <param name="textWrapping">Describes how wrap text inside a layout rectangle.</param>
/// <param name="baseLinesGapScale">The scale for distance one baseline from another. Default is 1.</param>
/// <param name="scale">The text drawing scale. Default is 1.</param>
public static void DrawText(MultiFont fonts, string text, Rectangle layoutRect, Color color, TextAlignment horizontalAlignment = TextAlignment.Near, TextAlignment verticalAlignment = TextAlignment.Near, TextWrapping textWrapping = TextWrapping.NoWrap, float baseLinesGapScale = 1.0f, float scale = 1.0f)
{ {
var layout = new TextLayoutOptions if (useFallback && Fallbacks != null)
{ {
Bounds = layoutRect, return font.MeasureText(Style.Current.Fallbacks, text);
HorizontalAlignment = horizontalAlignment, }
VerticalAlignment = verticalAlignment, else
TextWrapping = textWrapping, {
Scale = scale, return font.MeasureText(text);
BaseLinesGapScale = baseLinesGapScale, }
};
DrawText(fonts, text, color, ref layout);
} }
/// <summary> public static Float2 MeasureText(Font font, string text, ref TextRange textRange, bool useFallback = true)
/// Draws a text using a custom material shader. Given material must have GUI domain and a public parameter named Font (texture parameter used for a font atlas sampling).
/// </summary>
/// <param name="fonts">The fonts to use, ordered by priority.</param>
/// <param name="customMaterial">Custom material for font characters rendering. It must contain texture parameter named Font used to sample font texture.</param>
/// <param name="text">The text to render.</param>
/// <param name="layoutRect">The size and position of the area in which the text is drawn.</param>
/// <param name="color">The text color.</param>
/// <param name="horizontalAlignment">The horizontal alignment of the text in a layout rectangle.</param>
/// <param name="verticalAlignment">The vertical alignment of the text in a layout rectangle.</param>
/// <param name="textWrapping">Describes how wrap text inside a layout rectangle.</param>
/// <param name="baseLinesGapScale">The scale for distance one baseline from another. Default is 1.</param>
/// <param name="scale">The text drawing scale. Default is 1.</param>
public static void DrawText(MultiFont fonts, MaterialBase customMaterial, string text, Rectangle layoutRect, Color color, TextAlignment horizontalAlignment = TextAlignment.Near, TextAlignment verticalAlignment = TextAlignment.Near, TextWrapping textWrapping = TextWrapping.NoWrap, float baseLinesGapScale = 1.0f, float scale = 1.0f)
{ {
var layout = new TextLayoutOptions if (useFallback && Fallbacks != null)
{ {
Bounds = layoutRect, return font.MeasureText(Style.Current.Fallbacks, text, ref textRange);
HorizontalAlignment = horizontalAlignment, }
VerticalAlignment = verticalAlignment, else
TextWrapping = textWrapping, {
Scale = scale, return font.MeasureText(text, ref textRange);
BaseLinesGapScale = baseLinesGapScale, }
}; }
DrawText(fonts, text, color, ref layout, customMaterial); public static Float2 MeasureText(Font font, string text, ref TextLayoutOptions layout, bool useFallback = true)
{
if (useFallback && Fallbacks != null)
{
return font.MeasureText(Style.Current.Fallbacks, text, ref layout);
}
else
{
return font.MeasureText(text, ref layout);
}
}
public static Float2 MeasureText(Font font, string text, ref TextRange textRange, ref TextLayoutOptions layout, bool useFallback = true)
{
if (useFallback && Fallbacks != null)
{
return font.MeasureText(Style.Current.Fallbacks, text, ref textRange, ref layout);
}
else
{
return font.MeasureText(text, ref textRange, ref layout);
}
} }
/// <summary> /// <summary>

View File

@@ -294,12 +294,12 @@ namespace FlaxEngine
style.DragWindow = style.BackgroundSelected * 0.7f; style.DragWindow = style.BackgroundSelected * 0.7f;
// Use optionally bundled default font (matches Editor) // Use optionally bundled default font (matches Editor)
FontAsset[] defaultFont = [Content.LoadAsyncInternal<FontAsset>("Editor/Fonts/Roboto-Regular"), Content.LoadAsyncInternal<FontAsset>("Editor/Fonts/NotoSansSC-Regular")]; FontAsset defaultFont = Content.LoadAsyncInternal<FontAsset>("Editor/Fonts/Roboto-Regular");
style.FontTitle = new MultiFontReference(defaultFont, 18).GetMultiFont(); style.FontTitle = new FontReference(defaultFont, 18).GetFont();
style.FontLarge = new MultiFontReference(defaultFont, 14).GetMultiFont(); style.FontLarge = new FontReference(defaultFont, 14).GetFont();
style.FontMedium = new MultiFontReference(defaultFont, 9).GetMultiFont(); style.FontMedium = new FontReference(defaultFont, 9).GetFont();
style.FontSmall = new MultiFontReference(defaultFont, 9).GetMultiFont(); style.FontSmall = new FontReference(defaultFont, 9).GetFont();
Style.Current = style; Style.Current = style;
} }

View File

@@ -23,7 +23,7 @@ namespace FlaxEngine.GUI
/// <summary> /// <summary>
/// The font. /// The font.
/// </summary> /// </summary>
protected MultiFontReference _font; protected FontReference _font;
/// <summary> /// <summary>
/// The text. /// The text.
@@ -44,7 +44,7 @@ namespace FlaxEngine.GUI
/// Gets or sets the font used to draw button text. /// Gets or sets the font used to draw button text.
/// </summary> /// </summary>
[EditorDisplay("Text Style"), EditorOrder(2022), ExpandGroups] [EditorDisplay("Text Style"), EditorOrder(2022), ExpandGroups]
public MultiFontReference Font public FontReference Font
{ {
get => _font; get => _font;
set => _font = value; set => _font = value;
@@ -156,7 +156,7 @@ namespace FlaxEngine.GUI
var style = Style.Current; var style = Style.Current;
if (style != null) if (style != null)
{ {
_font = new MultiFontReference(style.FontMedium); _font = new FontReference(style.FontMedium);
TextColor = style.Foreground; TextColor = style.Foreground;
BackgroundColor = style.BackgroundNormal; BackgroundColor = style.BackgroundNormal;
BorderColor = style.BorderNormal; BorderColor = style.BorderNormal;
@@ -262,7 +262,7 @@ namespace FlaxEngine.GUI
Render2D.DrawRectangle(clientRect, borderColor, BorderThickness); Render2D.DrawRectangle(clientRect, borderColor, BorderThickness);
// Draw text // Draw text
Render2D.DrawText(_font?.GetMultiFont(), TextMaterial, _text, clientRect, textColor, TextAlignment.Center, TextAlignment.Center); Render2D.DrawText(_font?.GetFont(), TextMaterial, _text, clientRect, textColor, TextAlignment.Center, TextAlignment.Center);
} }
/// <inheritdoc /> /// <inheritdoc />

View File

@@ -278,7 +278,7 @@ namespace FlaxEngine.GUI
/// Gets or sets the font used to draw text. /// Gets or sets the font used to draw text.
/// </summary> /// </summary>
[EditorDisplay("Text Style"), EditorOrder(2021)] [EditorDisplay("Text Style"), EditorOrder(2021)]
public MultiFontReference Font { get; set; } public FontReference Font { get; set; }
/// <summary> /// <summary>
/// Gets or sets the custom material used to render the text. It must has domain set to GUI and have a public texture parameter named Font used to sample font atlas texture with font characters data. /// Gets or sets the custom material used to render the text. It must has domain set to GUI and have a public texture parameter named Font used to sample font atlas texture with font characters data.
@@ -359,7 +359,7 @@ namespace FlaxEngine.GUI
: base(0, 0, 120, 18.0f) : base(0, 0, 120, 18.0f)
{ {
var style = Style.Current; var style = Style.Current;
Font = new MultiFontReference(style.FontMedium); Font = new FontReference(style.FontMedium);
TextColor = style.Foreground; TextColor = style.Foreground;
BackgroundColor = style.BackgroundNormal; BackgroundColor = style.BackgroundNormal;
BackgroundColorHighlighted = BackgroundColor; BackgroundColorHighlighted = BackgroundColor;
@@ -476,7 +476,7 @@ namespace FlaxEngine.GUI
var font = Font.GetFont(); var font = Font.GetFont();
for (int i = 0; i < _items.Count; i++) for (int i = 0; i < _items.Count; i++)
{ {
itemsWidth = Mathf.Max(itemsWidth, itemsMargin + 4 + font.MeasureText(_items[i]).X); itemsWidth = Mathf.Max(itemsWidth, itemsMargin + 4 + Render2D.MeasureText(font, _items[i]).X);
} }
*/ */
var itemsWidth = Width; var itemsWidth = Width;
@@ -674,7 +674,7 @@ namespace FlaxEngine.GUI
var textRect = new Rectangle(margin, 0, clientRect.Width - boxSize - 2.0f * margin, clientRect.Height); var textRect = new Rectangle(margin, 0, clientRect.Width - boxSize - 2.0f * margin, clientRect.Height);
Render2D.PushClip(textRect); Render2D.PushClip(textRect);
var textColor = TextColor; var textColor = TextColor;
Render2D.DrawText(Font.GetMultiFont(), FontMaterial, _items[_selectedIndex], textRect, enabled ? textColor : textColor * 0.5f, TextAlignment.Near, TextAlignment.Center); Render2D.DrawText(Font.GetFont(), FontMaterial, _items[_selectedIndex], textRect, enabled ? textColor : textColor * 0.5f, TextAlignment.Near, TextAlignment.Center);
Render2D.PopClip(); Render2D.PopClip();
} }

View File

@@ -26,7 +26,7 @@ namespace FlaxEngine.GUI
/// <summary> /// <summary>
/// The font. /// The font.
/// </summary> /// </summary>
protected MultiFontReference _font; protected FontReference _font;
/// <summary> /// <summary>
/// Gets or sets the text. /// Gets or sets the text.
@@ -86,7 +86,7 @@ namespace FlaxEngine.GUI
/// Gets or sets the font. /// Gets or sets the font.
/// </summary> /// </summary>
[EditorDisplay("Text Style"), EditorOrder(2024)] [EditorDisplay("Text Style"), EditorOrder(2024)]
public MultiFontReference Font public FontReference Font
{ {
get => _font; get => _font;
set set
@@ -192,7 +192,7 @@ namespace FlaxEngine.GUI
{ {
AutoFocus = false; AutoFocus = false;
var style = Style.Current; var style = Style.Current;
Font = new MultiFontReference(style.FontMedium); Font = new FontReference(style.FontMedium);
TextColor = style.Foreground; TextColor = style.Foreground;
TextColorHighlighted = style.Foreground; TextColorHighlighted = style.Foreground;
} }
@@ -203,7 +203,7 @@ namespace FlaxEngine.GUI
{ {
AutoFocus = false; AutoFocus = false;
var style = Style.Current; var style = Style.Current;
Font = new MultiFontReference(style.FontMedium); Font = new FontReference(style.FontMedium);
TextColor = style.Foreground; TextColor = style.Foreground;
TextColorHighlighted = style.Foreground; TextColorHighlighted = style.Foreground;
} }
@@ -235,7 +235,7 @@ namespace FlaxEngine.GUI
} }
} }
Render2D.DrawText(_font.GetMultiFont(), Material, _text, rect, color, hAlignment, wAlignment, Wrapping, BaseLinesGapScale, scale); Render2D.DrawText(_font.GetFont(), Material, _text, rect, color, hAlignment, wAlignment, Wrapping, BaseLinesGapScale, scale);
if (ClipText) if (ClipText)
Render2D.PopClip(); Render2D.PopClip();
@@ -246,7 +246,7 @@ namespace FlaxEngine.GUI
{ {
if (_autoWidth || _autoHeight || _autoFitText) if (_autoWidth || _autoHeight || _autoFitText)
{ {
var font = _font.GetMultiFont(); var font = _font.GetFont();
if (font) if (font)
{ {
// Calculate text size // Calculate text size
@@ -256,7 +256,7 @@ namespace FlaxEngine.GUI
layout.Bounds.Size.X = Width - Margin.Width; layout.Bounds.Size.X = Width - Margin.Width;
else if (_autoWidth && !_autoHeight) else if (_autoWidth && !_autoHeight)
layout.Bounds.Size.Y = Height - Margin.Height; layout.Bounds.Size.Y = Height - Margin.Height;
_textSize = font.MeasureText(_text, ref layout); _textSize = Render2D.MeasureText(font, _text, ref layout);
_textSize.Y *= BaseLinesGapScale; _textSize.Y *= BaseLinesGapScale;
// Check if size is controlled via text // Check if size is controlled via text

View File

@@ -46,7 +46,7 @@ namespace FlaxEngine.GUI
var style = Style.Current; var style = Style.Current;
_textStyle = new TextBlockStyle _textStyle = new TextBlockStyle
{ {
Font = new FontReference(style.FontMedium.Fonts.First()), Font = new FontReference(style.FontMedium),
Color = style.Foreground, Color = style.Foreground,
BackgroundSelectedBrush = new SolidColorBrush(style.BackgroundSelected), BackgroundSelectedBrush = new SolidColorBrush(style.BackgroundSelected),
}; };

View File

@@ -1,5 +1,6 @@
// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved. // Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
using System.Drawing;
using System.Linq; using System.Linq;
namespace FlaxEngine.GUI namespace FlaxEngine.GUI
@@ -40,7 +41,7 @@ namespace FlaxEngine.GUI
/// Gets or sets the font. /// Gets or sets the font.
/// </summary> /// </summary>
[EditorDisplay("Text Style"), EditorOrder(2024)] [EditorDisplay("Text Style"), EditorOrder(2024)]
public MultiFontReference Font { get; set; } public FontReference Font { get; set; }
/// <summary> /// <summary>
/// Gets or sets the custom material used to render the text. It must has domain set to GUI and have a public texture parameter named Font used to sample font atlas texture with font characters data. /// Gets or sets the custom material used to render the text. It must has domain set to GUI and have a public texture parameter named Font used to sample font atlas texture with font characters data.
@@ -90,7 +91,7 @@ namespace FlaxEngine.GUI
_layout.Bounds = new Rectangle(DefaultMargin, 1, Width - 2 * DefaultMargin, Height - 2); _layout.Bounds = new Rectangle(DefaultMargin, 1, Width - 2 * DefaultMargin, Height - 2);
var style = Style.Current; var style = Style.Current;
Font = new MultiFontReference(style.FontMedium); Font = new FontReference(style.FontMedium);
TextColor = style.Foreground; TextColor = style.Foreground;
WatermarkTextColor = style.ForegroundDisabled; WatermarkTextColor = style.ForegroundDisabled;
SelectionColor = style.BackgroundSelected; SelectionColor = style.BackgroundSelected;
@@ -99,33 +100,33 @@ namespace FlaxEngine.GUI
/// <inheritdoc /> /// <inheritdoc />
public override Float2 GetTextSize() public override Float2 GetTextSize()
{ {
var font = Font.GetMultiFont(); var font = Font.GetFont();
if (font == null) if (font == null)
{ {
return Float2.Zero; return Float2.Zero;
} }
return font.MeasureText(_text, ref _layout); return Render2D.MeasureText(font, _text, ref _layout);
} }
/// <inheritdoc /> /// <inheritdoc />
public override Float2 GetCharPosition(int index, out float height) public override Float2 GetCharPosition(int index, out float height)
{ {
var font = Font.GetMultiFont(); var font = Font.GetFont();
if (font == null) if (font == null)
{ {
height = Height; height = Height;
return Float2.Zero; return Float2.Zero;
} }
height = font.MaxHeight / DpiScale; height = font.Height / DpiScale;
return font.GetCharPosition(_text, index, ref _layout); return font.GetCharPosition(_text, index, ref _layout);
} }
/// <inheritdoc /> /// <inheritdoc />
public override int HitTestText(Float2 location) public override int HitTestText(Float2 location)
{ {
var font = Font.GetMultiFont(); var font = Font.GetFont();
if (font == null) if (font == null)
{ {
return 0; return 0;
@@ -148,7 +149,7 @@ namespace FlaxEngine.GUI
// Cache data // Cache data
var rect = new Rectangle(Float2.Zero, Size); var rect = new Rectangle(Float2.Zero, Size);
bool enabled = EnabledInHierarchy; bool enabled = EnabledInHierarchy;
var font = Font.GetMultiFont(); var font = Font.GetFont();
if (!font) if (!font)
return; return;
@@ -172,7 +173,7 @@ namespace FlaxEngine.GUI
{ {
var leftEdge = font.GetCharPosition(_text, SelectionLeft, ref _layout); var leftEdge = font.GetCharPosition(_text, SelectionLeft, ref _layout);
var rightEdge = font.GetCharPosition(_text, SelectionRight, ref _layout); var rightEdge = font.GetCharPosition(_text, SelectionRight, ref _layout);
float fontHeight = font.MaxHeight / DpiScale; float fontHeight = font.Height / DpiScale;
// Draw selection background // Draw selection background
float alpha = Mathf.Min(1.0f, Mathf.Cos(_animateTime * BackgroundSelectedFlashSpeed) * 0.5f + 1.3f); float alpha = Mathf.Min(1.0f, Mathf.Cos(_animateTime * BackgroundSelectedFlashSpeed) * 0.5f + 1.3f);
@@ -212,11 +213,25 @@ namespace FlaxEngine.GUI
var color = TextColor; var color = TextColor;
if (!enabled) if (!enabled)
color *= 0.6f; color *= 0.6f;
Render2D.DrawText(font, _text, color, ref _layout, TextMaterial); if (Render2D.Fallbacks != null)
{
Render2D.DrawText(font, Render2D.Fallbacks, _text, color, ref _layout, TextMaterial);
}
else
{
Render2D.DrawText(font, _text, color, ref _layout, TextMaterial);
}
} }
else if (!string.IsNullOrEmpty(_watermarkText) && !IsFocused) else if (!string.IsNullOrEmpty(_watermarkText) && !IsFocused)
{ {
Render2D.DrawText(font, _watermarkText, WatermarkTextColor, ref _layout, TextMaterial); if (Render2D.Fallbacks != null)
{
Render2D.DrawText(font, Render2D.Fallbacks, _watermarkText, WatermarkTextColor, ref _layout, TextMaterial);
}
else
{
Render2D.DrawText(font, _watermarkText, WatermarkTextColor, ref _layout, TextMaterial);
}
} }
// Caret // Caret

View File

@@ -130,7 +130,7 @@ namespace FlaxEngine.GUI
/// Gets or sets the font used to render panel header text. /// Gets or sets the font used to render panel header text.
/// </summary> /// </summary>
[EditorDisplay("Header Text Style"), EditorOrder(2020), ExpandGroups] [EditorDisplay("Header Text Style"), EditorOrder(2020), ExpandGroups]
public MultiFontReference HeaderTextFont { get; set; } public FontReference HeaderTextFont { get; set; }
/// <summary> /// <summary>
/// Gets or sets the custom material used to render the text. It must has domain set to GUI and have a public texture parameter named Font used to sample font atlas texture with font characters data. /// Gets or sets the custom material used to render the text. It must has domain set to GUI and have a public texture parameter named Font used to sample font atlas texture with font characters data.
@@ -238,7 +238,7 @@ namespace FlaxEngine.GUI
var style = Style.Current; var style = Style.Current;
HeaderColor = style.BackgroundNormal; HeaderColor = style.BackgroundNormal;
HeaderColorMouseOver = style.BackgroundHighlighted; HeaderColorMouseOver = style.BackgroundHighlighted;
HeaderTextFont = new MultiFontReference(style.FontMedium); HeaderTextFont = new FontReference(style.FontMedium);
HeaderTextColor = style.Foreground; HeaderTextColor = style.Foreground;
ArrowImageOpened = new SpriteBrush(style.ArrowDown); ArrowImageOpened = new SpriteBrush(style.ArrowDown);
ArrowImageClosed = new SpriteBrush(style.ArrowRight); ArrowImageClosed = new SpriteBrush(style.ArrowRight);
@@ -375,7 +375,7 @@ namespace FlaxEngine.GUI
textColor *= 0.6f; textColor *= 0.6f;
} }
Render2D.DrawText(HeaderTextFont.GetMultiFont(), HeaderTextMaterial, HeaderText, textRect, textColor, TextAlignment.Near, TextAlignment.Center); Render2D.DrawText(HeaderTextFont.GetFont(), HeaderTextMaterial, HeaderText, textRect, textColor, TextAlignment.Near, TextAlignment.Center);
if (!_isClosed && EnableContainmentLines) if (!_isClosed && EnableContainmentLines)
{ {

View File

@@ -15,61 +15,67 @@ namespace FlaxEngine.GUI
public static Style Current { get; set; } public static Style Current { get; set; }
[Serialize] [Serialize]
private MultiFontReference _fontTitle; private FontReference _fontTitle;
/// <summary> /// <summary>
/// The font title. /// The font title.
/// </summary> /// </summary>
[NoSerialize] [NoSerialize]
[EditorOrder(10)] [EditorOrder(10)]
public MultiFont FontTitle public Font FontTitle
{ {
get => _fontTitle?.GetMultiFont(); get => _fontTitle?.GetFont();
set => _fontTitle = new MultiFontReference(value); set => _fontTitle = new FontReference(value);
} }
[Serialize] [Serialize]
private MultiFontReference _fontLarge; private FontReference _fontLarge;
/// <summary> /// <summary>
/// The font large. /// The font large.
/// </summary> /// </summary>
[NoSerialize] [NoSerialize]
[EditorOrder(20)] [EditorOrder(20)]
public MultiFont FontLarge public Font FontLarge
{ {
get => _fontLarge?.GetMultiFont(); get => _fontLarge?.GetFont();
set => _fontLarge = new MultiFontReference(value); set => _fontLarge = new FontReference(value);
} }
[Serialize] [Serialize]
private MultiFontReference _fontMedium; private FontReference _fontMedium;
/// <summary> /// <summary>
/// The font medium. /// The font medium.
/// </summary> /// </summary>
[NoSerialize] [NoSerialize]
[EditorOrder(30)] [EditorOrder(30)]
public MultiFont FontMedium public Font FontMedium
{ {
get => _fontMedium?.GetMultiFont(); get => _fontMedium?.GetFont();
set => _fontMedium = new MultiFontReference(value); set => _fontMedium = new FontReference(value);
} }
[Serialize] [Serialize]
private MultiFontReference _fontSmall; private FontReference _fontSmall;
/// <summary> /// <summary>
/// The font small. /// The font small.
/// </summary> /// </summary>
[NoSerialize] [NoSerialize]
[EditorOrder(40)] [EditorOrder(40)]
public MultiFont FontSmall public Font FontSmall
{ {
get => _fontSmall?.GetMultiFont(); get => _fontSmall?.GetFont();
set => _fontSmall = new MultiFontReference(value); set => _fontSmall = new FontReference(value);
} }
/// <summary>
/// The fallback fonts to use if the primary font can't render the char.
/// </summary>
[EditorOrder(50)]
public FallbackFonts Fallbacks;
/// <summary> /// <summary>
/// The background color. /// The background color.
/// </summary> /// </summary>