Cleanup stuff in #2019

This commit is contained in:
Wojtek Figat
2024-02-18 19:48:43 +01:00
parent 45aa0e1b65
commit a2b8312fba
30 changed files with 252 additions and 1756 deletions

View File

@@ -182,12 +182,6 @@ namespace FlaxEngine.GUI
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>
/// Initializes a new instance of the <see cref="Label"/> class.
/// </summary>
@@ -239,23 +233,7 @@ namespace FlaxEngine.GUI
}
}
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);
}
Render2D.DrawText(_font.GetFont(), Material, _text, rect, color, hAlignment, wAlignment, Wrapping, BaseLinesGapScale, scale);
if (ClipText)
Render2D.PopClip();
@@ -276,8 +254,7 @@ namespace FlaxEngine.GUI
layout.Bounds.Size.X = Width - Margin.Width;
else if (_autoWidth && !_autoHeight)
layout.Bounds.Size.Y = Height - Margin.Height;
_textSize = EnableFontFallback ?
font.MeasureText(_text, ref layout) : font.MeasureTextInternal(_text, ref layout);
_textSize = font.MeasureText(_text, ref layout);
_textSize.Y *= BaseLinesGapScale;
// Check if size is controlled via text

View File

@@ -1,6 +1,5 @@
// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using FlaxEngine.Utilities;

View File

@@ -213,18 +213,18 @@ namespace FlaxEngine.GUI
style.Alignment &= ~TextBlockStyle.Alignments.VerticalMask;
switch (valign)
{
case "top":
style.Alignment = TextBlockStyle.Alignments.Top;
break;
case "bottom":
style.Alignment = TextBlockStyle.Alignments.Bottom;
break;
case "middle":
style.Alignment = TextBlockStyle.Alignments.Middle;
break;
case "baseline":
style.Alignment = TextBlockStyle.Alignments.Baseline;
break;
case "top":
style.Alignment = TextBlockStyle.Alignments.Top;
break;
case "bottom":
style.Alignment = TextBlockStyle.Alignments.Bottom;
break;
case "middle":
style.Alignment = TextBlockStyle.Alignments.Middle;
break;
case "baseline":
style.Alignment = TextBlockStyle.Alignments.Baseline;
break;
}
}
context.StyleStack.Push(style);
@@ -245,15 +245,15 @@ namespace FlaxEngine.GUI
style.Alignment &= ~TextBlockStyle.Alignments.VerticalMask;
switch (valign)
{
case "left":
style.Alignment = TextBlockStyle.Alignments.Left;
break;
case "right":
style.Alignment = TextBlockStyle.Alignments.Right;
break;
case "center":
style.Alignment = TextBlockStyle.Alignments.Center;
break;
case "left":
style.Alignment = TextBlockStyle.Alignments.Left;
break;
case "right":
style.Alignment = TextBlockStyle.Alignments.Right;
break;
case "center":
style.Alignment = TextBlockStyle.Alignments.Center;
break;
}
}
context.StyleStack.Push(style);

View File

@@ -316,7 +316,6 @@ namespace FlaxEngine.GUI
color = textBlock.Style.ShadowColor;
if (!enabled)
color *= 0.6f;
// We don't need font fallbacks for rich text since the font is user-selected
Render2D.DrawText(font, _text, ref textBlock.Range, color, textBlock.Bounds.Location + textBlock.Style.ShadowOffset, textBlock.Style.CustomMaterial);
}

View File

@@ -1,8 +1,5 @@
// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
using System.ComponentModel;
namespace FlaxEngine.GUI
{
/// <summary>
@@ -67,12 +64,6 @@ namespace FlaxEngine.GUI
[EditorDisplay("Text Style"), EditorOrder(2022), Tooltip("The color of the selection (Transparent if not used).")]
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>
/// Initializes a new instance of the <see cref="TextBox"/> class.
/// </summary>
@@ -112,8 +103,7 @@ namespace FlaxEngine.GUI
return Float2.Zero;
}
return EnableFontFallback ? font.MeasureText(_text, ref _layout) :
font.MeasureTextInternal(_text, ref _layout);
return font.MeasureText(_text, ref _layout);
}
/// <inheritdoc />
@@ -126,9 +116,8 @@ namespace FlaxEngine.GUI
return Float2.Zero;
}
height = (EnableFontFallback ? font.GetMaxHeight() : font.Height) / DpiScale;
return EnableFontFallback ? font.GetCharPosition(_text, index, ref _layout) :
font.GetCharPositionInternal(_text, index, ref _layout);
height = font.Height / DpiScale;
return font.GetCharPosition(_text, index, ref _layout);
}
/// <inheritdoc />
@@ -140,8 +129,7 @@ namespace FlaxEngine.GUI
return 0;
}
return EnableFontFallback ? font.HitTestText(_text, location, ref _layout) :
font.HitTestTextInternal(_text, location, ref _layout);
return font.HitTestText(_text, location, ref _layout);
}
/// <inheritdoc />
@@ -180,13 +168,9 @@ namespace FlaxEngine.GUI
// Check if sth is selected to draw selection
if (HasSelection)
{
var leftEdge = EnableFontFallback ?
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;
var leftEdge = font.GetCharPosition(_text, SelectionLeft, ref _layout);
var rightEdge = font.GetCharPosition(_text, SelectionRight, ref _layout);
float fontHeight = font.Height / DpiScale;
// Draw selection background
float alpha = Mathf.Min(1.0f, Mathf.Cos(_animateTime * BackgroundSelectedFlashSpeed) * 0.5f + 1.3f);
@@ -226,19 +210,11 @@ namespace FlaxEngine.GUI
var color = TextColor;
if (!enabled)
color *= 0.6f;
if (EnableFontFallback)
Render2D.DrawText(font, _text, color, ref _layout, TextMaterial);
else
// Draw without fallback
Render2D.DrawTextInternal(font, _text, color, ref _layout, TextMaterial);
Render2D.DrawText(font, _text, color, ref _layout, TextMaterial);
}
else if (!string.IsNullOrEmpty(_watermarkText) && !IsFocused)
{
if (EnableFontFallback)
Render2D.DrawText(font, _watermarkText, WatermarkTextColor, ref _layout, TextMaterial);
else
// Draw without fallback
Render2D.DrawTextInternal(font, _watermarkText, WatermarkTextColor, ref _layout, TextMaterial);
Render2D.DrawText(font, _watermarkText, WatermarkTextColor, ref _layout, TextMaterial);
}
// Caret

View File

@@ -280,13 +280,13 @@ namespace FlaxEngine.GUI
/// </summary>
[EditorDisplay("Border Style"), EditorOrder(2010), Tooltip("Whether to have a border."), ExpandGroups]
public bool HasBorder { get; set; } = true;
/// <summary>
/// Gets or sets the border thickness.
/// </summary>
[EditorDisplay("Border Style"), EditorOrder(2011), Tooltip("The thickness of the border."), Limit(0)]
public float BorderThickness { get; set; } = 1.0f;
/// <summary>
/// Gets or sets the color of the border (Transparent if not used).
/// </summary>