diff --git a/Source/Editor/CustomEditors/Dedicated/ScriptsEditor.cs b/Source/Editor/CustomEditors/Dedicated/ScriptsEditor.cs
index 90ae9ae54..ab949508e 100644
--- a/Source/Editor/CustomEditors/Dedicated/ScriptsEditor.cs
+++ b/Source/Editor/CustomEditors/Dedicated/ScriptsEditor.cs
@@ -43,7 +43,7 @@ namespace FlaxEditor.CustomEditors.Dedicated
// Add script button
var buttonText = "Add script";
- var textSize = Render2D.MeasureText(Style.Current.FontMedium, buttonText);
+ var textSize = FallbackTextUtils.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
diff --git a/Source/Editor/CustomEditors/Dedicated/UIControlEditor.cs b/Source/Editor/CustomEditors/Dedicated/UIControlEditor.cs
index b8250918f..4efbee259 100644
--- a/Source/Editor/CustomEditors/Dedicated/UIControlEditor.cs
+++ b/Source/Editor/CustomEditors/Dedicated/UIControlEditor.cs
@@ -423,7 +423,7 @@ namespace FlaxEditor.CustomEditors.Dedicated
// Set control type button
var space = layout.Space(20);
var buttonText = "Set Type";
- var textSize = Render2D.MeasureText(FlaxEngine.GUI.Style.Current.FontMedium, buttonText);
+ var textSize = FallbackTextUtils.MeasureText(FlaxEngine.GUI.Style.Current.FontMedium, buttonText);
float setTypeButtonWidth = (textSize.X < 60.0f) ? 60.0f : textSize.X + 4;
var setTypeButton = new Button
{
diff --git a/Source/Editor/CustomEditors/Editors/ActorTransformEditor.cs b/Source/Editor/CustomEditors/Editors/ActorTransformEditor.cs
index e84bf5914..8889a765a 100644
--- a/Source/Editor/CustomEditors/Editors/ActorTransformEditor.cs
+++ b/Source/Editor/CustomEditors/Editors/ActorTransformEditor.cs
@@ -101,7 +101,7 @@ namespace FlaxEditor.CustomEditors.Editors
_linkButton.Clicked += ToggleLink;
ToggleEnabled();
SetLinkStyle();
- var textSize = Render2D.MeasureText(FlaxEngine.GUI.Style.Current.FontMedium, LinkedLabel.Text.Value);
+ var textSize = FallbackTextUtils.MeasureText(FlaxEngine.GUI.Style.Current.FontMedium, LinkedLabel.Text.Value);
_linkButton.LocalX += textSize.X + 10;
LinkedLabel.SetupContextMenu += (label, menu, editor) =>
{
diff --git a/Source/Editor/CustomEditors/Editors/TagEditor.cs b/Source/Editor/CustomEditors/Editors/TagEditor.cs
index 49ac9d937..bbece7e04 100644
--- a/Source/Editor/CustomEditors/Editors/TagEditor.cs
+++ b/Source/Editor/CustomEditors/Editors/TagEditor.cs
@@ -631,7 +631,7 @@ namespace FlaxEditor.CustomEditors.Editors
TooltipText = "Edit...",
Parent = _label,
};
- var textSize = Render2D.MeasureText(FlaxEngine.GUI.Style.Current.FontMedium, buttonText);
+ var textSize = FallbackTextUtils.MeasureText(FlaxEngine.GUI.Style.Current.FontMedium, buttonText);
if (textSize.Y > button.Width)
button.Width = textSize.Y + 2;
diff --git a/Source/Editor/GUI/ContextMenu/ContextMenuButton.cs b/Source/Editor/GUI/ContextMenu/ContextMenuButton.cs
index 3137de240..d8c492e46 100644
--- a/Source/Editor/GUI/ContextMenu/ContextMenuButton.cs
+++ b/Source/Editor/GUI/ContextMenu/ContextMenuButton.cs
@@ -236,9 +236,9 @@ namespace FlaxEditor.GUI.ContextMenu
float width = 20;
if (style.FontMedium)
{
- width += Render2D.MeasureText(style.FontMedium, Text).X;
+ width += FallbackTextUtils.MeasureText(style.FontMedium, Text).X;
if (!string.IsNullOrEmpty(ShortKeys))
- width += 40 + Render2D.MeasureText(style.FontMedium, ShortKeys).X;
+ width += 40 + FallbackTextUtils.MeasureText(style.FontMedium, ShortKeys).X;
}
return Mathf.Max(width, base.MinimumWidth);
diff --git a/Source/Editor/GUI/Docking/DockWindow.cs b/Source/Editor/GUI/Docking/DockWindow.cs
index 36a4c112e..b7c12287f 100644
--- a/Source/Editor/GUI/Docking/DockWindow.cs
+++ b/Source/Editor/GUI/Docking/DockWindow.cs
@@ -489,7 +489,7 @@ namespace FlaxEditor.GUI.Docking
{
var style = Style.Current;
if (style?.FontMedium != null)
- _titleSize = Render2D.MeasureText(style.FontMedium, _title);
+ _titleSize = FallbackTextUtils.MeasureText(style.FontMedium, _title);
}
base.PerformLayoutBeforeChildren();
diff --git a/Source/Editor/GUI/MainMenuButton.cs b/Source/Editor/GUI/MainMenuButton.cs
index 3440996aa..6fe8b98d3 100644
--- a/Source/Editor/GUI/MainMenuButton.cs
+++ b/Source/Editor/GUI/MainMenuButton.cs
@@ -103,7 +103,7 @@ namespace FlaxEditor.GUI
float width = 18;
if (style.FontMedium)
- width += Render2D.MeasureText(style.FontMedium, Text).X;
+ width += FallbackTextUtils.MeasureText(style.FontMedium, Text).X;
Width = width;
}
diff --git a/Source/Editor/GUI/NavigationButton.cs b/Source/Editor/GUI/NavigationButton.cs
index 6face21ef..5d399da02 100644
--- a/Source/Editor/GUI/NavigationButton.cs
+++ b/Source/Editor/GUI/NavigationButton.cs
@@ -68,7 +68,7 @@ namespace FlaxEditor.GUI
if (style.FontMedium)
{
- Width = Render2D.MeasureText(style.FontMedium, Text).X + 2 * DefaultMargin;
+ Width = FallbackTextUtils.MeasureText(style.FontMedium, Text).X + 2 * DefaultMargin;
}
}
}
diff --git a/Source/Editor/GUI/Timeline/Tracks/MemberTrack.cs b/Source/Editor/GUI/Timeline/Tracks/MemberTrack.cs
index b4433622e..dd79922ac 100644
--- a/Source/Editor/GUI/Timeline/Tracks/MemberTrack.cs
+++ b/Source/Editor/GUI/Timeline/Tracks/MemberTrack.cs
@@ -345,7 +345,7 @@ namespace FlaxEditor.GUI.Timeline.Tracks
if (_previewValue != null)
{
// Based on Track.Draw for track text placement
- var left = _xOffset + 16 + Render2D.MeasureText(Style.Current.FontSmall, Title ?? Name).X;
+ var left = _xOffset + 16 + FallbackTextUtils.MeasureText(Style.Current.FontSmall, Title ?? Name).X;
if (Icon.IsValid)
left += 18;
if (IsExpanded)
diff --git a/Source/Editor/GUI/ToolStripButton.cs b/Source/Editor/GUI/ToolStripButton.cs
index cf34fd36b..50dce78b4 100644
--- a/Source/Editor/GUI/ToolStripButton.cs
+++ b/Source/Editor/GUI/ToolStripButton.cs
@@ -152,7 +152,7 @@ namespace FlaxEditor.GUI
if (hasSprite)
width += iconSize;
if (!string.IsNullOrEmpty(_text) && style.FontMedium)
- width += Render2D.MeasureText(style.FontMedium, _text).X + (hasSprite ? DefaultMargin : 0);
+ width += FallbackTextUtils.MeasureText(style.FontMedium, _text).X + (hasSprite ? DefaultMargin : 0);
Width = width;
}
diff --git a/Source/Editor/GUI/Tree/TreeNode.cs b/Source/Editor/GUI/Tree/TreeNode.cs
index 7b47e5eb6..700ba6da1 100644
--- a/Source/Editor/GUI/Tree/TreeNode.cs
+++ b/Source/Editor/GUI/Tree/TreeNode.cs
@@ -576,7 +576,7 @@ namespace FlaxEditor.GUI.Tree
var font = TextFont.GetFont();
if (font)
{
- _textWidth = Render2D.MeasureText(font, _text).X;
+ _textWidth = FallbackTextUtils.MeasureText(font, _text).X;
_textChanged = false;
}
}
diff --git a/Source/Editor/Surface/Archetypes/Animation.StateMachine.cs b/Source/Editor/Surface/Archetypes/Animation.StateMachine.cs
index 19a995b1e..078b89c56 100644
--- a/Source/Editor/Surface/Archetypes/Animation.StateMachine.cs
+++ b/Source/Editor/Surface/Archetypes/Animation.StateMachine.cs
@@ -337,7 +337,7 @@ namespace FlaxEditor.Surface.Archetypes
_textRect = new Rectangle(Float2.Zero, Size);
var style = Style.Current;
- var titleSize = Render2D.MeasureText(style.FontLarge, Title);
+ var titleSize = FallbackTextUtils.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 = Render2D.MeasureText(style.FontLarge, Title);
+ var titleSize = FallbackTextUtils.MeasureText(style.FontLarge, Title);
var width = Mathf.Max(100, titleSize.X + 50);
Resize(width, 0);
titleSize.X += 8.0f;
diff --git a/Source/Editor/Surface/Archetypes/Animation.cs b/Source/Editor/Surface/Archetypes/Animation.cs
index dcf4a9689..dae16b425 100644
--- a/Source/Editor/Surface/Archetypes/Animation.cs
+++ b/Source/Editor/Surface/Archetypes/Animation.cs
@@ -77,7 +77,7 @@ namespace FlaxEditor.Surface.Archetypes
Title = asset?.ShortName ?? "Animation";
var style = Style.Current;
- Resize(Mathf.Max(230, Render2D.MeasureText(style.FontLarge, Title).X + 30), 160);
+ Resize(Mathf.Max(230, FallbackTextUtils.MeasureText(style.FontLarge, Title).X + 30), 160);
}
///
diff --git a/Source/Editor/Surface/Archetypes/BehaviorTree.cs b/Source/Editor/Surface/Archetypes/BehaviorTree.cs
index 364dfa1ef..5f3c0b0a2 100644
--- a/Source/Editor/Surface/Archetypes/BehaviorTree.cs
+++ b/Source/Editor/Surface/Archetypes/BehaviorTree.cs
@@ -101,7 +101,7 @@ namespace FlaxEditor.Surface.Archetypes
_debugRelevant = Behavior.GetNodeDebugRelevancy(instance, behavior);
_debugInfo = Behavior.GetNodeDebugInfo(instance, behavior);
if (!string.IsNullOrEmpty(_debugInfo))
- _debugInfoSize = Render2D.MeasureText(Style.Current.FontSmall, _debugInfo);
+ _debugInfoSize = FallbackTextUtils.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, Render2D.MeasureText(titleLabelFont, Title).X + 30);
+ width = Mathf.Max(width, FallbackTextUtils.MeasureText(titleLabelFont, Title).X + 30);
if (_debugInfoSize.X > 0)
{
width = Mathf.Max(width, _debugInfoSize.X + 8.0f);
diff --git a/Source/Editor/Surface/ContextMenu/VisjectCMItem.cs b/Source/Editor/Surface/ContextMenu/VisjectCMItem.cs
index fd9f0c63b..019be78b6 100644
--- a/Source/Editor/Surface/ContextMenu/VisjectCMItem.cs
+++ b/Source/Editor/Surface/ContextMenu/VisjectCMItem.cs
@@ -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 = Render2D.MeasureText(style.FontSmall, _archetype.Title).X;
+ var titleLength = FallbackTextUtils.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);
}
diff --git a/Source/Editor/Surface/Elements/InputBox.cs b/Source/Editor/Surface/Elements/InputBox.cs
index 2ab286bd9..526d85d15 100644
--- a/Source/Editor/Surface/Elements/InputBox.cs
+++ b/Source/Editor/Surface/Elements/InputBox.cs
@@ -1428,7 +1428,7 @@ namespace FlaxEditor.Surface.Elements
if (_defaultValueEditor != null)
{
- _defaultValueEditor.Location = new Float2(X + Width + 8 + Render2D.MeasureText(Style.Current.FontSmall, Text).X, Y);
+ _defaultValueEditor.Location = new Float2(X + Width + 8 + FallbackTextUtils.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 + Render2D.MeasureText(Style.Current.FontSmall, Text).X, Y, 90, Height);
+ var bounds = new Rectangle(X + Width + 8 + FallbackTextUtils.MeasureText(Style.Current.FontSmall, Text).X, Y, 90, Height);
_editor = DefaultValueEditors[i];
try
{
diff --git a/Source/Editor/Surface/SurfaceNode.cs b/Source/Editor/Surface/SurfaceNode.cs
index 60d776102..3c2381192 100644
--- a/Source/Editor/Surface/SurfaceNode.cs
+++ b/Source/Editor/Surface/SurfaceNode.cs
@@ -200,7 +200,7 @@ namespace FlaxEditor.Surface
continue;
if (child is InputBox inputBox)
{
- var boxWidth = Render2D.MeasureText(boxLabelFont, inputBox.Text).X + 20;
+ var boxWidth = FallbackTextUtils.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, Render2D.MeasureText(boxLabelFont, outputBox.Text).X + 20);
+ rightWidth = Mathf.Max(rightWidth, FallbackTextUtils.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, Render2D.MeasureText(titleLabelFont, Title).X + 30);
+ width = Mathf.Max(width, FallbackTextUtils.MeasureText(titleLabelFont, Title).X + 30);
height = Mathf.Max(height, Mathf.Max(leftHeight, rightHeight));
Resize(width, height);
}
diff --git a/Source/Editor/Tools/Foliage/FoliageTab.cs b/Source/Editor/Tools/Foliage/FoliageTab.cs
index 58cf6f204..c2b1fbe68 100644
--- a/Source/Editor/Tools/Foliage/FoliageTab.cs
+++ b/Source/Editor/Tools/Foliage/FoliageTab.cs
@@ -148,7 +148,7 @@ namespace FlaxEditor.Tools.Foliage
Parent = _noFoliagePanel,
Enabled = false
};
- var textSize = Render2D.MeasureText(Style.Current.FontMedium, buttonText);
+ var textSize = FallbackTextUtils.MeasureText(Style.Current.FontMedium, buttonText);
if (_createNewFoliage.Width < textSize.X)
{
_createNewFoliage.LocalX -= (textSize.X - _createNewFoliage.Width) / 2;
diff --git a/Source/Editor/Tools/Terrain/CarveTab.cs b/Source/Editor/Tools/Terrain/CarveTab.cs
index 12c9fd148..0a86aab6f 100644
--- a/Source/Editor/Tools/Terrain/CarveTab.cs
+++ b/Source/Editor/Tools/Terrain/CarveTab.cs
@@ -106,7 +106,7 @@ namespace FlaxEditor.Tools.Terrain
Parent = _noTerrainPanel,
Enabled = false
};
- var textSize = Render2D.MeasureText(Style.Current.FontMedium, buttonText);
+ var textSize = FallbackTextUtils.MeasureText(Style.Current.FontMedium, buttonText);
if (_createTerrainButton.Width < textSize.X)
{
_createTerrainButton.LocalX -= (textSize.X - _createTerrainButton.Width) / 2;
diff --git a/Source/Editor/Utilities/TextRenderUtils.cs b/Source/Editor/Utilities/TextRenderUtils.cs
deleted file mode 100644
index d7b79ae81..000000000
--- a/Source/Editor/Utilities/TextRenderUtils.cs
+++ /dev/null
@@ -1,108 +0,0 @@
-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
- {
- ///
- /// Draws a text using the global fallback defined in styles.
- ///
- /// The font to use.
- /// The text to render.
- /// The size and position of the area in which the text is drawn.
- /// The text color.
- /// The horizontal alignment of the text in a layout rectangle.
- /// The vertical alignment of the text in a layout rectangle.
- /// Describes how wrap text inside a layout rectangle.
- /// The scale for distance one baseline from another. Default is 1.
- /// The text drawing scale. Default is 1.
- 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);
- }
-
- ///
- /// 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).
- ///
- /// The font to use.
- /// Custom material for font characters rendering. It must contain texture parameter named Font used to sample font texture.
- /// The text to render.
- /// The size and position of the area in which the text is drawn.
- /// The text color.
- /// The horizontal alignment of the text in a layout rectangle.
- /// The vertical alignment of the text in a layout rectangle.
- /// Describes how wrap text inside a layout rectangle.
- /// The scale for distance one baseline from another. Default is 1.
- /// The text drawing scale. Default is 1.
- 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);
- }
- }
-}
diff --git a/Source/Editor/Viewport/EditorViewport.cs b/Source/Editor/Viewport/EditorViewport.cs
index 77a677c0c..0633d0ba9 100644
--- a/Source/Editor/Viewport/EditorViewport.cs
+++ b/Source/Editor/Viewport/EditorViewport.cs
@@ -548,9 +548,9 @@ namespace FlaxEditor.Viewport
#region Camera settings widget
var largestText = "Relative Panning";
- var textSize = Render2D.MeasureText(Style.Current.FontMedium, largestText);
+ var textSize = FallbackTextUtils.MeasureText(Style.Current.FontMedium, largestText);
var xLocationForExtras = textSize.X + 5;
- var cameraSpeedTextWidth = Render2D.MeasureText(Style.Current.FontMedium, "0.00").X;
+ var cameraSpeedTextWidth = FallbackTextUtils.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 = Render2D.MeasureText(Style.Current.FontMedium, largestText);
+ textSize = FallbackTextUtils.MeasureText(Style.Current.FontMedium, largestText);
xLocationForExtras = textSize.X + 5;
var viewMode = new ViewportWidgetsContainer(ViewportWidgetLocation.UpperLeft);
diff --git a/Source/Editor/Viewport/Widgets/ViewportWidgetButton.cs b/Source/Editor/Viewport/Widgets/ViewportWidgetButton.cs
index 250790621..598f4ee32 100644
--- a/Source/Editor/Viewport/Widgets/ViewportWidgetButton.cs
+++ b/Source/Editor/Viewport/Widgets/ViewportWidgetButton.cs
@@ -164,7 +164,7 @@ namespace FlaxEditor.Viewport.Widgets
var style = Style.Current;
if (style != null && style.FontMedium)
- Width = CalculateButtonWidth(_forcedTextWidth > 0.0f ? _forcedTextWidth : Render2D.MeasureText(style.FontMedium, _text).X, Icon.IsValid);
+ Width = CalculateButtonWidth(_forcedTextWidth > 0.0f ? _forcedTextWidth : FallbackTextUtils.MeasureText(style.FontMedium, _text).X, Icon.IsValid);
}
}
}
diff --git a/Source/Editor/Windows/AboutDialog.cs b/Source/Editor/Windows/AboutDialog.cs
index ac887dadf..02aad16ec 100644
--- a/Source/Editor/Windows/AboutDialog.cs
+++ b/Source/Editor/Windows/AboutDialog.cs
@@ -54,7 +54,7 @@ namespace FlaxEditor.Windows
Parent = this
};
var buttonText = "Copy version info";
- var fontSize = Render2D.MeasureText(Style.Current.FontMedium, buttonText);
+ var fontSize = FallbackTextUtils.MeasureText(Style.Current.FontMedium, buttonText);
var copyVersionButton = new Button(Width - fontSize.X - 8, 6, fontSize.X + 4, 20)
{
Text = buttonText,
diff --git a/Source/Editor/Windows/PluginsWindow.cs b/Source/Editor/Windows/PluginsWindow.cs
index 4dfa0ed08..03beab2fa 100644
--- a/Source/Editor/Windows/PluginsWindow.cs
+++ b/Source/Editor/Windows/PluginsWindow.cs
@@ -122,7 +122,7 @@ namespace FlaxEditor.Windows
url = desc.RepositoryUrl;
versionLabel.Font.Font.WaitForLoaded();
var font = versionLabel.Font.GetFont();
- var authorWidth = Render2D.MeasureText(font, desc.Author).X + 8;
+ var authorWidth = FallbackTextUtils.MeasureText(font, desc.Author).X + 8;
var authorLabel = new ClickableLabel
{
HorizontalAlignment = TextAlignment.Far,
diff --git a/Source/Editor/Windows/Profiler/Timeline.cs b/Source/Editor/Windows/Profiler/Timeline.cs
index 00365f74a..780b31a3b 100644
--- a/Source/Editor/Windows/Profiler/Timeline.cs
+++ b/Source/Editor/Windows/Profiler/Timeline.cs
@@ -86,7 +86,7 @@ namespace FlaxEditor.Windows.Profiler
Render2D.DrawRectangle(bounds, color * 0.5f);
if (_nameLength < 0 && style.FontMedium)
- _nameLength = Render2D.MeasureText(style.FontMedium, _name).X;
+ _nameLength = FallbackTextUtils.MeasureText(style.FontMedium, _name).X;
if (_nameLength < bounds.Width + 4)
{
diff --git a/Source/Engine/Render2D/FallbackTextUtils.cs b/Source/Engine/Render2D/FallbackTextUtils.cs
new file mode 100644
index 000000000..eb676f0a9
--- /dev/null
+++ b/Source/Engine/Render2D/FallbackTextUtils.cs
@@ -0,0 +1,126 @@
+
+namespace FlaxEngine
+{
+ ///
+ /// A collection of functions to handle text rendering with fallback font
+ ///
+ public static class FallbackTextUtils
+ {
+ public static FallbackFonts Fallbacks
+ {
+ get; set;
+ } = null;
+
+ 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)
+ {
+ var layout = new TextLayoutOptions
+ {
+ Bounds = layoutRect,
+ HorizontalAlignment = horizontalAlignment,
+ VerticalAlignment = verticalAlignment,
+ TextWrapping = textWrapping,
+ Scale = scale,
+ BaseLinesGapScale = baseLinesGapScale,
+ };
+
+ if (Fallbacks != null)
+ {
+ Render2D.DrawText(font, Fallbacks, text, color, ref layout);
+ }
+ else
+ {
+ Render2D.DrawText(font, text, color, ref layout);
+ }
+ }
+
+ 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)
+ {
+ var layout = new TextLayoutOptions
+ {
+ Bounds = layoutRect,
+ HorizontalAlignment = horizontalAlignment,
+ VerticalAlignment = verticalAlignment,
+ TextWrapping = textWrapping,
+ Scale = scale,
+ BaseLinesGapScale = baseLinesGapScale,
+ };
+
+ if (Fallbacks != null)
+ {
+ Render2D.DrawText(font, Fallbacks, text, color, ref layout, customMaterial);
+ }
+ else
+ {
+ Render2D.DrawText(font, text, color, ref layout, customMaterial);
+ }
+ }
+
+ public static Float2 MeasureText(Font font, string text)
+ {
+ if (Fallbacks != null)
+ {
+ return font.MeasureText(Fallbacks, text);
+ }
+ else
+ {
+ return font.MeasureText(text);
+ }
+ }
+
+ public static Float2 MeasureText(Font font, string text, ref TextRange textRange)
+ {
+ if (Fallbacks != null)
+ {
+ return font.MeasureText(Fallbacks, text, ref textRange);
+ }
+ else
+ {
+ return font.MeasureText(text, ref textRange);
+ }
+ }
+
+ public static Float2 MeasureText(Font font, string text, ref TextLayoutOptions layout)
+ {
+ if (Fallbacks != null)
+ {
+ return font.MeasureText(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)
+ {
+ if (Fallbacks != null)
+ {
+ return font.MeasureText(Fallbacks, text, ref textRange, ref layout);
+ }
+ else
+ {
+ return font.MeasureText(text, ref textRange, ref layout);
+ }
+ }
+
+ public static Float2 GetCharPosition(Font font, string text, int index)
+ {
+ return font.GetCharPosition(Style.Current.Fallbacks, text, index);
+ }
+
+ public static Float2 GetCharPosition(Font font, string text, ref TextRange textRange, int index)
+ {
+ return font.GetCharPosition(Style.Current.Fallbacks, text, ref textRange, index);
+ }
+
+ public static Float2 GetCharPosition(Font font, string text, int index, ref TextLayoutOptions layout)
+ {
+ return font.GetCharPosition(Style.Current.Fallbacks, text, index, ref layout);
+ }
+
+ public static Float2 GetCharPosition(Font font, string text, ref TextRange textRange, int index, ref TextLayoutOptions layout)
+ {
+ return font.GetCharPosition(Style.Current.Fallbacks, text, ref textRange, index, ref layout);
+ }
+ }
+}
diff --git a/Source/Engine/Render2D/Render2D.cs b/Source/Engine/Render2D/Render2D.cs
index b7158ccc7..6e4f1dc1d 100644
--- a/Source/Engine/Render2D/Render2D.cs
+++ b/Source/Engine/Render2D/Render2D.cs
@@ -7,10 +7,6 @@ namespace FlaxEngine
{
partial class Render2D
{
- public static FallbackFonts Fallbacks
- {
- get; set;
- } = null;
///
/// Pushes transformation layer.
@@ -117,8 +113,7 @@ namespace FlaxEngine
/// Describes how wrap text inside a layout rectangle.
/// The scale for distance one baseline from another. Default is 1.
/// The text drawing scale. Default is 1.
- /// Whether to use fallback fonts for chars not renderable by the font.
- 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)
+ 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)
{
var layout = new TextLayoutOptions
{
@@ -129,15 +124,7 @@ namespace FlaxEngine
Scale = scale,
BaseLinesGapScale = baseLinesGapScale,
};
-
- if (useFallback && Fallbacks != null)
- {
- DrawText(font, Fallbacks, text, color, ref layout);
- }
- else
- {
- DrawText(font, text, color, ref layout);
- }
+ DrawText(font, text, color, ref layout);
}
///
@@ -153,8 +140,7 @@ namespace FlaxEngine
/// Describes how wrap text inside a layout rectangle.
/// The scale for distance one baseline from another. Default is 1.
/// The text drawing scale. Default is 1.
- /// Whether to use fallback fonts for chars not renderable by the font.
- 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)
+ 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)
{
var layout = new TextLayoutOptions
{
@@ -165,63 +151,7 @@ namespace FlaxEngine
Scale = scale,
BaseLinesGapScale = baseLinesGapScale,
};
-
- if (useFallback && Fallbacks != null)
- {
- DrawText(font, Fallbacks, text, color, ref layout, customMaterial);
- }
- else
- {
- DrawText(font, text, color, ref layout, customMaterial);
- }
- }
-
- public static Float2 MeasureText(Font font, string text, bool useFallback = true)
- {
- if (useFallback && Fallbacks != null)
- {
- return font.MeasureText(Style.Current.Fallbacks, text);
- }
- else
- {
- return font.MeasureText(text);
- }
- }
-
- public static Float2 MeasureText(Font font, string text, ref TextRange textRange, bool useFallback = true)
- {
- if (useFallback && Fallbacks != null)
- {
- return font.MeasureText(Style.Current.Fallbacks, text, ref textRange);
- }
- else
- {
- return font.MeasureText(text, ref textRange);
- }
- }
-
- 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);
- }
+ DrawText(font, text, color, ref layout, customMaterial);
}
///
diff --git a/Source/Engine/UI/GUI/Common/Dropdown.cs b/Source/Engine/UI/GUI/Common/Dropdown.cs
index c9fef131c..46f05f516 100644
--- a/Source/Engine/UI/GUI/Common/Dropdown.cs
+++ b/Source/Engine/UI/GUI/Common/Dropdown.cs
@@ -476,7 +476,7 @@ namespace FlaxEngine.GUI
var font = Font.GetFont();
for (int i = 0; i < _items.Count; i++)
{
- itemsWidth = Mathf.Max(itemsWidth, itemsMargin + 4 + Render2D.MeasureText(font, _items[i]).X);
+ itemsWidth = Mathf.Max(itemsWidth, itemsMargin + 4 + FallbackTextUtils.MeasureText(font, _items[i]).X);
}
*/
var itemsWidth = Width;
diff --git a/Source/Engine/UI/GUI/Common/Label.cs b/Source/Engine/UI/GUI/Common/Label.cs
index d7147d3ab..4e26c1934 100644
--- a/Source/Engine/UI/GUI/Common/Label.cs
+++ b/Source/Engine/UI/GUI/Common/Label.cs
@@ -256,7 +256,7 @@ namespace FlaxEngine.GUI
layout.Bounds.Size.X = Width - Margin.Width;
else if (_autoWidth && !_autoHeight)
layout.Bounds.Size.Y = Height - Margin.Height;
- _textSize = Render2D.MeasureText(font, _text, ref layout);
+ _textSize = FallbackTextUtils.MeasureText(font, _text, ref layout);
_textSize.Y *= BaseLinesGapScale;
// Check if size is controlled via text
diff --git a/Source/Engine/UI/GUI/Common/TextBox.cs b/Source/Engine/UI/GUI/Common/TextBox.cs
index a32f3a76c..ea7523f48 100644
--- a/Source/Engine/UI/GUI/Common/TextBox.cs
+++ b/Source/Engine/UI/GUI/Common/TextBox.cs
@@ -106,7 +106,7 @@ namespace FlaxEngine.GUI
return Float2.Zero;
}
- return Render2D.MeasureText(font, _text, ref _layout);
+ return FallbackTextUtils.MeasureText(font, _text, ref _layout);
}
///