Files
Voile/DaggerFramework/Source/UI/TextLabel.cs
2023-09-25 22:18:23 +02:00

39 lines
897 B
C#

using DaggerFramework.Rendering;
namespace DaggerFramework.UI;
public class TextLabel : UIElement
{
public string Text { get; set; } = string.Empty;
public Font Font
{
get => _font; set
{
_isDirty = true;
_font = value;
}
}
public int FontSize { get; set; } = 16;
public Color FontColor { get; set; } = Color.White;
protected override void OnRender(Renderer renderer)
{
if (_isDirty && _font != null)
{
_fontHandle = renderer.LoadFont(_font);
_isDirty = false;
}
if (_font == null)
{
renderer.DrawDebugText(Text, FontSize, FontColor);
}
else
{
renderer.DrawText(_fontHandle, Text, FontSize, FontColor);
}
}
private Font? _font;
private int _fontHandle;
private bool _isDirty;
}