diff --git a/GeonBit.UI/Source/Entities/Paragraph.cs b/GeonBit.UI/Source/Entities/Paragraph.cs index 607510e..47b3e7f 100644 --- a/GeonBit.UI/Source/Entities/Paragraph.cs +++ b/GeonBit.UI/Source/Entities/Paragraph.cs @@ -163,6 +163,7 @@ public Paragraph(string text, Anchor anchor = Anchor.Auto, Vector2? size = null, Text = text; UpdateStyle(DefaultStyle); if (scale != null) { SetStyleProperty(StylePropertyIds.Scale, new StyleProperty((float)scale)); } + UpdateFontPropertiesIfNeeded(); } @@ -180,6 +181,7 @@ public Paragraph(string text, Anchor anchor, Color color, float? scale = null, V { SetStyleProperty(StylePropertyIds.FillColor, new StyleProperty(color)); if (scale != null) { SetStyleProperty(StylePropertyIds.Scale, new StyleProperty((float)scale)); } + UpdateFontPropertiesIfNeeded(); } /// @@ -365,11 +367,10 @@ override public void UpdateDestinationRects() } /// - /// Calculate the paragraph actual destination rect with word-wrap and other factors taken into consideration. + /// Update font-related properties, if needed. /// - public void CalcTextActualRectWithWrap() + private void UpdateFontPropertiesIfNeeded() { - // get font SpriteFont font = GetCurrFont(); if (font != _currFont) { @@ -384,6 +385,15 @@ public void CalcTextActualRectWithWrap() if ((SingleCharacterSize.X * 2) != _currFont.MeasureString("!.").X) throw new Exceptions.InvalidValueException("Cannot use non-monospace fonts!"); } + } + + /// + /// Calculate the paragraph actual destination rect with word-wrap and other factors taken into consideration. + /// + public void CalcTextActualRectWithWrap() + { + // update font properties + UpdateFontPropertiesIfNeeded(); // calc actual scale float actualScale = Scale * BaseSize * GlobalScale; @@ -397,7 +407,7 @@ public void CalcTextActualRectWithWrap() string newProcessedText = Text; if (WrapWords) { - newProcessedText = WrapText(font, newProcessedText, _destRect.Width, _actualScale); + newProcessedText = WrapText(_currFont, newProcessedText, _destRect.Width, _actualScale); } // if processed text changed @@ -412,7 +422,7 @@ public void CalcTextActualRectWithWrap() // so we just update _size every frame and the text alignemtn (left, right, center..) fix itself by the destination rect. _fontOrigin = Vector2.Zero; _position = new Vector2(_destRect.X, _destRect.Y); - Vector2 size = font.MeasureString(_processedText); + Vector2 size = _currFont.MeasureString(_processedText); // set position and origin based on anchor. // note: no top-left here because thats the default set above.