Add font fallback

Note: All the `First()` in the code are temperary workarounds to make it work and require refractoring
This commit is contained in:
ExMatics HydrogenC
2023-11-28 07:17:46 +08:00
parent b3a18883ca
commit 47a25c7828
47 changed files with 787 additions and 87 deletions

View File

@@ -273,7 +273,7 @@ namespace FlaxEditor.GUI
MaximumItemsInViewCount = 20;
var style = Style.Current;
Font = new FontReference(style.FontMedium);
Font = new FontReference(style.FontMedium.First());
TextColor = style.Foreground;
BackgroundColor = style.BackgroundNormal;
BackgroundColorHighlighted = BackgroundColor;

View File

@@ -1,6 +1,7 @@
// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
using System;
using System.Linq;
using FlaxEngine;
using FlaxEngine.GUI;
@@ -233,11 +234,11 @@ namespace FlaxEditor.GUI.ContextMenu
{
var style = Style.Current;
float width = 20;
if (style.FontMedium)
if (style.FontMedium.First())
{
width += style.FontMedium.MeasureText(Text).X;
width += style.FontMedium.First().MeasureText(Text).X;
if (!string.IsNullOrEmpty(ShortKeys))
width += 40 + style.FontMedium.MeasureText(ShortKeys).X;
width += 40 + style.FontMedium.First().MeasureText(ShortKeys).X;
}
return Mathf.Max(width, base.MinimumWidth);

View File

@@ -437,7 +437,7 @@ namespace FlaxEditor.GUI
_contentsColor = style.Background.RGBMultiplied(0.7f);
_linesColor = style.ForegroundDisabled.RGBMultiplied(0.7f);
_labelsColor = style.ForegroundDisabled;
_labelsFont = style.FontSmall;
_labelsFont = style.FontSmall.First();
_mainPanel = new Panel(ScrollBars.Both)
{

View File

@@ -6,6 +6,7 @@ using FlaxEngine;
using FlaxEngine.Assertions;
using FlaxEngine.GUI;
using FlaxEditor.Options;
using System.Linq;
namespace FlaxEditor.GUI.Docking
{
@@ -488,7 +489,7 @@ namespace FlaxEditor.GUI.Docking
{
var style = Style.Current;
if (style?.FontMedium != null)
_titleSize = style.FontMedium.MeasureText(_title);
_titleSize = style.FontMedium.First().MeasureText(_title);
}
base.PerformLayoutBeforeChildren();

View File

@@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using FlaxEditor.GUI.ContextMenu;
using FlaxEditor.GUI.Input;
using FlaxEditor.Utilities;
@@ -86,8 +87,8 @@ namespace FlaxEditor.GUI
var font = style.FontSmall;
for (int i = 0; i < ranges.Length; i++)
{
var start = font.GetCharPosition(Name, ranges[i].StartIndex);
var end = font.GetCharPosition(Name, ranges[i].EndIndex);
var start = font.First().GetCharPosition(Name, ranges[i].StartIndex);
var end = font.First().GetCharPosition(Name, ranges[i].EndIndex);
_highlights.Add(new Rectangle(start.X + 2, 0, end.X - start.X, Height));
}
Visible = true;

View File

@@ -2,6 +2,7 @@
using FlaxEngine;
using FlaxEngine.GUI;
using System.Linq;
namespace FlaxEditor.GUI
{
@@ -101,8 +102,8 @@ namespace FlaxEditor.GUI
var style = Style.Current;
float width = 18;
if (style.FontMedium)
width += style.FontMedium.MeasureText(Text).X;
if (style.FontMedium.First())
width += style.FontMedium.First().MeasureText(Text).X;
Width = width;
}

View File

@@ -2,6 +2,7 @@
using FlaxEngine;
using FlaxEngine.GUI;
using System.Linq;
namespace FlaxEditor.GUI
{
@@ -65,9 +66,9 @@ namespace FlaxEditor.GUI
{
var style = Style.Current;
if (style.FontMedium)
if (style.FontMedium.First())
{
Width = style.FontMedium.MeasureText(Text).X + 2 * DefaultMargin;
Width = style.FontMedium.First().MeasureText(Text).X + 2 * DefaultMargin;
}
}
}

View File

@@ -1,6 +1,7 @@
// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
using System;
using System.Linq;
using FlaxEngine;
using FlaxEngine.GUI;
@@ -38,8 +39,8 @@ namespace FlaxEditor.GUI
{
Depth = -1;
if (Height < Style.Current.FontMedium.Height)
Height = Style.Current.FontMedium.Height + 4;
if (Height < Style.Current.FontMedium.First().Height)
Height = Style.Current.FontMedium.First().Height + 4;
}
/// <inheritdoc />

View File

@@ -1,6 +1,7 @@
// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
using System;
using System.Linq;
using System.Runtime.CompilerServices;
using FlaxEngine;
using FlaxEngine.GUI;
@@ -129,7 +130,7 @@ namespace FlaxEditor.GUI
Render2D.FillRectangle(rect, column.TitleBackgroundColor);
var style = Style.Current;
var font = column.TitleFont ?? style.FontMedium;
var font = column.TitleFont ?? style.FontMedium.First();
Render2D.DrawText(font, column.Title, rect, column.TitleColor, TextAlignment.Center, TextAlignment.Center);
if (columnIndex < _columns.Length - 1)

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 + Style.Current.FontSmall.First().MeasureText(Title ?? Name).X;
if (Icon.IsValid)
left += 18;
if (IsExpanded)

View File

@@ -1,6 +1,7 @@
// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
using System;
using System.Linq;
using FlaxEngine;
using FlaxEngine.GUI;
@@ -150,8 +151,8 @@ namespace FlaxEditor.GUI
if (hasSprite)
width += iconSize;
if (!string.IsNullOrEmpty(_text) && style.FontMedium)
width += style.FontMedium.MeasureText(_text).X + (hasSprite ? DefaultMargin : 0);
if (!string.IsNullOrEmpty(_text) && style.FontMedium.First())
width += style.FontMedium.First().MeasureText(_text).X + (hasSprite ? DefaultMargin : 0);
Width = width;
}

View File

@@ -1,6 +1,7 @@
// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
using System;
using System.Linq;
using FlaxEngine;
using FlaxEngine.GUI;
@@ -317,7 +318,7 @@ namespace FlaxEditor.GUI.Tree
BackgroundColorSelected = style.BackgroundSelected;
BackgroundColorHighlighted = style.BackgroundHighlighted;
BackgroundColorSelectedUnfocused = style.LightBackground;
TextFont = new FontReference(style.FontSmall);
TextFont = new FontReference(style.FontSmall.First());
}
/// <summary>