From 04092e9e9f647848246c931f796468359b94101a Mon Sep 17 00:00:00 2001 From: "Frank A. Krueger" Date: Mon, 19 Jun 2017 00:18:25 -0700 Subject: [PATCH] Add Width and Height to Canvas --- Ooui/Canvas.cs | 12 ++++++++++++ Tests/CanvasTests.cs | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/Ooui/Canvas.cs b/Ooui/Canvas.cs index 6c18647..3fed795 100644 --- a/Ooui/Canvas.cs +++ b/Ooui/Canvas.cs @@ -7,6 +7,18 @@ namespace Ooui Context2d context2d = new Context2d (); int gotContext2d = 0; + int width = 150; + public int Width { + get => width; + set => SetProperty (ref width, value <= 0 ? 150 : value, "width"); + } + + int height = 150; + public int Height { + get => height; + set => SetProperty (ref height, value <= 0 ? 150 : value, "height"); + } + public Canvas () : base ("canvas") { diff --git a/Tests/CanvasTests.cs b/Tests/CanvasTests.cs index da1aed5..12d8a9b 100644 --- a/Tests/CanvasTests.cs +++ b/Tests/CanvasTests.cs @@ -19,5 +19,39 @@ namespace Tests Assert.AreEqual (2, c.StateMessages.Count); Assert.AreEqual (c2d, c2d2); } + + [TestMethod] + public void DefaultWidthAndHeight () + { + var c = new Canvas (); + Assert.AreEqual (150, c.Width); + Assert.AreEqual (150, c.Height); + } + + [TestMethod] + public void WidthAndHeight () + { + var c = new Canvas { + Width = 640, + Height = 480, + }; + Assert.AreEqual (640, c.Width); + Assert.AreEqual (480, c.Height); + } + + [TestMethod] + public void CantBeNegativeOrZero () + { + var c = new Canvas { + Width = 640, + Height = 480, + }; + Assert.AreEqual (640, c.Width); + Assert.AreEqual (480, c.Height); + c.Width = 0; + c.Height = 0; + Assert.AreEqual (150, c.Width); + Assert.AreEqual (150, c.Height); + } } }