37 lines
988 B
C#

using System;
using System.Drawing;
using System.Numerics;
using Dashboard.Drawing;
namespace Dashboard.Controls
{
public class Label : Control
{
public bool AutoSize { get; set; } = true;
public string Text { get; set; } = "";
public event EventHandler? TextChanged;
protected IBrush TextBrush => throw new NotImplementedException();
protected IFont Font => throw new NotImplementedException();
protected virtual void OnTextChanged(string oldValue, string newValue)
{
if (AutoSize)
CalculateSize();
}
protected void CalculateSize()
{
SizeF sz = Typesetter.MeasureString(Font, Text);
ClientArea = new Box2d(ClientArea.Min, ClientArea.Min + (Vector2)sz);
}
public override void OnPaint()
{
base.OnPaint();
DrawQueue.Text(new Vector3(ClientArea.Min, 0), TextBrush, Text, Font);
}
}
}