diff --git a/Source/Editor/Windows/DebugLogWindow.cs b/Source/Editor/Windows/DebugLogWindow.cs
index ed3a117be..64cb29f88 100644
--- a/Source/Editor/Windows/DebugLogWindow.cs
+++ b/Source/Editor/Windows/DebugLogWindow.cs
@@ -70,22 +70,61 @@ namespace FlaxEditor.Windows
private class LogEntry : Control
{
+ ///
+ /// Text block with only color available, no other styling.
+ ///
private struct TextColorBlock
{
+ ///
+ /// Color of this block.
+ ///
public Color TextColor;
+
+ ///
+ /// Range of the text.
+ ///
public TextRange Range;
- public Float2 Location;
- public Float2 Size;
+
+ ///
+ /// The text location and size.
+ ///
+ public Rectangle Bounds;
}
+ ///
+ /// Rich text parsing context.
+ ///
private struct ColorParseContext
{
+ ///
+ /// LogEntry control.
+ ///
public LogEntry Control;
+
+ ///
+ /// Caret location for the next text block.
+ ///
public Float2 Caret;
+
+ ///
+ /// Current parsed color.
+ ///
public Color CurrentColor;
+
+ ///
+ /// Default color, for reverting color on closing tags.
+ ///
public Color DefaultColor;
+
+ ///
+ /// Current text font for text processing.
+ ///
public Font TextFont;
+ ///
+ /// Add text block to the control.
+ ///
+ /// The text block to add.
public void AddBlock(ref TextColorBlock block)
{
Control._textBlocks.Add(block);
@@ -163,18 +202,27 @@ namespace FlaxEditor.Windows
}
}
+ // Processing leftover text
ProcessTextBlock(ref context, pointerPos, Desc.Title.Length);
}
+ ///
+ /// Processing the text block within given range and adding it to the list.
+ ///
+ /// The parsing context.
+ /// Start of the range.(Character index)
+ /// End of the range.(Character index)
private void ProcessTextBlock(ref ColorParseContext context, int startPos, int endPos)
{
+ // Text block preset
var textBlock = new TextColorBlock()
{
TextColor = context.CurrentColor,
Range = new TextRange(startPos, endPos),
- Location = context.Caret
+ Bounds = new Rectangle(context.Caret, Float2.Zero)
};
+ // Processing the text with selected font. (Handle newlines, text offsets)
var lines = context.TextFont.ProcessText(Desc.Title, ref textBlock.Range);
if (lines == null || lines.Length == 0)
@@ -190,18 +238,20 @@ namespace FlaxEditor.Windows
EndIndex = startPos + line.LastCharIndex + 1
};
+ // Move to the next line
if (i != 0)
{
context.Caret.Y += line.Size.Y;
- textBlock.Location.X = 0;
- textBlock.Location.Y += line.Size.Y;
+ textBlock.Bounds.X = 0;
+ textBlock.Bounds.Y += line.Size.Y;
}
- textBlock.Location.X += line.Location.X;
- textBlock.Size = line.Size;
+ textBlock.Bounds.X += line.Location.X;
+ textBlock.Bounds.Size = line.Size;
context.AddBlock(ref textBlock);
}
+ // Caret location for the next text block
var lastLine = lines[lines.Length - 1];
if (lines.Length == 1)
{
@@ -213,14 +263,21 @@ namespace FlaxEditor.Windows
}
}
+ ///
+ /// Parse color info from the tag and handle closing tags.
+ ///
+ /// The parsing context.
+ /// Tag to process.
private static void ProcessColorTag(ref ColorParseContext context, ref HtmlTag tag)
{
+ // Closing tag
if (tag.IsSlash)
{
context.CurrentColor = context.DefaultColor;
}
else
{
+ // Parse color
if (tag.Attributes.TryGetValue(string.Empty, out string colorText))
{
if (Color.TryParse(colorText, out Color colorVal))
@@ -228,6 +285,10 @@ namespace FlaxEditor.Windows
context.CurrentColor = colorVal;
}
}
+ else
+ {
+ context.CurrentColor = context.DefaultColor;
+ }
}
}
@@ -265,25 +326,27 @@ namespace FlaxEditor.Windows
Render2D.DrawSprite(Icon, new Rectangle(8, 0, 32, 32), color);
// Title
- var textRect = new Rectangle(43, 2, clientRect.Width - 40, clientRect.Height - 10);
+ var textLocation = new Float2(43, 2);
Render2D.PushClip(ref clientRect);
bool coloredText = _window._colorDebugLogText;
+ // Render text blocks with their colors
for (int i = 0; i < _textBlocks.Count; i++)
{
TextColorBlock block = _textBlocks[i];
Render2D.DrawText(style.FontMedium, Desc.Title, ref block.Range,
- coloredText ? block.TextColor : style.Foreground, textRect.TopLeft + block.Location);
+ coloredText ? block.TextColor : style.Foreground, textLocation + block.Bounds.Location);
}
+ // Adding log counter for collapsed logs
if (LogCount > 1)
{
- Float2 numberLocation = textRect.TopLeft;
+ Float2 numberLocation = textLocation;
if (_textBlocks.Count > 0)
{
TextColorBlock block = _textBlocks[_textBlocks.Count - 1];
- numberLocation += block.Location;
- numberLocation.X += block.Size.X;
+ numberLocation += block.Bounds.Location;
+ numberLocation.X += block.Bounds.Size.X;
}
Render2D.DrawText(style.FontMedium, $" ({LogCount})", color, numberLocation);