瀏覽代碼

Add full constructor to ColorScheme

tznind 1 年之前
父節點
當前提交
b5747cce50
共有 2 個文件被更改,包括 38 次插入0 次删除
  1. 15 0
      Terminal.Gui/Drawing/ColorScheme.cs
  2. 23 0
      UnitTests/Drawing/ColorSchemeTests.cs

+ 15 - 0
Terminal.Gui/Drawing/ColorScheme.cs

@@ -48,6 +48,21 @@ public record ColorScheme : IEqualityOperators<ColorScheme, ColorScheme, bool>
         _hotFocus = attribute;
     }
 
+    /// <summary>Creates a new instance, initialized with the values provided.</summary>
+    public ColorScheme (
+        Attribute normal,
+        Attribute focus,
+        Attribute hotNormal,
+        Attribute disabled,
+        Attribute hotFocus)
+    {
+        _normal = normal;
+        _focus = focus;
+        _hotNormal = hotNormal;
+        _disabled = disabled;
+        _hotFocus = hotFocus;
+    }
+
     /// <summary>The default foreground and background color for text when the view is disabled.</summary>
     public Attribute Disabled
     {

+ 23 - 0
UnitTests/Drawing/ColorSchemeTests.cs

@@ -38,4 +38,27 @@ public class ColorSchemeTests
         lbl.ColorScheme = scheme;
         lbl.Draw ();
     }
+
+    [Fact]
+    public void ColorScheme_BigConstructor ()
+    {
+        var a = new Attribute (1);
+        var b = new Attribute (2);
+        var c = new Attribute (3);
+        var d = new Attribute (4);
+        var e = new Attribute (5);
+
+        var cs = new ColorScheme (
+            normal: a,
+            focus: b,
+            hotNormal: c,
+            disabled: d,
+            hotFocus: e);
+
+        Assert.Equal (a, cs.Normal);
+        Assert.Equal (b, cs.Focus);
+        Assert.Equal (c, cs.HotNormal);
+        Assert.Equal (d, cs.Disabled);
+        Assert.Equal (e, cs.HotFocus);
+    }
 }