1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-12-26 10:19:22 +01:00

added HasValue() to styleprop

This commit is contained in:
Ellpeck 2020-02-06 17:36:51 +01:00
parent 5bf111d05a
commit d823064979
5 changed files with 11 additions and 8 deletions

View file

@ -132,7 +132,7 @@ namespace MLEM.Ui.Elements {
}
public override void Draw(GameTime time, SpriteBatch batch, float alpha, BlendState blendState, SamplerState samplerState, Matrix matrix) {
if (this.Texture.Value != null)
if (this.Texture.HasValue())
batch.Draw(this.Texture, this.DisplayArea, Color.White * alpha, this.Scale);
// if we handle overflow, draw using the render target in DrawUnbound
if (!this.scrollOverflow || this.renderTarget == null) {

View file

@ -36,9 +36,8 @@ namespace MLEM.Ui.Elements {
batch.Draw(this.Texture, this.DisplayArea, (Color) this.Color * alpha, this.Scale);
var percentage = this.CurrentValue / this.MaxValue;
var tex = this.ProgressTexture.Value;
var padHor = tex != null ? tex.Padding.Width * this.Scale : 0;
var padVer = tex != null ? tex.Padding.Height * this.Scale : 0;
var padHor = this.ProgressTexture.HasValue() ? this.ProgressTexture.Value.Padding.Width * this.Scale : 0;
var padVer = this.ProgressTexture.HasValue() ? this.ProgressTexture.Value.Padding.Height * this.Scale : 0;
var width = percentage * (this.DisplayArea.Width - padHor) + padHor;
var height = percentage * (this.DisplayArea.Height - padVer) + padVer;
RectangleF progressArea;
@ -61,7 +60,7 @@ namespace MLEM.Ui.Elements {
break;
}
var offsetArea = progressArea.Shrink(this.ProgressPadding.Value * this.Scale);
if (this.ProgressTexture.Value != null) {
if (this.ProgressTexture.HasValue()) {
batch.Draw(this.ProgressTexture, offsetArea, (Color) this.ProgressColor * alpha, this.Scale);
} else {
batch.Draw(batch.GetBlankTexture(), offsetArea, (Color) this.ProgressColor * alpha);

View file

@ -84,7 +84,7 @@ namespace MLEM.Ui.Elements {
private void HandleTextChange(bool textChanged = true) {
// not initialized yet
if (this.Font.Value == null)
if (!this.Font.HasValue())
return;
var length = this.Font.Value.MeasureString(this.text).X * this.TextScale;
var maxWidth = this.DisplayArea.Width / this.Scale - this.TextOffsetX * 2;

View file

@ -23,7 +23,11 @@ namespace MLEM.Ui.Style {
}
public T OrDefault(T def) {
return EqualityComparer<T>.Default.Equals(this.Value, default) ? def : this.Value;
return this.HasValue() ? this.Value : def;
}
public bool HasValue() {
return !EqualityComparer<T>.Default.Equals(this.Value, default);
}
public static implicit operator T(StyleProp<T> prop) {

View file

@ -85,7 +85,7 @@ namespace MLEM.Ui {
this.OnMousedElementChanged = e => this.ApplyToAll(t => t.OnMousedElementChanged?.Invoke(t, e));
this.OnSelectedElementChanged = e => this.ApplyToAll(t => t.OnSelectedElementChanged?.Invoke(t, e));
this.OnSelectedElementDrawn = (element, time, batch, alpha) => {
if (this.Controls.IsAutoNavMode && element.SelectionIndicator.Value != null) {
if (this.Controls.IsAutoNavMode && element.SelectionIndicator.HasValue()) {
batch.Draw(element.SelectionIndicator, element.DisplayArea, Color.White * alpha, element.Scale / 2);
}
};