Fix console rendering bug
This commit is contained in:
@@ -186,7 +186,7 @@ namespace FlaxEngine.GUI
|
||||
};
|
||||
|
||||
// Process text into text blocks (handle newlines etc.)
|
||||
var font = textBlock.Style.Font.GetMultiFont();
|
||||
var font = textBlock.Style.Font.GetFont();
|
||||
if (!font)
|
||||
return;
|
||||
var lines = font.ProcessText(_text, ref textBlock.Range);
|
||||
@@ -195,27 +195,20 @@ namespace FlaxEngine.GUI
|
||||
for (int i = 0; i < lines.Length; i++)
|
||||
{
|
||||
ref var line = ref lines[i];
|
||||
|
||||
textBlock.Range = new TextRange
|
||||
{
|
||||
StartIndex = start + line.FirstCharIndex,
|
||||
EndIndex = start + line.LastCharIndex,
|
||||
};
|
||||
if (i != 0)
|
||||
{
|
||||
context.Caret.X = 0;
|
||||
OnLineAdded(ref context, textBlock.Range.StartIndex - 1);
|
||||
}
|
||||
for (int k = 0; k < line.Blocks.Length; k++)
|
||||
{
|
||||
ref var block = ref line.Blocks[k];
|
||||
textBlock.Bounds = new Rectangle(context.Caret, line.Size);
|
||||
textBlock.Bounds.X += line.Location.X;
|
||||
|
||||
textBlock.Range = new TextRange
|
||||
{
|
||||
StartIndex = start + block.FirstCharIndex,
|
||||
EndIndex = start + block.LastCharIndex,
|
||||
};
|
||||
|
||||
textBlock.Bounds = new Rectangle(context.Caret, block.Size);
|
||||
textBlock.Bounds.X += block.Location.X;
|
||||
|
||||
context.AddTextBlock(ref textBlock);
|
||||
}
|
||||
context.AddTextBlock(ref textBlock);
|
||||
}
|
||||
|
||||
// Update the caret location
|
||||
@@ -244,9 +237,9 @@ namespace FlaxEngine.GUI
|
||||
var ascender = textBlock.Ascender;
|
||||
//if (ascender <= 0)
|
||||
{
|
||||
var textBlockFont = textBlock.Style.Font.GetMultiFont();
|
||||
var textBlockFont = textBlock.Style.Font.GetFont();
|
||||
if (textBlockFont)
|
||||
ascender = textBlockFont.MaxAscender;
|
||||
ascender = textBlockFont.Ascender;
|
||||
}
|
||||
lineAscender = Mathf.Max(lineAscender, ascender);
|
||||
lineSize = Float2.Max(lineSize, textBlockSize);
|
||||
@@ -267,9 +260,9 @@ namespace FlaxEngine.GUI
|
||||
var ascender = textBlock.Ascender;
|
||||
if (ascender <= 0)
|
||||
{
|
||||
var textBlockFont = textBlock.Style.Font.GetMultiFont();
|
||||
var textBlockFont = textBlock.Style.Font.GetFont();
|
||||
if (textBlockFont)
|
||||
ascender = textBlockFont.MaxAscender;
|
||||
ascender = textBlockFont.Ascender;
|
||||
}
|
||||
vOffset = lineAscender - ascender;
|
||||
textBlock.Bounds.Location.Y += vOffset;
|
||||
|
||||
@@ -11,9 +11,9 @@ namespace FlaxEngine.GUI
|
||||
{
|
||||
context.Caret.X = 0;
|
||||
var style = context.StyleStack.Peek();
|
||||
var font = style.Font.GetMultiFont();
|
||||
var font = style.Font.GetFont();
|
||||
if (font)
|
||||
context.Caret.Y += font.MaxHeight;
|
||||
context.Caret.Y += font.Height;
|
||||
}
|
||||
|
||||
private static void ProcessColor(ref ParsingContext context, ref HtmlTag tag)
|
||||
@@ -87,14 +87,15 @@ namespace FlaxEngine.GUI
|
||||
else
|
||||
{
|
||||
var style = context.StyleStack.Peek();
|
||||
style.Font = new MultiFontReference(style.Font);
|
||||
if (tag.Attributes.TryGetValue("size", out var sizeText) && int.TryParse(sizeText, out var size) && tag.Attributes.TryGetValue(string.Empty, out var fontName))
|
||||
style.Font = new FontReference(style.Font);
|
||||
if (tag.Attributes.TryGetValue(string.Empty, out var fontName))
|
||||
{
|
||||
var font = (FontAsset)FindAsset(fontName, typeof(FontAsset));
|
||||
if (font)
|
||||
style.Font = new MultiFontReference([font], size);
|
||||
style.Font.Font = font;
|
||||
}
|
||||
|
||||
if (tag.Attributes.TryGetValue("size", out var sizeText) && int.TryParse(sizeText, out var size))
|
||||
style.Font.Size = size;
|
||||
context.StyleStack.Push(style);
|
||||
}
|
||||
}
|
||||
@@ -108,7 +109,7 @@ namespace FlaxEngine.GUI
|
||||
else
|
||||
{
|
||||
var style = context.StyleStack.Peek();
|
||||
// style.Font = style.Font.GetBold();
|
||||
style.Font = style.Font.GetBold();
|
||||
context.StyleStack.Push(style);
|
||||
}
|
||||
}
|
||||
@@ -122,7 +123,7 @@ namespace FlaxEngine.GUI
|
||||
else
|
||||
{
|
||||
var style = context.StyleStack.Peek();
|
||||
// style.Font = style.Font.GetItalic();
|
||||
style.Font = style.Font.GetItalic();
|
||||
context.StyleStack.Push(style);
|
||||
}
|
||||
}
|
||||
@@ -136,9 +137,9 @@ namespace FlaxEngine.GUI
|
||||
else
|
||||
{
|
||||
var style = context.StyleStack.Peek();
|
||||
style.Font = new MultiFontReference(style.Font);
|
||||
TryParseNumberTag(ref tag, string.Empty, style.Font.First().Size, out var size);
|
||||
style.Font = new MultiFontReference(style.Font, (int)size);
|
||||
style.Font = new FontReference(style.Font);
|
||||
TryParseNumberTag(ref tag, string.Empty, style.Font.Size, out var size);
|
||||
style.Font.Size = (int)size;
|
||||
context.StyleStack.Push(style);
|
||||
}
|
||||
}
|
||||
@@ -173,9 +174,9 @@ namespace FlaxEngine.GUI
|
||||
imageBlock.Style.BackgroundBrush = image;
|
||||
|
||||
// Setup size
|
||||
var font = imageBlock.Style.Font.GetMultiFont();
|
||||
var font = imageBlock.Style.Font.GetFont();
|
||||
if (font)
|
||||
imageBlock.Bounds.Size = new Float2(font.MaxHeight);
|
||||
imageBlock.Bounds.Size = new Float2(font.Height);
|
||||
imageBlock.Bounds.Size.X *= image.Size.X / image.Size.Y; // Keep original aspect ratio
|
||||
bool hasWidth = TryParseNumberTag(ref tag, "width", imageBlock.Bounds.Width, out var width);
|
||||
imageBlock.Bounds.Width = width;
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace FlaxEngine.GUI
|
||||
var style = Style.Current;
|
||||
_textStyle = new TextBlockStyle
|
||||
{
|
||||
Font = new MultiFontReference(style.FontMedium),
|
||||
Font = new FontReference(style.FontMedium.Fonts.First()),
|
||||
Color = style.Foreground,
|
||||
BackgroundSelectedBrush = new SolidColorBrush(style.BackgroundSelected),
|
||||
};
|
||||
|
||||
@@ -123,10 +123,10 @@ namespace FlaxEngine.GUI
|
||||
if (index <= 0)
|
||||
{
|
||||
ref TextBlock textBlock = ref textBlocks[0];
|
||||
var font = textBlock.Style.Font.GetMultiFont();
|
||||
var font = textBlock.Style.Font.GetFont();
|
||||
if (font)
|
||||
{
|
||||
height = font.MaxHeight / DpiScale;
|
||||
height = font.Height / DpiScale;
|
||||
return textBlock.Bounds.UpperLeft;
|
||||
}
|
||||
}
|
||||
@@ -135,10 +135,10 @@ namespace FlaxEngine.GUI
|
||||
if (index >= _text.Length)
|
||||
{
|
||||
ref TextBlock textBlock = ref textBlocks[count - 1];
|
||||
var font = textBlock.Style.Font.GetMultiFont();
|
||||
var font = textBlock.Style.Font.GetFont();
|
||||
if (font)
|
||||
{
|
||||
height = font.MaxHeight / DpiScale;
|
||||
height = font.Height / DpiScale;
|
||||
return textBlock.Bounds.UpperRight;
|
||||
}
|
||||
}
|
||||
@@ -150,10 +150,10 @@ namespace FlaxEngine.GUI
|
||||
|
||||
if (textBlock.Range.Contains(index))
|
||||
{
|
||||
var font = textBlock.Style.Font.GetMultiFont();
|
||||
var font = textBlock.Style.Font.GetFont();
|
||||
if (!font)
|
||||
break;
|
||||
height = font.MaxHeight / DpiScale;
|
||||
height = font.Height / DpiScale;
|
||||
return textBlock.Bounds.Location + font.GetCharPosition(_text, ref textBlock.Range, index - textBlock.Range.StartIndex);
|
||||
}
|
||||
}
|
||||
@@ -165,10 +165,10 @@ namespace FlaxEngine.GUI
|
||||
|
||||
if (index >= textBlock.Range.EndIndex)
|
||||
{
|
||||
var font = textBlock.Style.Font.GetMultiFont();
|
||||
var font = textBlock.Style.Font.GetFont();
|
||||
if (!font)
|
||||
break;
|
||||
height = font.MaxHeight / DpiScale;
|
||||
height = font.Height / DpiScale;
|
||||
return textBlock.Bounds.UpperRight;
|
||||
}
|
||||
}
|
||||
@@ -193,7 +193,7 @@ namespace FlaxEngine.GUI
|
||||
|
||||
if (containsY && (containsX || (i + 1 < count && textBlocks[i + 1].Bounds.Location.Y > textBlock.Bounds.Location.Y + 1.0f)))
|
||||
{
|
||||
var font = textBlock.Style.Font.GetMultiFont();
|
||||
var font = textBlock.Style.Font.GetFont();
|
||||
if (!font && textBlock.Range.Length > 0)
|
||||
break;
|
||||
return font.HitTestText(_text, ref textBlock.Range, location - textBlock.Bounds.Location) + textBlock.Range.StartIndex;
|
||||
@@ -281,7 +281,7 @@ namespace FlaxEngine.GUI
|
||||
}
|
||||
|
||||
// Pick font
|
||||
var font = textBlock.Style.Font.GetMultiFont();
|
||||
var font = textBlock.Style.Font.GetFont();
|
||||
if (!font)
|
||||
continue;
|
||||
|
||||
@@ -290,7 +290,7 @@ namespace FlaxEngine.GUI
|
||||
{
|
||||
var leftEdge = selection.StartIndex <= textBlock.Range.StartIndex ? textBlock.Bounds.UpperLeft : font.GetCharPosition(_text, selection.StartIndex);
|
||||
var rightEdge = selection.EndIndex >= textBlock.Range.EndIndex ? textBlock.Bounds.UpperRight : font.GetCharPosition(_text, selection.EndIndex);
|
||||
float height = font.MaxHeight / DpiScale;
|
||||
float height = font.Height / DpiScale;
|
||||
float alpha = Mathf.Min(1.0f, Mathf.Cos(_animateTime * BackgroundSelectedFlashSpeed) * 0.5f + 1.3f);
|
||||
alpha *= alpha;
|
||||
Color selectionColor = Color.White * alpha;
|
||||
@@ -305,7 +305,7 @@ namespace FlaxEngine.GUI
|
||||
ref TextBlock textBlock = ref textBlocks[i];
|
||||
|
||||
// Pick font
|
||||
var font = textBlock.Style.Font.GetMultiFont();
|
||||
var font = textBlock.Style.Font.GetFont();
|
||||
if (!font)
|
||||
continue;
|
||||
|
||||
@@ -332,7 +332,7 @@ namespace FlaxEngine.GUI
|
||||
ref TextBlock textBlock = ref textBlocks[i];
|
||||
|
||||
// Pick font
|
||||
var font = textBlock.Style.Font.GetMultiFont();
|
||||
var font = textBlock.Style.Font.GetFont();
|
||||
if (!font)
|
||||
continue;
|
||||
|
||||
@@ -340,7 +340,7 @@ namespace FlaxEngine.GUI
|
||||
if (textBlock.Style.UnderlineBrush != null)
|
||||
{
|
||||
var underLineHeight = 2.0f;
|
||||
var height = font.MaxHeight / DpiScale;
|
||||
var height = font.Height / DpiScale;
|
||||
var underlineRect = new Rectangle(textBlock.Bounds.Location.X, textBlock.Bounds.Location.Y + height - underLineHeight * 0.5f, textBlock.Bounds.Width, underLineHeight);
|
||||
textBlock.Style.UnderlineBrush.Draw(underlineRect, textBlock.Style.Color);
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ namespace FlaxEngine.GUI
|
||||
/// The text font.
|
||||
/// </summary>
|
||||
[EditorOrder(0)]
|
||||
public MultiFontReference Font;
|
||||
public FontReference Font;
|
||||
|
||||
/// <summary>
|
||||
/// The custom material for the text rendering (must be GUI domain).
|
||||
|
||||
Reference in New Issue
Block a user