From d73539e41e3de0477cdc2e682d0a4ed4f7e98dd8 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sun, 28 Feb 2021 14:43:07 +0100 Subject: [PATCH] added a text scale multiplier to Paragraph --- MLEM.Ui/Elements/Paragraph.cs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/MLEM.Ui/Elements/Paragraph.cs b/MLEM.Ui/Elements/Paragraph.cs index 339dc62..138adb7 100644 --- a/MLEM.Ui/Elements/Paragraph.cs +++ b/MLEM.Ui/Elements/Paragraph.cs @@ -31,10 +31,16 @@ namespace MLEM.Ui.Elements { /// public StyleProp TextColor; /// - /// The scale that the text will be rendered with + /// The scale that the text will be rendered with. + /// To add a multiplier rather than changing the scale directly, use . /// public StyleProp TextScale; /// + /// A multiplier that will be applied to . + /// To change the text scale itself, use . + /// + public float TextScaleMultiplier = 1; + /// /// The text to render inside of this paragraph. /// Use if the text changes frequently. /// @@ -92,7 +98,7 @@ namespace MLEM.Ui.Elements { protected override Vector2 CalcActualSize(RectangleF parentArea) { var size = base.CalcActualSize(parentArea); this.ParseText(size); - var dims = this.TokenizedText.Measure(this.RegularFont) * this.TextScale * this.Scale; + var dims = this.TokenizedText.Measure(this.RegularFont) * this.TextScale * this.TextScaleMultiplier * this.Scale; return new Vector2(this.AutoAdjustWidth ? dims.X + this.ScaledPadding.Width : size.X, dims.Y + this.ScaledPadding.Height); } @@ -107,7 +113,7 @@ namespace MLEM.Ui.Elements { /// public override void Draw(GameTime time, SpriteBatch batch, float alpha, BlendState blendState, SamplerState samplerState, Matrix matrix) { var pos = this.DisplayArea.Location; - var sc = this.TextScale * this.Scale; + var sc = this.TextScale * this.TextScaleMultiplier * this.Scale; var color = this.TextColor.OrDefault(Color.White) * alpha; this.TokenizedText.Draw(time, batch, pos, this.RegularFont, color, sc, 0); base.Draw(time, batch, alpha, blendState, samplerState, matrix); @@ -134,9 +140,9 @@ namespace MLEM.Ui.Elements { // add links to the paragraph this.RemoveChildren(c => c is Link); foreach (var link in this.TokenizedText.Tokens.Where(t => t.AppliedCodes.Any(c => c is LinkCode))) - this.AddChild(new Link(Anchor.TopLeft, link, this.TextScale)); + this.AddChild(new Link(Anchor.TopLeft, link, this.TextScale * this.TextScaleMultiplier)); } - this.TokenizedText.Split(this.RegularFont, size.X - this.ScaledPadding.Width, this.TextScale * this.Scale); + this.TokenizedText.Split(this.RegularFont, size.X - this.ScaledPadding.Width, this.TextScale * this.TextScaleMultiplier * this.Scale); } private void QueryTextCallback() {