2019-11-05 13:28:41 +01:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
2019-10-14 21:28:12 +02:00
|
|
|
namespace MLEM.Ui.Style {
|
|
|
|
public struct StyleProp<T> {
|
|
|
|
|
|
|
|
public T Value { get; private set; }
|
|
|
|
private bool isCustom;
|
|
|
|
|
2019-11-05 13:28:41 +01:00
|
|
|
public StyleProp(T value) {
|
|
|
|
this.isCustom = true;
|
|
|
|
this.Value = value;
|
|
|
|
}
|
|
|
|
|
2019-10-14 21:28:12 +02:00
|
|
|
public void SetFromStyle(T value) {
|
2020-02-06 01:51:41 +01:00
|
|
|
if (!this.isCustom) {
|
2019-10-14 21:28:12 +02:00
|
|
|
this.Value = value;
|
2020-02-06 01:51:41 +01:00
|
|
|
}
|
2019-10-14 21:28:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void Set(T value) {
|
|
|
|
this.isCustom = true;
|
|
|
|
this.Value = value;
|
|
|
|
}
|
|
|
|
|
2019-11-05 13:28:41 +01:00
|
|
|
public T OrDefault(T def) {
|
2020-02-06 17:36:51 +01:00
|
|
|
return this.HasValue() ? this.Value : def;
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool HasValue() {
|
|
|
|
return !EqualityComparer<T>.Default.Equals(this.Value, default);
|
2019-11-05 13:28:41 +01:00
|
|
|
}
|
|
|
|
|
2019-10-14 21:28:12 +02:00
|
|
|
public static implicit operator T(StyleProp<T> prop) {
|
|
|
|
return prop.Value;
|
|
|
|
}
|
|
|
|
|
2019-11-05 13:28:41 +01:00
|
|
|
public static implicit operator StyleProp<T>(T prop) {
|
|
|
|
return new StyleProp<T>(prop);
|
|
|
|
}
|
|
|
|
|
2019-10-14 21:28:12 +02:00
|
|
|
}
|
|
|
|
}
|