Add size tag

This commit is contained in:
Wojciech Figat
2022-08-03 15:41:25 +02:00
parent 6f18a8a3ff
commit 4923d63a94
2 changed files with 22 additions and 0 deletions

View File

@@ -75,6 +75,7 @@ namespace FlaxEngine.GUI
{ "font", ProcessFont },
{ "b", ProcessBold },
{ "i", ProcessItalic },
{ "size", ProcessSize },
};
private HtmlParser _parser = new HtmlParser();

View File

@@ -137,5 +137,26 @@ namespace FlaxEngine.GUI
context.StyleStack.Push(style);
}
}
private static void ProcessSize(ref ParsingContext context, ref HtmlTag tag)
{
if (tag.IsSlash)
{
context.StyleStack.Pop();
}
else
{
var style = context.StyleStack.Peek();
style.Font = new FontReference(style.Font);
if (tag.Attributes.TryGetValue(string.Empty, out var sizeText))
{
if (int.TryParse(sizeText, out var sizeInt))
style.Font.Size = sizeInt;
if (sizeText.Length > 1 && sizeText[sizeText.Length - 1] == '%')
style.Font.Size = (int)(style.Font.Size * float.Parse(sizeText.Substring(0, sizeText.Length - 1)) / 100.0f);
}
context.StyleStack.Push(style);
}
}
}
}