mirror of
https://github.com/AlexMacocian/MonoGame.Extended.git
synced 2026-07-24 12:06:37 +00:00
27 lines
999 B
C#
27 lines
999 B
C#
namespace MonoGame.Extended.Gui.Controls
|
|
{
|
|
public abstract class ContentControl : Control
|
|
{
|
|
public object Content { get; set; }
|
|
public bool HasContent => Content == null;
|
|
|
|
public override void Draw(IGuiContext context, IGuiRenderer renderer, float deltaSeconds)
|
|
{
|
|
base.Draw(context, renderer, deltaSeconds);
|
|
|
|
var text = Content?.ToString();
|
|
var textInfo = GetTextInfo(context, text, ContentRectangle, HorizontalTextAlignment, VerticalTextAlignment);
|
|
|
|
if (!string.IsNullOrWhiteSpace(textInfo.Text))
|
|
renderer.DrawText(textInfo.Font, textInfo.Text, textInfo.Position + TextOffset, textInfo.Color, textInfo.ClippingRectangle);
|
|
}
|
|
|
|
public override Size2 GetContentSize(IGuiContext context)
|
|
{
|
|
var text = Content?.ToString();
|
|
var font = Font ?? context.DefaultFont;
|
|
return font.MeasureString(text ?? string.Empty);
|
|
}
|
|
}
|
|
|
|
} |