Add fallback settings for control
This commit is contained in:
@@ -182,6 +182,12 @@ namespace FlaxEngine.GUI
|
|||||||
set => _autoFitTextRange = value;
|
set => _autoFitTextRange = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets whether to fallback when the primary font cannot render a char.
|
||||||
|
/// </summary>
|
||||||
|
[EditorOrder(120), DefaultValue(true), Tooltip("Whether to fallback when the font cannot render a char.")]
|
||||||
|
public bool EnableFontFallback { get; set; } = true;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="Label"/> class.
|
/// Initializes a new instance of the <see cref="Label"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -233,7 +239,23 @@ namespace FlaxEngine.GUI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Render2D.DrawText(_font.GetFont(), Material, _text, rect, color, hAlignment, wAlignment, Wrapping, BaseLinesGapScale, scale);
|
if (EnableFontFallback)
|
||||||
|
{
|
||||||
|
Render2D.DrawText(_font.GetFont(), Material, _text, rect, color, hAlignment, wAlignment, Wrapping, BaseLinesGapScale, scale);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var layout = new TextLayoutOptions
|
||||||
|
{
|
||||||
|
Bounds = rect,
|
||||||
|
HorizontalAlignment = hAlignment,
|
||||||
|
VerticalAlignment = wAlignment,
|
||||||
|
TextWrapping = Wrapping,
|
||||||
|
Scale = scale,
|
||||||
|
BaseLinesGapScale = BaseLinesGapScale,
|
||||||
|
};
|
||||||
|
Render2D.DrawTextInternal(_font.GetFont(), _text, color, ref layout, Material);
|
||||||
|
}
|
||||||
|
|
||||||
if (ClipText)
|
if (ClipText)
|
||||||
Render2D.PopClip();
|
Render2D.PopClip();
|
||||||
@@ -254,7 +276,8 @@ 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 = EnableFontFallback ?
|
||||||
|
font.MeasureText(_text, ref layout) : font.MeasureTextInternal(_text, ref layout);
|
||||||
_textSize.Y *= BaseLinesGapScale;
|
_textSize.Y *= BaseLinesGapScale;
|
||||||
|
|
||||||
// Check if size is controlled via text
|
// Check if size is controlled via text
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
|
// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
|
||||||
|
|
||||||
|
|
||||||
|
using System.ComponentModel;
|
||||||
|
|
||||||
namespace FlaxEngine.GUI
|
namespace FlaxEngine.GUI
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -65,6 +67,12 @@ namespace FlaxEngine.GUI
|
|||||||
[EditorDisplay("Text Style"), EditorOrder(2022), Tooltip("The color of the selection (Transparent if not used).")]
|
[EditorDisplay("Text Style"), EditorOrder(2022), Tooltip("The color of the selection (Transparent if not used).")]
|
||||||
public Color SelectionColor { get; set; }
|
public Color SelectionColor { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets whether to fallback when the primary font cannot render a char.
|
||||||
|
/// </summary>
|
||||||
|
[EditorOrder(120), DefaultValue(true), Tooltip("Whether to fallback when the font cannot render a char.")]
|
||||||
|
public bool EnableFontFallback { get; set; } = true;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="TextBox"/> class.
|
/// Initializes a new instance of the <see cref="TextBox"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -104,7 +112,8 @@ namespace FlaxEngine.GUI
|
|||||||
return Float2.Zero;
|
return Float2.Zero;
|
||||||
}
|
}
|
||||||
|
|
||||||
return font.MeasureText(_text, ref _layout);
|
return EnableFontFallback ? font.MeasureText(_text, ref _layout) :
|
||||||
|
font.MeasureTextInternal(_text, ref _layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@@ -117,8 +126,9 @@ namespace FlaxEngine.GUI
|
|||||||
return Float2.Zero;
|
return Float2.Zero;
|
||||||
}
|
}
|
||||||
|
|
||||||
height = font.GetMaxHeight() / DpiScale;
|
height = (EnableFontFallback ? font.GetMaxHeight() : font.Height) / DpiScale;
|
||||||
return font.GetCharPosition(_text, index, ref _layout);
|
return EnableFontFallback ? font.GetCharPosition(_text, index, ref _layout) :
|
||||||
|
font.GetCharPositionInternal(_text, index, ref _layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@@ -130,7 +140,8 @@ namespace FlaxEngine.GUI
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return font.HitTestText(_text, location, ref _layout);
|
return EnableFontFallback ? font.HitTestText(_text, location, ref _layout) :
|
||||||
|
font.HitTestTextInternal(_text, location, ref _layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@@ -169,8 +180,12 @@ namespace FlaxEngine.GUI
|
|||||||
// Check if sth is selected to draw selection
|
// Check if sth is selected to draw selection
|
||||||
if (HasSelection)
|
if (HasSelection)
|
||||||
{
|
{
|
||||||
var leftEdge = font.GetCharPosition(_text, SelectionLeft, ref _layout);
|
var leftEdge = EnableFontFallback ?
|
||||||
var rightEdge = font.GetCharPosition(_text, SelectionRight, ref _layout);
|
font.GetCharPosition(_text, SelectionLeft, ref _layout) :
|
||||||
|
font.GetCharPositionInternal(_text, SelectionLeft, ref _layout);
|
||||||
|
var rightEdge = EnableFontFallback ?
|
||||||
|
font.GetCharPosition(_text, SelectionRight, ref _layout) :
|
||||||
|
font.GetCharPositionInternal(_text, SelectionRight, ref _layout);
|
||||||
float fontHeight = font.GetMaxHeight() / DpiScale;
|
float fontHeight = font.GetMaxHeight() / DpiScale;
|
||||||
|
|
||||||
// Draw selection background
|
// Draw selection background
|
||||||
@@ -211,11 +226,19 @@ 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 (EnableFontFallback)
|
||||||
|
Render2D.DrawText(font, _text, color, ref _layout, TextMaterial);
|
||||||
|
else
|
||||||
|
// Draw without fallback
|
||||||
|
Render2D.DrawTextInternal(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 (EnableFontFallback)
|
||||||
|
Render2D.DrawText(font, _watermarkText, WatermarkTextColor, ref _layout, TextMaterial);
|
||||||
|
else
|
||||||
|
// Draw without fallback
|
||||||
|
Render2D.DrawTextInternal(font, _watermarkText, WatermarkTextColor, ref _layout, TextMaterial);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Caret
|
// Caret
|
||||||
|
|||||||
Reference in New Issue
Block a user