Dashboard/Quik/Controls/Label.cs

31 lines
840 B
C#
Raw Normal View History

2024-07-17 22:18:20 +02:00
using Dashboard.CommandMachine;
using Dashboard.Media;
using Dashboard.Typography;
2024-05-16 21:58:22 +02:00
2024-07-17 22:18:20 +02:00
namespace Dashboard.Controls
2024-05-16 21:58:22 +02:00
{
public class Label : Control
{
2024-06-09 21:54:33 +02:00
public string Text { get; set; } = string.Empty;
public QFont? Font { get; set; }
2024-05-16 21:58:22 +02:00
public float TextSize { get; set; }
2024-06-09 21:06:13 +02:00
public bool AutoSize { get; set; } = true;
protected override void ValidateLayout()
{
if (AutoSize)
{
2024-06-09 21:54:33 +02:00
QVec2 size = Typesetter.MeasureHorizontal(Text, TextSize, Font!);
2024-06-09 21:06:13 +02:00
Size = size;
}
}
2024-05-16 21:58:22 +02:00
protected override void ValidateVisual(CommandList cmd)
{
float padding = Padding;
QVec2 origin = new QVec2(padding, padding);
2024-06-09 21:54:33 +02:00
cmd.TypesetHorizontalDirect(Text, origin, TextSize, Font!);
2024-05-16 21:58:22 +02:00
}
}
}