mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-22 20:58:34 +01:00
disallow creating Paragraphs without fonts
This commit is contained in:
parent
9eef1e5b1c
commit
01bec459de
4 changed files with 7 additions and 22 deletions
|
@ -26,6 +26,7 @@ Additions
|
||||||
|
|
||||||
Improvements
|
Improvements
|
||||||
- Removed LINQ Any and All usage in various methods to improve memory usage
|
- 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
|
Fixes
|
||||||
- Fixed a crash if a paragraph has a link formatting code, but no font
|
- Fixed a crash if a paragraph has a link formatting code, but no font
|
||||||
|
|
|
@ -48,7 +48,10 @@ namespace Demos {
|
||||||
RadioTexture = new NinePatch(new TextureRegion(this.testTexture, 16, 0, 8, 8), 3),
|
RadioTexture = new NinePatch(new TextureRegion(this.testTexture, 16, 0, 8, 8), 3),
|
||||||
RadioCheckmark = new TextureRegion(this.testTexture, 32, 0, 8, 8)
|
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
|
// set the defined style as the current one
|
||||||
this.UiSystem.Style = style;
|
this.UiSystem.Style = style;
|
||||||
// scale every ui up by 5
|
// scale every ui up by 5
|
||||||
|
@ -73,7 +76,7 @@ namespace Demos {
|
||||||
});
|
});
|
||||||
|
|
||||||
this.root.AddChild(new VerticalSpace(3));
|
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") {
|
this.root.AddChild(new Button(Anchor.AutoCenter, new Vector2(1, 10), "Change Style") {
|
||||||
OnPressed = element => this.UiSystem.Style = this.UiSystem.Style == untexturedStyle ? style : untexturedStyle,
|
OnPressed = element => this.UiSystem.Style = this.UiSystem.Style == untexturedStyle ? style : untexturedStyle,
|
||||||
PositionOffset = new Vector2(0, 1),
|
PositionOffset = new Vector2(0, 1),
|
||||||
|
|
|
@ -151,8 +151,8 @@ namespace MLEM.Ui.Elements {
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void InitStyle(UiStyle style) {
|
protected override void InitStyle(UiStyle style) {
|
||||||
base.InitStyle(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.TextScale.SetFromStyle(style.TextScale);
|
||||||
this.RegularFont.SetFromStyle(style.Font);
|
|
||||||
this.TextColor.SetFromStyle(style.TextColor);
|
this.TextColor.SetFromStyle(style.TextColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,25 +37,6 @@ namespace MLEM.Ui.Style {
|
||||||
this.ProgressBarColor = Color.White;
|
this.ProgressBarColor = Color.White;
|
||||||
this.ProgressBarProgressPadding = new Vector2(1);
|
this.ProgressBarProgressPadding = new Vector2(1);
|
||||||
this.ProgressBarProgressColor = Color.Red;
|
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) {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue