diff --git a/CHANGELOG.md b/CHANGELOG.md index 821fb02..90de437 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ Additions Improvements - Removed LINQ Any and All usage in various methods to improve memory usage +- Explicitly disallow creating Paragraphs without fonts to make starting out with MLEM.Ui less confusing Fixes - Fixed a crash if a paragraph has a link formatting code, but no font diff --git a/Demos/UiDemo.cs b/Demos/UiDemo.cs index ae7afd7..09ad761 100644 --- a/Demos/UiDemo.cs +++ b/Demos/UiDemo.cs @@ -48,7 +48,10 @@ namespace Demos { RadioTexture = new NinePatch(new TextureRegion(this.testTexture, 16, 0, 8, 8), 3), RadioCheckmark = new TextureRegion(this.testTexture, 32, 0, 8, 8) }; - var untexturedStyle = new UntexturedStyle(this.SpriteBatch); + var untexturedStyle = new UntexturedStyle(this.SpriteBatch) { + TextScale = style.TextScale, + Font = style.Font + }; // set the defined style as the current one this.UiSystem.Style = style; // scale every ui up by 5 @@ -73,7 +76,7 @@ namespace Demos { }); this.root.AddChild(new VerticalSpace(3)); - this.root.AddChild(new Paragraph(Anchor.AutoLeft, 1, "Note that the default style does not contain any textures or font files and, as such, is quite bland. However, the default style is quite easy to override, as can be seen in the code for this demo.")); + this.root.AddChild(new Paragraph(Anchor.AutoLeft, 1, "Note that the default style does not contain any textures and, as such, is quite bland. However, the default style is quite easy to override, as can be seen in the code for this demo.")); this.root.AddChild(new Button(Anchor.AutoCenter, new Vector2(1, 10), "Change Style") { OnPressed = element => this.UiSystem.Style = this.UiSystem.Style == untexturedStyle ? style : untexturedStyle, PositionOffset = new Vector2(0, 1), diff --git a/MLEM.Ui/Elements/Paragraph.cs b/MLEM.Ui/Elements/Paragraph.cs index 962fddf..f182ee8 100644 --- a/MLEM.Ui/Elements/Paragraph.cs +++ b/MLEM.Ui/Elements/Paragraph.cs @@ -151,8 +151,8 @@ namespace MLEM.Ui.Elements { /// protected override void InitStyle(UiStyle style) { base.InitStyle(style); + this.RegularFont.SetFromStyle(style.Font ?? throw new NotSupportedException("Paragraphs cannot use ui styles that don't have a font. Please supply a custom font by setting UiStyle.Font.")); this.TextScale.SetFromStyle(style.TextScale); - this.RegularFont.SetFromStyle(style.Font); this.TextColor.SetFromStyle(style.TextColor); } diff --git a/MLEM.Ui/Style/UntexturedStyle.cs b/MLEM.Ui/Style/UntexturedStyle.cs index bc58fd6..108a445 100644 --- a/MLEM.Ui/Style/UntexturedStyle.cs +++ b/MLEM.Ui/Style/UntexturedStyle.cs @@ -37,25 +37,6 @@ namespace MLEM.Ui.Style { this.ProgressBarColor = Color.White; this.ProgressBarProgressPadding = new Vector2(1); this.ProgressBarProgressColor = Color.Red; - this.Font = new EmptyFont(); - } - - private class EmptyFont : GenericFont { - - public override GenericFont Bold => this; - public override GenericFont Italic => this; - public override float LineHeight => 1; - - protected override Vector2 MeasureChar(char c) { - return Vector2.Zero; - } - - public override void DrawString(SpriteBatch batch, string text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth) { - } - - public override void DrawString(SpriteBatch batch, StringBuilder text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth) { - } - } }