From 74988921b1c0e15047fdb74cdab16763f4da7175 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Fri, 23 Aug 2019 00:12:26 +0200 Subject: [PATCH] added line space to paragraph --- Demos/UiDemo.cs | 2 +- MLEM.Ui/Elements/Paragraph.cs | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Demos/UiDemo.cs b/Demos/UiDemo.cs index b682498..5c4354e 100644 --- a/Demos/UiDemo.cs +++ b/Demos/UiDemo.cs @@ -63,7 +63,7 @@ namespace Demos { var root = new Panel(Anchor.Center, new Vector2(80, 100), Vector2.Zero, false, true, new Point(5, 10)); this.UiSystem.Add("Test", root); - root.AddChild(new Paragraph(Anchor.AutoLeft, 1, "This is a small demo for MLEM.Ui, a user interface library that is part of (M)LEM (L)ibrary by (E)llpeck for (M)onoGame.")); + root.AddChild(new Paragraph(Anchor.AutoLeft, 1, "This is a small demo for MLEM.Ui, a user interface library that is part of (M)LEM (L)ibrary by (E)llpeck for (M)onoGame."){LineSpace = 1.5F}); var image = root.AddChild(new Image(Anchor.AutoCenter, new Vector2(50, 50), new TextureRegion(this.testTexture, 0, 0, 8, 8)) {IsHidden = true, Padding = new Point(3)}); // Setting their the x or y coordinate to 1 or a lower number causes the width or height to be a percentage of the parent's width or height // (for example, setting the size's x to 0.75 would make the element's width be 0.75*parentWidth) diff --git a/MLEM.Ui/Elements/Paragraph.cs b/MLEM.Ui/Elements/Paragraph.cs index 3027b1e..c855120 100644 --- a/MLEM.Ui/Elements/Paragraph.cs +++ b/MLEM.Ui/Elements/Paragraph.cs @@ -34,6 +34,7 @@ namespace MLEM.Ui.Elements { } public bool AutoAdjustWidth; public TextCallback GetTextCallback; + public float LineSpace = 1; public Paragraph(Anchor anchor, float width, TextCallback textCallback, bool centerText = false, IGenericFont font = null) : this(anchor, width, "", centerText, font) { @@ -61,6 +62,7 @@ namespace MLEM.Ui.Elements { if (strgScale.X > this.longestLineLength) this.longestLineLength = strgScale.X; } + this.lineHeight *= this.LineSpace; return new Point(this.AutoAdjustWidth ? this.longestLineLength.Ceil() + this.ScaledPadding.X * 2 : size.X, (this.lineHeight * this.splitText.Length).Ceil() + this.ScaledPadding.Y * 2); }