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,
Offsets = new Margin(0, 0, 0, 40),
Parent = this,
Font = new MultiFontReference(Style.Current.FontTitle)
Font = new FontReference(Style.Current.FontTitle)
};
var infoLabel = new Label
{

View File

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

View File

@@ -81,7 +81,7 @@ namespace FlaxEditor.CustomEditors.Dedicated
// Title
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",
Parent = this
};

View File

@@ -43,7 +43,7 @@ namespace FlaxEditor.CustomEditors.Dedicated
// Add script button
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;
var buttonHeight = (textSize.Y < 18) ? 18 : textSize.Y + 4;
_addScriptsButton = new Button

View File

@@ -239,7 +239,7 @@ namespace FlaxEditor.CustomEditors.Dedicated
// Title
var title = new Label(2, 2, DialogWidth - 4, TitleHeight)
{
Font = new MultiFontReference(style.FontLarge),
Font = new FontReference(style.FontLarge),
Text = "Anchor Presets",
Parent = this
};
@@ -247,7 +247,7 @@ namespace FlaxEditor.CustomEditors.Dedicated
// Info
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",
Parent = this
};
@@ -423,7 +423,7 @@ namespace FlaxEditor.CustomEditors.Dedicated
// Set control type button
var space = layout.Space(20);
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;
var setTypeButton = new Button
{

View File

@@ -101,7 +101,7 @@ namespace FlaxEditor.CustomEditors.Editors
_linkButton.Clicked += ToggleLink;
ToggleEnabled();
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;
LinkedLabel.SetupContextMenu += (label, menu, editor) =>
{

View File

@@ -631,7 +631,7 @@ namespace FlaxEditor.CustomEditors.Editors
TooltipText = "Edit...",
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)
button.Width = textSize.Y + 2;

View File

@@ -276,7 +276,7 @@ namespace FlaxEditor.CustomEditors
public LabelElement Header(string text)
{
var element = Label(text);
element.Label.Font = new MultiFontReference(Style.Current.FontLarge);
element.Label.Font = new FontReference(Style.Current.FontLarge);
return element;
}
@@ -284,7 +284,7 @@ namespace FlaxEditor.CustomEditors
{
var element = Header(header.Text);
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)
element.Label.TextColor = Color.FromRGBA(header.Color);
return element;

View File

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

View File

@@ -191,7 +191,7 @@ namespace FlaxEditor.GUI
/// Gets or sets the font used to draw text.
/// </summary>
[EditorDisplay("Style"), EditorOrder(2000)]
public MultiFontReference Font { get; set; }
public FontReference Font { get; set; }
/// <summary>
/// Gets or sets the color of the text.
@@ -273,7 +273,7 @@ namespace FlaxEditor.GUI
MaximumItemsInViewCount = 20;
var style = Style.Current;
Font = new MultiFontReference(style.FontMedium);
Font = new FontReference(style.FontMedium);
TextColor = style.Foreground;
BackgroundColor = style.BackgroundNormal;
BackgroundColorHighlighted = BackgroundColor;
@@ -554,7 +554,7 @@ namespace FlaxEditor.GUI
var textRect = new Rectangle(margin, 0, clientRect.Width - boxSize - 2.0f * margin, clientRect.Height);
Render2D.PushClip(textRect);
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();
}

View File

@@ -236,9 +236,9 @@ namespace FlaxEditor.GUI.ContextMenu
float width = 20;
if (style.FontMedium)
{
width += style.FontMedium.MeasureText(Text).X;
width += Render2D.MeasureText(style.FontMedium, Text).X;
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);

View File

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

View File

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

View File

@@ -76,7 +76,7 @@ namespace FlaxEditor.GUI
var windowIcon = FlaxEngine.Content.LoadAsyncInternal<Texture>(EditorAssets.WindowIcon);
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.HitTest += OnHitTest;
@@ -108,7 +108,7 @@ namespace FlaxEditor.GUI
_closeButton = new Button
{
Text = ((char)EditorAssets.SegMDL2Icons.ChromeClose).ToString(),
Font = new MultiFontReference(iconFont),
Font = new FontReference(iconFont),
BackgroundColor = Color.Transparent,
BorderColor = Color.Transparent,
BorderColorHighlighted = Color.Transparent,
@@ -124,7 +124,7 @@ namespace FlaxEditor.GUI
_minimizeButton = new Button
{
Text = ((char)EditorAssets.SegMDL2Icons.ChromeMinimize).ToString(),
Font = new MultiFontReference(iconFont),
Font = new FontReference(iconFont),
BackgroundColor = Color.Transparent,
BorderColor = Color.Transparent,
BorderColorHighlighted = Color.Transparent,
@@ -139,7 +139,7 @@ namespace FlaxEditor.GUI
_maximizeButton = new Button
{
Text = ((char)(_window.IsMaximized ? EditorAssets.SegMDL2Icons.ChromeRestore : EditorAssets.SegMDL2Icons.ChromeMaximize)).ToString(),
Font = new MultiFontReference(iconFont),
Font = new FontReference(iconFont),
BackgroundColor = Color.Transparent,
BorderColor = Color.Transparent,
BorderColorHighlighted = Color.Transparent,

View File

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

View File

@@ -68,7 +68,7 @@ namespace FlaxEditor.GUI
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;
if (Height < Style.Current.FontMedium.MaxHeight)
Height = Style.Current.FontMedium.MaxHeight + 4;
if (Height < Style.Current.FontMedium.Height)
Height = Style.Current.FontMedium.Height + 4;
}
/// <inheritdoc />

View File

@@ -345,7 +345,7 @@ namespace FlaxEditor.GUI.Timeline.Tracks
if (_previewValue != null)
{
// 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)
left += 18;
if (IsExpanded)

View File

@@ -152,7 +152,7 @@ namespace FlaxEditor.GUI
if (hasSprite)
width += iconSize;
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;
}

View File

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

View File

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

View File

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

View File

@@ -337,7 +337,7 @@ namespace FlaxEditor.Surface.Archetypes
_textRect = new Rectangle(Float2.Zero, Size);
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);
Resize(width, 0);
titleSize.X += 8.0f;
@@ -1402,7 +1402,7 @@ namespace FlaxEditor.Surface.Archetypes
{
Title = StateTitle;
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);
Resize(width, 0);
titleSize.X += 8.0f;

View File

@@ -39,7 +39,7 @@ namespace FlaxEditor.Surface.Archetypes
// Title
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,
Parent = this
};

View File

@@ -77,7 +77,7 @@ namespace FlaxEditor.Surface.Archetypes
Title = asset?.ShortName ?? "Animation";
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 />

View File

@@ -101,7 +101,7 @@ namespace FlaxEditor.Surface.Archetypes
_debugRelevant = Behavior.GetNodeDebugRelevancy(instance, behavior);
_debugInfo = Behavior.GetNodeDebugInfo(instance, behavior);
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 titleLabelFont = Style.Current.FontLarge;
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)
{
width = Mathf.Max(width, _debugInfoSize.X + 8.0f);

View File

@@ -1407,7 +1407,7 @@ namespace FlaxEditor.Surface.Archetypes
// Title
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",
Parent = this
};

View File

@@ -83,7 +83,7 @@ namespace FlaxEditor.Surface
// Title
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",
Parent = this
};

View File

@@ -141,7 +141,7 @@ namespace FlaxEditor.Surface.ContextMenu
};
// Title bar
var titleFontReference = new MultiFontReference(Style.Current.FontLarge);
var titleFontReference = new FontReference(Style.Current.FontLarge);
var titleLabel = new Label
{
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);
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);
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)
{
_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))
{
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];
try
{

View File

@@ -200,7 +200,7 @@ namespace FlaxEditor.Surface
continue;
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)
boxWidth += inputBox.DefaultValueEditor.Width + 4;
leftWidth = Mathf.Max(leftWidth, boxWidth);
@@ -208,7 +208,7 @@ namespace FlaxEditor.Surface
}
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);
}
else if (child is Control control)
@@ -226,7 +226,7 @@ namespace FlaxEditor.Surface
}
}
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));
Resize(width, height);
}

View File

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

View File

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

View File

@@ -96,7 +96,7 @@ namespace FlaxEditor.Tools.Terrain
AnchorPreset = AnchorPresets.HorizontalStretchTop,
Offsets = new Margin(0, 0, 0, 40),
Parent = this,
Font = new MultiFontReference(Style.Current.FontTitle)
Font = new FontReference(Style.Current.FontTitle)
};
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
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 cameraSpeedTextWidth = Style.Current.FontMedium.MeasureText("0.00").X;
var cameraSpeedTextWidth = Render2D.MeasureText(Style.Current.FontMedium, "0.00").X;
// Camera Settings Widget
_cameraWidget = new ViewportWidgetsContainer(ViewportWidgetLocation.UpperRight);
@@ -801,7 +801,7 @@ namespace FlaxEditor.Viewport
#region View mode widget
largestText = "Brightness";
textSize = Style.Current.FontMedium.MeasureText(largestText);
textSize = Render2D.MeasureText(Style.Current.FontMedium, largestText);
xLocationForExtras = textSize.X + 5;
var viewMode = new ViewportWidgetsContainer(ViewportWidgetLocation.UpperLeft);

View File

@@ -164,7 +164,7 @@ namespace FlaxEditor.Viewport.Widgets
var style = Style.Current;
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)
{
Text = "Flax Engine",
Font = new MultiFontReference(Style.Current.FontTitle),
Font = new FontReference(Style.Current.FontTitle),
HorizontalAlignment = TextAlignment.Near,
VerticalAlignment = TextAlignment.Center,
Parent = this
@@ -54,7 +54,7 @@ namespace FlaxEditor.Windows
Parent = this
};
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)
{
Text = buttonText,

View File

@@ -144,7 +144,7 @@ namespace FlaxEditor.Windows.Assets
protected override void OnAssetLinked()
{
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);
var options = Asset.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);
Render2D.PushClip(textRect);
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();
// Arrow

View File

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

View File

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