1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-05-19 23:51:23 +02:00

disallow creating Paragraphs without fonts

This commit is contained in:
Ell 2021-07-22 04:51:41 +02:00
parent 9eef1e5b1c
commit 01bec459de
4 changed files with 7 additions and 22 deletions

View file

@ -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

View file

@ -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),

View file

@ -151,8 +151,8 @@ namespace MLEM.Ui.Elements {
/// <inheritdoc />
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);
}

View file

@ -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) {
}
}
}