1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-09-28 09:01:06 +02:00
MLEM/MLEM.Ui/Style/StyleProp.cs

45 lines
1.2 KiB
C#
Raw Normal View History

2019-11-05 13:28:41 +01:00
using System.Collections.Generic;
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;
}
public void SetFromStyle(T value) {
2020-02-06 01:33:24 +01:00
if (!this.isCustom)
this.Value = value;
}
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 01:33:24 +01:00
return EqualityComparer<T>.Default.Equals(this.Value, default(T)) ? def : this.Value;
2019-11-05 13:28:41 +01: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);
}
2020-02-06 01:33:24 +01:00
public static bool operator ==(StyleProp<T> left, StyleProp<T> right) {
return EqualityComparer<T>.Default.Equals(left.Value, right.Value);
}
public static bool operator !=(StyleProp<T> left, StyleProp<T> right) {
return !(left == right);
}
}
}