From 567c422f8cd42eba2437f9a8c2522716a1649be7 Mon Sep 17 00:00:00 2001 From: hazel Date: Mon, 26 Jan 2026 22:04:39 +0100 Subject: celesteia archive, last updated april 9th 2024 Signed-off-by: hazel --- source/ui/elements/Label.cs | 62 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 source/ui/elements/Label.cs (limited to 'source/ui/elements/Label.cs') diff --git a/source/ui/elements/Label.cs b/source/ui/elements/Label.cs new file mode 100644 index 0000000..c875791 --- /dev/null +++ b/source/ui/elements/Label.cs @@ -0,0 +1,62 @@ +using Celesteia.UI.Properties; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; + +namespace Celesteia.UI.Elements { + public class Label : Element { + private Texture2D _background; + private TextProperties _text; + + public Label(Rect rect) { + SetRect(rect); + } + + public Label SetNewRect(Rect rect) { + SetRect(rect); + return this; + } + + public Label SetPivotPoint(Vector2 pivot) { + SetPivot(pivot); + return this; + } + + public Label SetBackground(Texture2D background) { + SetTexture(background); + return this; + } + + public Label SetText(string text) { + _text.SetText(text); + return this; + } + + public Label SetColor(Color color) { + _text.SetColor(color); + return this; + } + + public Label SetTextProperties(TextProperties text) { + _text = text; + return this; + } + + public override void Draw(SpriteBatch spriteBatch) + { + // Draw the label's background, if present. + if (_background != null) spriteBatch.Draw(GetTexture(), GetRectangle(), null, Color.White); + + TextUtilities.DrawAlignedText(spriteBatch, GetRectangle(), _text); + } + + public Texture2D GetTexture() => _background; + public void SetTexture(Texture2D background) => _background = background; + + public Label Clone() { + return new Label(GetRect()) + .SetPivotPoint(GetPivot()) + .SetBackground(GetTexture()) + .SetTextProperties(_text); + } + } +} \ No newline at end of file -- cgit v1.2.3