Files
RobustToolbox/Robust.Client/UserInterface/Controls/RichTextLabel.cs
T
Pieter-Jan BriersandGitHub cf2995437f Remove Godot support. (#805)
Let's be real, it's pretty damn broken already and will never be fixed.
2019-05-05 01:58:24 +02:00

87 lines
1.9 KiB
C#

using System.Collections.Generic;
using JetBrains.Annotations;
using Robust.Client.Graphics;
using Robust.Client.Graphics.Drawing;
using Robust.Client.Utility;
using Robust.Shared.Maths;
using Robust.Shared.Utility;
namespace Robust.Client.UserInterface.Controls
{
public class RichTextLabel : Control
{
private FormattedMessage _message;
private RichTextEntry _entry;
public RichTextLabel()
{
}
public RichTextLabel(string name) : base(name)
{
}
public void SetMessage(FormattedMessage message)
{
_message = message;
_entry = new RichTextEntry(_message);
_updateEntry();
}
protected override Vector2 CalculateMinimumSize()
{
if (_message == null)
{
return Vector2.Zero;
}
return (0, _entry.Height);
}
private void _updateEntry()
{
var font = _getFont();
if (_message != null)
{
var oldHeight = _entry.Height;
_entry.Update(font, Width);
if (oldHeight != _entry.Height)
{
MinimumSizeChanged();
}
}
}
protected internal override void Draw(DrawingHandleScreen handle)
{
base.Draw(handle);
if (_message == null)
{
return;
}
_entry.Draw(handle, _getFont(), SizeBox, 0, new Stack<FormattedMessage.Tag>());
}
protected override void Resized()
{
base.Resized();
_updateEntry();
}
[Pure]
private Font _getFont()
{
if (TryGetStyleProperty("font", out Font font))
{
return font;
}
return UserInterfaceManager.ThemeDefaults.DefaultFont;
}
}
}