Make styles inherited by default
This commit is contained in:
parent
3f1b44d855
commit
3f30531d52
|
@ -17,12 +17,17 @@ namespace Ooui
|
||||||
set => SetProperty ("background-color", value);
|
set => SetProperty ("background-color", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Value BackgroundImage {
|
||||||
|
get => GetProperty ("background-image");
|
||||||
|
set => SetProperty ("background-image", value);
|
||||||
|
}
|
||||||
|
|
||||||
private Value GetProperty (string propertyName)
|
private Value GetProperty (string propertyName)
|
||||||
{
|
{
|
||||||
lock (properties) {
|
lock (properties) {
|
||||||
Value p;
|
Value p;
|
||||||
if (!properties.TryGetValue (propertyName, out p)) {
|
if (!properties.TryGetValue (propertyName, out p)) {
|
||||||
p = new Value ();
|
p = "inherit";
|
||||||
properties[propertyName] = p;
|
properties[propertyName] = p;
|
||||||
}
|
}
|
||||||
return p;
|
return p;
|
||||||
|
@ -31,13 +36,14 @@ namespace Ooui
|
||||||
|
|
||||||
private void SetProperty (string propertyName, Value value)
|
private void SetProperty (string propertyName, Value value)
|
||||||
{
|
{
|
||||||
|
var safeValue = value ?? "inherit";
|
||||||
lock (properties) {
|
lock (properties) {
|
||||||
Value old;
|
Value old;
|
||||||
if (properties.TryGetValue (propertyName, out old)) {
|
if (properties.TryGetValue (propertyName, out old)) {
|
||||||
if (EqualityComparer<Value>.Default.Equals (old, value))
|
if (EqualityComparer<Value>.Default.Equals (old, safeValue))
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
properties[propertyName] = value;
|
properties[propertyName] = safeValue;
|
||||||
}
|
}
|
||||||
PropertyChanged?.Invoke (this, new PropertyChangedEventArgs (propertyName));
|
PropertyChanged?.Invoke (this, new PropertyChangedEventArgs (propertyName));
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,23 @@ namespace Tests
|
||||||
[TestClass]
|
[TestClass]
|
||||||
public class StyleTests
|
public class StyleTests
|
||||||
{
|
{
|
||||||
|
[TestMethod]
|
||||||
|
public void DefaultIsInherit ()
|
||||||
|
{
|
||||||
|
var s = new Style ();
|
||||||
|
Assert.AreEqual ("inherit", s.BackgroundColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void NullMakesInherit ()
|
||||||
|
{
|
||||||
|
var s = new Style ();
|
||||||
|
s.BackgroundColor = "red";
|
||||||
|
Assert.AreEqual ("red", s.BackgroundColor);
|
||||||
|
s.BackgroundColor = null;
|
||||||
|
Assert.AreEqual ("inherit", s.BackgroundColor);
|
||||||
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void ChangedWhen ()
|
public void ChangedWhen ()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue