Add fallback settings to CSharp
This commit is contained in:
@@ -23,7 +23,7 @@ namespace FlaxEngine.GUI
|
||||
/// <summary>
|
||||
/// The font.
|
||||
/// </summary>
|
||||
protected MultiFontReference _font;
|
||||
protected FontReference _font;
|
||||
|
||||
/// <summary>
|
||||
/// The text.
|
||||
@@ -44,7 +44,7 @@ namespace FlaxEngine.GUI
|
||||
/// Gets or sets the font used to draw button text.
|
||||
/// </summary>
|
||||
[EditorDisplay("Text Style"), EditorOrder(2022), ExpandGroups]
|
||||
public MultiFontReference Font
|
||||
public FontReference Font
|
||||
{
|
||||
get => _font;
|
||||
set => _font = value;
|
||||
@@ -156,7 +156,7 @@ namespace FlaxEngine.GUI
|
||||
var style = Style.Current;
|
||||
if (style != null)
|
||||
{
|
||||
_font = new MultiFontReference(style.FontMedium);
|
||||
_font = new FontReference(style.FontMedium);
|
||||
TextColor = style.Foreground;
|
||||
BackgroundColor = style.BackgroundNormal;
|
||||
BorderColor = style.BorderNormal;
|
||||
@@ -262,7 +262,7 @@ namespace FlaxEngine.GUI
|
||||
Render2D.DrawRectangle(clientRect, borderColor, BorderThickness);
|
||||
|
||||
// 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 />
|
||||
|
||||
@@ -278,7 +278,7 @@ namespace FlaxEngine.GUI
|
||||
/// Gets or sets the font used to draw text.
|
||||
/// </summary>
|
||||
[EditorDisplay("Text Style"), EditorOrder(2021)]
|
||||
public MultiFontReference Font { get; set; }
|
||||
public FontReference Font { get; set; }
|
||||
|
||||
/// <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.
|
||||
@@ -359,7 +359,7 @@ namespace FlaxEngine.GUI
|
||||
: base(0, 0, 120, 18.0f)
|
||||
{
|
||||
var style = Style.Current;
|
||||
Font = new MultiFontReference(style.FontMedium);
|
||||
Font = new FontReference(style.FontMedium);
|
||||
TextColor = style.Foreground;
|
||||
BackgroundColor = style.BackgroundNormal;
|
||||
BackgroundColorHighlighted = BackgroundColor;
|
||||
@@ -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 + font.MeasureText(_items[i]).X);
|
||||
itemsWidth = Mathf.Max(itemsWidth, itemsMargin + 4 + Render2D.MeasureText(font, _items[i]).X);
|
||||
}
|
||||
*/
|
||||
var itemsWidth = Width;
|
||||
@@ -674,7 +674,7 @@ namespace FlaxEngine.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(), 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();
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace FlaxEngine.GUI
|
||||
/// <summary>
|
||||
/// The font.
|
||||
/// </summary>
|
||||
protected MultiFontReference _font;
|
||||
protected FontReference _font;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the text.
|
||||
@@ -86,7 +86,7 @@ namespace FlaxEngine.GUI
|
||||
/// Gets or sets the font.
|
||||
/// </summary>
|
||||
[EditorDisplay("Text Style"), EditorOrder(2024)]
|
||||
public MultiFontReference Font
|
||||
public FontReference Font
|
||||
{
|
||||
get => _font;
|
||||
set
|
||||
@@ -192,7 +192,7 @@ namespace FlaxEngine.GUI
|
||||
{
|
||||
AutoFocus = false;
|
||||
var style = Style.Current;
|
||||
Font = new MultiFontReference(style.FontMedium);
|
||||
Font = new FontReference(style.FontMedium);
|
||||
TextColor = style.Foreground;
|
||||
TextColorHighlighted = style.Foreground;
|
||||
}
|
||||
@@ -203,7 +203,7 @@ namespace FlaxEngine.GUI
|
||||
{
|
||||
AutoFocus = false;
|
||||
var style = Style.Current;
|
||||
Font = new MultiFontReference(style.FontMedium);
|
||||
Font = new FontReference(style.FontMedium);
|
||||
TextColor = 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)
|
||||
Render2D.PopClip();
|
||||
@@ -246,7 +246,7 @@ namespace FlaxEngine.GUI
|
||||
{
|
||||
if (_autoWidth || _autoHeight || _autoFitText)
|
||||
{
|
||||
var font = _font.GetMultiFont();
|
||||
var font = _font.GetFont();
|
||||
if (font)
|
||||
{
|
||||
// Calculate text size
|
||||
@@ -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 = font.MeasureText(_text, ref layout);
|
||||
_textSize = Render2D.MeasureText(font, _text, ref layout);
|
||||
_textSize.Y *= BaseLinesGapScale;
|
||||
|
||||
// Check if size is controlled via text
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace FlaxEngine.GUI
|
||||
var style = Style.Current;
|
||||
_textStyle = new TextBlockStyle
|
||||
{
|
||||
Font = new FontReference(style.FontMedium.Fonts.First()),
|
||||
Font = new FontReference(style.FontMedium),
|
||||
Color = style.Foreground,
|
||||
BackgroundSelectedBrush = new SolidColorBrush(style.BackgroundSelected),
|
||||
};
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
|
||||
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
|
||||
namespace FlaxEngine.GUI
|
||||
@@ -40,7 +41,7 @@ namespace FlaxEngine.GUI
|
||||
/// Gets or sets the font.
|
||||
/// </summary>
|
||||
[EditorDisplay("Text Style"), EditorOrder(2024)]
|
||||
public MultiFontReference Font { get; set; }
|
||||
public FontReference Font { get; set; }
|
||||
|
||||
/// <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.
|
||||
@@ -90,7 +91,7 @@ namespace FlaxEngine.GUI
|
||||
_layout.Bounds = new Rectangle(DefaultMargin, 1, Width - 2 * DefaultMargin, Height - 2);
|
||||
|
||||
var style = Style.Current;
|
||||
Font = new MultiFontReference(style.FontMedium);
|
||||
Font = new FontReference(style.FontMedium);
|
||||
TextColor = style.Foreground;
|
||||
WatermarkTextColor = style.ForegroundDisabled;
|
||||
SelectionColor = style.BackgroundSelected;
|
||||
@@ -99,33 +100,33 @@ namespace FlaxEngine.GUI
|
||||
/// <inheritdoc />
|
||||
public override Float2 GetTextSize()
|
||||
{
|
||||
var font = Font.GetMultiFont();
|
||||
var font = Font.GetFont();
|
||||
if (font == null)
|
||||
{
|
||||
return Float2.Zero;
|
||||
}
|
||||
|
||||
return font.MeasureText(_text, ref _layout);
|
||||
return Render2D.MeasureText(font, _text, ref _layout);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override Float2 GetCharPosition(int index, out float height)
|
||||
{
|
||||
var font = Font.GetMultiFont();
|
||||
var font = Font.GetFont();
|
||||
if (font == null)
|
||||
{
|
||||
height = Height;
|
||||
return Float2.Zero;
|
||||
}
|
||||
|
||||
height = font.MaxHeight / DpiScale;
|
||||
height = font.Height / DpiScale;
|
||||
return font.GetCharPosition(_text, index, ref _layout);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override int HitTestText(Float2 location)
|
||||
{
|
||||
var font = Font.GetMultiFont();
|
||||
var font = Font.GetFont();
|
||||
if (font == null)
|
||||
{
|
||||
return 0;
|
||||
@@ -148,7 +149,7 @@ namespace FlaxEngine.GUI
|
||||
// Cache data
|
||||
var rect = new Rectangle(Float2.Zero, Size);
|
||||
bool enabled = EnabledInHierarchy;
|
||||
var font = Font.GetMultiFont();
|
||||
var font = Font.GetFont();
|
||||
if (!font)
|
||||
return;
|
||||
|
||||
@@ -172,7 +173,7 @@ namespace FlaxEngine.GUI
|
||||
{
|
||||
var leftEdge = font.GetCharPosition(_text, SelectionLeft, ref _layout);
|
||||
var rightEdge = font.GetCharPosition(_text, SelectionRight, ref _layout);
|
||||
float fontHeight = font.MaxHeight / DpiScale;
|
||||
float fontHeight = font.Height / DpiScale;
|
||||
|
||||
// Draw selection background
|
||||
float alpha = Mathf.Min(1.0f, Mathf.Cos(_animateTime * BackgroundSelectedFlashSpeed) * 0.5f + 1.3f);
|
||||
@@ -212,11 +213,25 @@ namespace FlaxEngine.GUI
|
||||
var color = TextColor;
|
||||
if (!enabled)
|
||||
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)
|
||||
{
|
||||
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
|
||||
|
||||
@@ -130,7 +130,7 @@ namespace FlaxEngine.GUI
|
||||
/// Gets or sets the font used to render panel header text.
|
||||
/// </summary>
|
||||
[EditorDisplay("Header Text Style"), EditorOrder(2020), ExpandGroups]
|
||||
public MultiFontReference HeaderTextFont { get; set; }
|
||||
public FontReference HeaderTextFont { get; set; }
|
||||
|
||||
/// <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.
|
||||
@@ -238,7 +238,7 @@ namespace FlaxEngine.GUI
|
||||
var style = Style.Current;
|
||||
HeaderColor = style.BackgroundNormal;
|
||||
HeaderColorMouseOver = style.BackgroundHighlighted;
|
||||
HeaderTextFont = new MultiFontReference(style.FontMedium);
|
||||
HeaderTextFont = new FontReference(style.FontMedium);
|
||||
HeaderTextColor = style.Foreground;
|
||||
ArrowImageOpened = new SpriteBrush(style.ArrowDown);
|
||||
ArrowImageClosed = new SpriteBrush(style.ArrowRight);
|
||||
@@ -375,7 +375,7 @@ namespace FlaxEngine.GUI
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -15,61 +15,67 @@ namespace FlaxEngine.GUI
|
||||
public static Style Current { get; set; }
|
||||
|
||||
[Serialize]
|
||||
private MultiFontReference _fontTitle;
|
||||
private FontReference _fontTitle;
|
||||
|
||||
/// <summary>
|
||||
/// The font title.
|
||||
/// </summary>
|
||||
[NoSerialize]
|
||||
[EditorOrder(10)]
|
||||
public MultiFont FontTitle
|
||||
public Font FontTitle
|
||||
{
|
||||
get => _fontTitle?.GetMultiFont();
|
||||
set => _fontTitle = new MultiFontReference(value);
|
||||
get => _fontTitle?.GetFont();
|
||||
set => _fontTitle = new FontReference(value);
|
||||
}
|
||||
|
||||
[Serialize]
|
||||
private MultiFontReference _fontLarge;
|
||||
private FontReference _fontLarge;
|
||||
|
||||
/// <summary>
|
||||
/// The font large.
|
||||
/// </summary>
|
||||
[NoSerialize]
|
||||
[EditorOrder(20)]
|
||||
public MultiFont FontLarge
|
||||
public Font FontLarge
|
||||
{
|
||||
get => _fontLarge?.GetMultiFont();
|
||||
set => _fontLarge = new MultiFontReference(value);
|
||||
get => _fontLarge?.GetFont();
|
||||
set => _fontLarge = new FontReference(value);
|
||||
}
|
||||
|
||||
[Serialize]
|
||||
private MultiFontReference _fontMedium;
|
||||
private FontReference _fontMedium;
|
||||
|
||||
/// <summary>
|
||||
/// The font medium.
|
||||
/// </summary>
|
||||
[NoSerialize]
|
||||
[EditorOrder(30)]
|
||||
public MultiFont FontMedium
|
||||
public Font FontMedium
|
||||
{
|
||||
get => _fontMedium?.GetMultiFont();
|
||||
set => _fontMedium = new MultiFontReference(value);
|
||||
get => _fontMedium?.GetFont();
|
||||
set => _fontMedium = new FontReference(value);
|
||||
}
|
||||
|
||||
[Serialize]
|
||||
private MultiFontReference _fontSmall;
|
||||
private FontReference _fontSmall;
|
||||
|
||||
/// <summary>
|
||||
/// The font small.
|
||||
/// </summary>
|
||||
[NoSerialize]
|
||||
[EditorOrder(40)]
|
||||
public MultiFont FontSmall
|
||||
public Font FontSmall
|
||||
{
|
||||
get => _fontSmall?.GetMultiFont();
|
||||
set => _fontSmall = new MultiFontReference(value);
|
||||
get => _fontSmall?.GetFont();
|
||||
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>
|
||||
/// The background color.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user