diff --git a/Terminal.Gui/View/View.cs b/Terminal.Gui/View/View.cs index 8c066698d7..6edd992ebd 100644 --- a/Terminal.Gui/View/View.cs +++ b/Terminal.Gui/View/View.cs @@ -476,8 +476,8 @@ public virtual Rect Frame { set { _frame = new Rect (value.X, value.Y, Math.Max (value.Width, 0), Math.Max (value.Height, 0)); if (IsInitialized || LayoutStyle == LayoutStyle.Absolute) { - TextFormatter.Size = GetSizeNeededForTextAndHotKey (); LayoutFrames (); + TextFormatter.Size = GetSizeNeededForTextAndHotKey (); SetNeedsLayout (); SetNeedsDisplay (); } @@ -676,7 +676,6 @@ public virtual Rect Bounds { value.Size.Height + Margin.Thickness.Vertical + Border.Thickness.Vertical + Padding.Thickness.Vertical ) ); - ; } } @@ -869,8 +868,8 @@ Width is Dim.DimAbsolute && /// will not fit. public bool SetMinWidthHeight () { - if (IsInitialized && GetMinimumBounds (out Size size)) { - Bounds = new Rect (Bounds.Location, size); + if (GetMinimumBounds (out Size size)) { + _frame = new Rect (_frame.Location, size); return true; } return false; @@ -1006,8 +1005,7 @@ void SetInitialProperties (ustring text, Rect rect, LayoutStyle layoutStyle = La Text = text == null ? ustring.Empty : text; LayoutStyle = layoutStyle; - var r = rect.IsEmpty ? TextFormatter.CalcRect (0, 0, text, direction) : rect; - Frame = r; + Frame = rect.IsEmpty ? TextFormatter.CalcRect (0, 0, text, direction) : rect; OnResizeNeeded (); CreateFrames (); @@ -1050,15 +1048,14 @@ protected virtual void OnResizeNeeded () var w = _width is Dim.DimAbsolute ? _width.Anchor (0) : _frame.Width; var h = _height is Dim.DimAbsolute ? _height.Anchor (0) : _frame.Height; // BUGBUG: v2 - ? - If layoutstyle is absolute, this overwrites the current frame h/w with 0. Hmmm... + // This is needed for DimAbsolute values by setting the frame before LayoutSubViews. _frame = new Rect (new Point (actX, actY), new Size (w, h)); // Set frame, not Frame! - - } //// BUGBUG: I think these calls are redundant or should be moved into just the AutoSize case if (IsInitialized || LayoutStyle == LayoutStyle.Absolute) { - TextFormatter.Size = GetSizeNeededForTextAndHotKey (); - LayoutFrames (); SetMinWidthHeight (); + LayoutFrames (); + TextFormatter.Size = GetSizeNeededForTextAndHotKey (); SetNeedsLayout (); SetNeedsDisplay (); } @@ -1624,6 +1621,7 @@ public virtual void OnAdded (SuperViewChangedEventArgs e) { var view = e.Child; view.IsAdded = true; + view.OnResizeNeeded (); view._x ??= view._frame.X; view._y ??= view._frame.Y; view._width ??= view._frame.Width; @@ -2723,6 +2721,7 @@ internal virtual void LayoutFrames () if (Margin == null) return; // CreateFrames() has not been called yet if (Margin.Frame.Size != Frame.Size) { + Margin._frame = new Rect (Point.Empty, Frame.Size); Margin.X = 0; Margin.Y = 0; Margin.Width = Frame.Size.Width; @@ -2734,6 +2733,7 @@ internal virtual void LayoutFrames () var border = Margin.Thickness.GetInside (Margin.Frame); if (border != Border.Frame) { + Border._frame = new Rect (new Point (border.Location.X, border.Location.Y), border.Size); Border.X = border.Location.X; Border.Y = border.Location.Y; Border.Width = border.Size.Width; @@ -2745,6 +2745,7 @@ internal virtual void LayoutFrames () var padding = Border.Thickness.GetInside (Border.Frame); if (padding != Padding.Frame) { + Padding._frame = new Rect (new Point (padding.Location.X, padding.Location.Y), padding.Size); Padding.X = padding.Location.X; Padding.Y = padding.Location.Y; Padding.Width = padding.Size.Width; @@ -2833,16 +2834,10 @@ public virtual ustring Text { get => _text; set { _text = value; - if (IsInitialized) { - SetHotKey (); - UpdateTextFormatterText (); - //TextFormatter.Format (); - OnResizeNeeded (); - } - - // BUGBUG: v2 - This is here as a HACK until we fix the unit tests to not check a view's dims until - // after it's been initialized. See #2450 + SetHotKey (); UpdateTextFormatterText (); + //TextFormatter.Format (); + OnResizeNeeded (); #if DEBUG if (_text != null && string.IsNullOrEmpty (Id)) { @@ -2927,11 +2922,8 @@ public virtual VerticalTextAlignment VerticalTextAlignment { public virtual TextDirection TextDirection { get => TextFormatter.Direction; set { - if (!IsInitialized) { - TextFormatter.Direction = value; - } else { - UpdateTextDirection (value); - } + UpdateTextDirection (value); + TextFormatter.Direction = value; } } @@ -3324,6 +3316,7 @@ protected override void Dispose (bool disposing) Margin?.Dispose (); Margin = null; Border?.Dispose (); + Border = null; Padding?.Dispose (); Padding = null; @@ -3366,7 +3359,6 @@ public virtual void BeginInit () // TODO: Figure out why ScrollView and other tests fail if this call is put here // instead of the constructor. - OnResizeNeeded (); //InitializeFrames (); } else { @@ -3389,6 +3381,7 @@ public virtual void BeginInit () public void EndInit () { IsInitialized = true; + OnResizeNeeded (); if (_subviews != null) { foreach (var view in _subviews) { if (!view.IsInitialized) { diff --git a/Terminal.Gui/Views/Toplevel.cs b/Terminal.Gui/Views/Toplevel.cs index bf101f47d3..52b835145a 100644 --- a/Terminal.Gui/Views/Toplevel.cs +++ b/Terminal.Gui/Views/Toplevel.cs @@ -649,7 +649,7 @@ internal View GetLocationThatFits (Toplevel top, int targetX, int targetY, } // BUGBUG: v2 hack for now - var mfLength = top.Border.Thickness.Top > 0 ? 2 : 1; + var mfLength = top.Border?.Thickness.Top > 0 ? 2 : 1; if (top.Frame.Width <= maxWidth) { nx = Math.Max (targetX, 0); nx = nx + top.Frame.Width > maxWidth ? Math.Max (maxWidth - top.Frame.Width, 0) : nx; diff --git a/UnitTests/Dialogs/DialogTests.cs b/UnitTests/Dialogs/DialogTests.cs index 27b9351c59..8318e9a879 100644 --- a/UnitTests/Dialogs/DialogTests.cs +++ b/UnitTests/Dialogs/DialogTests.cs @@ -152,7 +152,7 @@ public void Location_When_Not_Application_Top_Not_Default () var iterations = -1; Application.Iteration += () => { iterations++; - + if (iterations == 0) { var d = new Dialog () { X = 5, @@ -200,12 +200,12 @@ public void Location_When_Not_Application_Top_Not_Default () Application.RequestStop (); } }; - + Application.Begin (Application.Top); ((FakeDriver)Application.Driver).SetBufferSize (20, 10); Application.Run (); } - + [Fact] [AutoInitShutdown] public void ButtonAlignment_One () @@ -511,10 +511,10 @@ public void ButtonAlignment_Four_On_Too_Small_Width () var btn4Text = "never"; var btn4 = $"{d.LeftBracket} {btn4Text} {d.RightBracket}"; var buttonRow = string.Empty; - + var width = 30; d.SetBufferSize (width, 1); - + // Default - Center buttonRow = $"{d.VLine}es ] {btn2} {btn3} [ neve{d.VLine}"; (runstate, var dlg) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Center, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text)); @@ -937,6 +937,65 @@ public void Dialog_In_Window_With_Size_One_Button_Aligns () // Application.Run (win); // Application.Shutdown (); // } - } + [Fact, AutoInitShutdown] + public void Dialog_In_Window_With_TexxtField_And_Button_AnchorEnd () + { + ((FakeDriver)Application.Driver).SetBufferSize (20, 5); + + var win = new Window (); + + int iterations = 0; + Application.Iteration += () => { + if (++iterations > 2) { + Application.RequestStop (); + } + }; + + win.Loaded += (s, a) => { + var dlg = new Dialog () { Width = 18, Height = 3 }; + Button btn = null; + btn = new Button ("Ok") { + X = Pos.AnchorEnd () - Pos.Function (Btn_Width) + }; + int Btn_Width () + { + return (btn?.Bounds.Width) ?? 0; + } + var tf = new TextField ("01234567890123456789") { + Width = Dim.Fill (1) - Dim.Function (Btn_Width) + }; + + dlg.Loaded += (s, a) => { + Application.Refresh (); + Assert.Equal (new Rect (10, 0, 6, 1), btn.Frame); + Assert.Equal (new Rect (0, 0, 6, 1), btn.Bounds); + var expected = @" +┌──────────────────┐ +│┌────────────────┐│ +││23456789 [ Ok ]││ +│└────────────────┘│ +└──────────────────┘"; + _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, output); + + dlg.SetNeedsLayout (); + dlg.LayoutSubviews (); + Application.Refresh (); + Assert.Equal (new Rect (10, 0, 6, 1), btn.Frame); + Assert.Equal (new Rect (0, 0, 6, 1), btn.Bounds); + expected = @" +┌──────────────────┐ +│┌────────────────┐│ +││23456789 [ Ok ]││ +│└────────────────┘│ +└──────────────────┘"; + _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, output); + }; + dlg.Add (btn, tf); + + Application.Run (dlg); + }; + Application.Run (win); + } + } } \ No newline at end of file diff --git a/UnitTests/Drawing/LineCanvasTests.cs b/UnitTests/Drawing/LineCanvasTests.cs index c029053f48..3c2d29b887 100644 --- a/UnitTests/Drawing/LineCanvasTests.cs +++ b/UnitTests/Drawing/LineCanvasTests.cs @@ -39,23 +39,23 @@ public void Bounds_H_Line (int x, int y, int length, Assert.Equal (new Rect (expectedX, expectedY, expectedWidth, expectedHeight), canvas.Bounds); } - - [InlineData (0, 0, 0, + + [InlineData (0, 0, 0, 0, 0, 1, 1)] - [InlineData (0, 0, 1, + [InlineData (0, 0, 1, 0, 0, 1, 1)] - [InlineData (0, 0, 2, + [InlineData (0, 0, 2, 0, 0, 2, 2)] - [InlineData (0, 0, 3, + [InlineData (0, 0, 3, 0, 0, 3, 3)] - [InlineData (0, 0, -1, + [InlineData (0, 0, -1, 0, 0, 1, 1)] - [InlineData (0, 0, -2, + [InlineData (0, 0, -2, -1, -1, 2, 2)] - [InlineData (0, 0, -3, + [InlineData (0, 0, -3, -2, -2, 3, 3)] [Theory, SetupFakeDriver] - public void Bounds_H_And_V_Lines_Both_Positive (int x, int y, int length, + public void Bounds_H_And_V_Lines_Both_Positive (int x, int y, int length, int expectedX, int expectedY, int expectedWidth, int expectedHeight) { var canvas = new LineCanvas (); @@ -125,6 +125,52 @@ public void Bounds_Specific () $"{Environment.NewLine}{lc}"); } + [Fact, SetupFakeDriver] + public void Bounds_Specific_With_Ustring () + { + // Draw at 1,1 within client area of View (i.e. leave a top and left margin of 1) + // This proves we aren't drawing excess above + int x = 1; + int y = 2; + int width = 3; + int height = 2; + + var lc = new LineCanvas (); + + // 01230 + // ╔╡╞╗1 + // ║ ║2 + + // Add a short horiz line for ╔╡ + lc.AddLine (new Point (x, y), 2, Orientation.Horizontal, LineStyle.Double); + Assert.Equal (new Rect (x, y, 2, 1), lc.Bounds); + + //LHS line down + lc.AddLine (new Point (x, y), height, Orientation.Vertical, LineStyle.Double); + Assert.Equal (new Rect (x, y, 2, 2), lc.Bounds); + + //Vertical line before Title, results in a ╡ + lc.AddLine (new Point (x + 1, y), 0, Orientation.Vertical, LineStyle.Single); + Assert.Equal (new Rect (x, y, 2, 2), lc.Bounds); + + //Vertical line after Title, results in a ╞ + lc.AddLine (new Point (x + 2, y), 0, Orientation.Vertical, LineStyle.Single); + Assert.Equal (new Rect (x, y, 3, 2), lc.Bounds); + + // remainder of top line + lc.AddLine (new Point (x + 2, y), width - 1, Orientation.Horizontal, LineStyle.Double); + Assert.Equal (new Rect (x, y, 4, 2), lc.Bounds); + + //RHS line down + lc.AddLine (new Point (x + width, y), height, Orientation.Vertical, LineStyle.Double); + Assert.Equal (new Rect (x, y, 4, 2), lc.Bounds); + + TestHelpers.AssertEqual (output, @" +╔╡╞╗ +║ ║", + ustring.Make ($"{Environment.NewLine}{lc}")); + } + [Fact, SetupFakeDriver] public void ToString_Empty () { @@ -356,7 +402,7 @@ public void Zero_Length_Intersections () //RHS line down lc.AddLine (new Point (x + width, y), height, Orientation.Vertical, LineStyle.Double); - + string looksLike = @" ╔╡╞══╗ ║ ║"; @@ -491,7 +537,7 @@ public void Top_With_1Down () var map = canvas.GetMap (); Assert.Equal (2, map.Count); - + TestHelpers.AssertEqual (output, @" ─ ─", @@ -502,7 +548,7 @@ public void Top_With_1Down () public void Window () { var canvas = new LineCanvas (); - + // Frame canvas.AddLine (new Point (0, 0), 10, Orientation.Horizontal, LineStyle.Single); canvas.AddLine (new Point (9, 0), 5, Orientation.Vertical, LineStyle.Single); @@ -512,7 +558,7 @@ public void Window () // Cross canvas.AddLine (new Point (5, 0), 5, Orientation.Vertical, LineStyle.Single); canvas.AddLine (new Point (0, 2), 10, Orientation.Horizontal, LineStyle.Single); - + string looksLike = @" ┌────┬───┐ @@ -678,31 +724,31 @@ public void Top_Left_From_TopRigth_LeftUp () │ "; TestHelpers.AssertEqual (output, looksLike, $"{Environment.NewLine}{canvas}"); } - -// [Fact, SetupFakeDriver] -// public void LeaveMargin_Top1_Left1 () -// { -// var canvas = new LineCanvas (); - -// // Upper box -// canvas.AddLine (new Point (0, 0), 9, Orientation.Horizontal, LineStyle.Single); -// canvas.AddLine (new Point (8, 0), 3, Orientation.Vertical, LineStyle.Single); -// canvas.AddLine (new Point (8, 3), -9, Orientation.Horizontal, LineStyle.Single); -// canvas.AddLine (new Point (0, 2), -3, Orientation.Vertical, LineStyle.Single); - -// // Lower Box -// canvas.AddLine (new Point (5, 0), 2, Orientation.Vertical, LineStyle.Single); -// canvas.AddLine (new Point (0, 2), 9, Orientation.Horizontal, LineStyle.Single); - -// string looksLike = -//@" -//┌────┬──┐ -//│ │ │ -//├────┼──┤ -//└────┴──┘ -//"; -// Assert.Equal (looksLike, $"{Environment.NewLine}{canvas}"); -// } + + // [Fact, SetupFakeDriver] + // public void LeaveMargin_Top1_Left1 () + // { + // var canvas = new LineCanvas (); + + // // Upper box + // canvas.AddLine (new Point (0, 0), 9, Orientation.Horizontal, LineStyle.Single); + // canvas.AddLine (new Point (8, 0), 3, Orientation.Vertical, LineStyle.Single); + // canvas.AddLine (new Point (8, 3), -9, Orientation.Horizontal, LineStyle.Single); + // canvas.AddLine (new Point (0, 2), -3, Orientation.Vertical, LineStyle.Single); + + // // Lower Box + // canvas.AddLine (new Point (5, 0), 2, Orientation.Vertical, LineStyle.Single); + // canvas.AddLine (new Point (0, 2), 9, Orientation.Horizontal, LineStyle.Single); + + // string looksLike = + //@" + //┌────┬──┐ + //│ │ │ + //├────┼──┤ + //└────┴──┘ + //"; + // Assert.Equal (looksLike, $"{Environment.NewLine}{canvas}"); + // } [InlineData (0, 0, 0, Orientation.Horizontal, LineStyle.Double, "═")] [InlineData (0, 0, 0, Orientation.Vertical, LineStyle.Double, "║")] diff --git a/UnitTests/TestHelpers.cs b/UnitTests/TestHelpers.cs index 35830dd547..9352a805a3 100644 --- a/UnitTests/TestHelpers.cs +++ b/UnitTests/TestHelpers.cs @@ -142,14 +142,13 @@ public static void AssertDriverContentsAre (string expectedLook, ITestOutputHelp // ignore trailing whitespace on each line var trailingWhitespace = new Regex (@"\s+$", RegexOptions.Multiline); - var leadingWhitespace = new Regex(@"^\s+",RegexOptions.Multiline); + var leadingWhitespace = new Regex (@"^\s+", RegexOptions.Multiline); // get rid of trailing whitespace on each line (and leading/trailing whitespace of start/end of full string) expectedLook = trailingWhitespace.Replace (expectedLook, "").Trim (); actualLook = trailingWhitespace.Replace (actualLook, "").Trim (); - if(ignoreLeadingWhitespace) - { + if (ignoreLeadingWhitespace) { expectedLook = leadingWhitespace.Replace (expectedLook, "").Trim (); actualLook = leadingWhitespace.Replace (actualLook, "").Trim (); } @@ -327,8 +326,8 @@ private static object DescribeColor (int userExpected) public static void AssertEqual (ITestOutputHelper output, string expectedLook, string actualLook) { // Convert newlines to platform-specific newlines - expectedLook = expectedLook.Replace ("\r\n", Environment.NewLine); - + expectedLook = ReplaceNewLinesToPlatformSpecific (expectedLook); + // If test is about to fail show user what things looked like if (!string.Equals (expectedLook, actualLook)) { output?.WriteLine ("Expected:" + Environment.NewLine + expectedLook); @@ -349,10 +348,10 @@ public static void AssertEqual (ITestOutputHelper output, string expectedLook, s public static void AssertEqual (ITestOutputHelper output, string expectedLook, ustring actualLook) { // Convert newlines to platform-specific newlines - expectedLook = expectedLook.Replace ("\r\n", Environment.NewLine); + expectedLook = ReplaceNewLinesToPlatformSpecific (expectedLook); // If test is about to fail show user what things looked like - if (!string.Equals (expectedLook, actualLook)) { + if (!string.Equals (expectedLook, actualLook.ToString ())) { output?.WriteLine ("Expected:" + Environment.NewLine + expectedLook); output?.WriteLine ("But Was:" + Environment.NewLine + actualLook.ToString ()); } @@ -360,4 +359,17 @@ public static void AssertEqual (ITestOutputHelper output, string expectedLook, u Assert.Equal (expectedLook, actualLook); } #pragma warning restore xUnit1013 // Public method should be marked as test + + private static string ReplaceNewLinesToPlatformSpecific (string toReplace) + { + var replaced = toReplace; + + if (Environment.NewLine.Length == 2 && !replaced.Contains ("\r\n")) { + replaced = replaced.Replace ("\n", Environment.NewLine); + } else if (Environment.NewLine.Length == 1) { + replaced = replaced.Replace ("\r\n", Environment.NewLine); + } + + return replaced; + } } diff --git a/UnitTests/View/Layout/LayoutTests.cs b/UnitTests/View/Layout/LayoutTests.cs index 2aa966e097..cc82035c35 100644 --- a/UnitTests/View/Layout/LayoutTests.cs +++ b/UnitTests/View/Layout/LayoutTests.cs @@ -677,6 +677,10 @@ public void TextDirection_Toggle () Application.Begin (Application.Top); ((FakeDriver)Application.Driver).SetBufferSize (22, 22); + Assert.Equal (new Rect (0, 0, 22, 22), win.Frame); + Assert.Equal (new Rect (0, 0, 22, 22), win.Margin.Frame); + Assert.Equal (new Rect (0, 0, 22, 22), win.Border.Frame); + Assert.Equal (new Rect (1, 1, 20, 20), win.Padding.Frame); Assert.False (view.AutoSize); Assert.Equal (TextDirection.LeftRight_TopBottom, view.TextDirection); Assert.Equal (Rect.Empty, view.Frame); @@ -1010,15 +1014,15 @@ public void Width_Height_AutoSize_True_Stay_True_If_TextFormatter_Size_Fit () Assert.Equal (new Rect (0, 0, 9, 1), horizontalView.Frame); Assert.Equal ("Absolute(0)", horizontalView.X.ToString ()); Assert.Equal ("Absolute(0)", horizontalView.Y.ToString ()); - // BUGBUG - v2 - With v1 AutoSize = true Width/Height should always match Frame.Width/Height, + // BUGBUG - v2 - With v1 AutoSize = true Width/Height should always grow or keep initial value, // but in v2, autosize will be replaced by Dim.Fit. Disabling test for now. - //Assert.Equal ("Absolute(9)", horizontalView.Width.ToString ()); - //Assert.Equal ("Absolute(1)", horizontalView.Height.ToString ()); - //Assert.Equal (new Rect (0, 3, 2, 8), verticalView.Frame); + Assert.Equal ("Absolute(9)", horizontalView.Width.ToString ()); + Assert.Equal ("Absolute(1)", horizontalView.Height.ToString ()); + Assert.Equal (new Rect (0, 3, 2, 8), verticalView.Frame); Assert.Equal ("Absolute(0)", verticalView.X.ToString ()); Assert.Equal ("Absolute(3)", verticalView.Y.ToString ()); - //Assert.Equal ("Absolute(2)", verticalView.Width.ToString ()); - //Assert.Equal ("Absolute(8)", verticalView.Height.ToString ()); + Assert.Equal ("Absolute(2)", verticalView.Width.ToString ()); + Assert.Equal ("Absolute(8)", verticalView.Height.ToString ()); var expected = @" ┌────────────────────┐ │Finish 終 │ @@ -1051,12 +1055,12 @@ public void Width_Height_AutoSize_True_Stay_True_If_TextFormatter_Size_Fit () Application.Top.Redraw (Application.Top.Bounds); Assert.True (horizontalView.AutoSize); Assert.True (verticalView.AutoSize); - // height was initialized with 8 and is kept as minimum - Assert.Equal (new Rect (0, 3, 2, 7), verticalView.Frame); + // height was initialized with 8 and can only grow or keep initial value + Assert.Equal (new Rect (0, 3, 2, 8), verticalView.Frame); Assert.Equal ("Absolute(0)", verticalView.X.ToString ()); Assert.Equal ("Absolute(3)", verticalView.Y.ToString ()); - //Assert.Equal ("Absolute(2)", verticalView.Width.ToString ()); - //Assert.Equal ("Absolute(8)", verticalView.Height.ToString ()); + Assert.Equal ("Absolute(2)", verticalView.Width.ToString ()); + Assert.Equal ("Absolute(8)", verticalView.Height.ToString ()); expected = @" ┌────────────────────┐ │Finish 終 │ diff --git a/UnitTests/View/ViewTests.cs b/UnitTests/View/ViewTests.cs index c0628e8b92..47a4905818 100644 --- a/UnitTests/View/ViewTests.cs +++ b/UnitTests/View/ViewTests.cs @@ -1446,5 +1446,18 @@ public void Frame_Set_After_Initialize_Update_NeededDisplay () TestHelpers.AssertDriverContentsWithFrameAre (expected, output); } + [Fact] + public void Dispose_View () + { + var view = new View (); + Assert.NotNull (view.Margin); + Assert.NotNull (view.Border); + Assert.NotNull (view.Padding); + + view.Dispose (); + Assert.Null (view.Margin); + Assert.Null (view.Border); + Assert.Null (view.Padding); + } } } diff --git a/UnitTests/Views/ButtonTests.cs b/UnitTests/Views/ButtonTests.cs index 683ba229f7..00a3d06c77 100644 --- a/UnitTests/Views/ButtonTests.cs +++ b/UnitTests/Views/ButtonTests.cs @@ -24,6 +24,7 @@ public void Constructors_Defaults () Assert.Equal (TextAlignment.Centered, btn.TextAlignment); Assert.Equal ('_', btn.HotKeySpecifier); Assert.True (btn.CanFocus); + Assert.Equal (new Rect (0, 0, 4, 1), btn.Bounds); Assert.Equal (new Rect (0, 0, 4, 1), btn.Frame); Assert.Equal (Key.Null, btn.HotKey); var expected = @" @@ -31,7 +32,7 @@ [ ] "; TestHelpers.AssertDriverContentsWithFrameAre (expected, output); Application.End (rs); - + btn = new Button ("ARGS", true) { Text = "Test" }; Assert.Equal ("Test", btn.Text); Application.Top.Add (btn); @@ -42,6 +43,7 @@ [ ] Assert.Equal (TextAlignment.Centered, btn.TextAlignment); Assert.Equal ('_', btn.HotKeySpecifier); Assert.True (btn.CanFocus); + Assert.Equal (new Rect (0, 0, 10, 1), btn.Bounds); Assert.Equal (new Rect (0, 0, 10, 1), btn.Frame); Assert.Equal (Key.T, btn.HotKey); expected = @" @@ -49,7 +51,7 @@ [ ] "; TestHelpers.AssertDriverContentsWithFrameAre (expected, output); Application.End (rs); - + btn = new Button (3, 4, "Test", true); Assert.Equal ("Test", btn.Text); Application.Top.Add (btn); @@ -60,6 +62,7 @@ [ ] Assert.Equal (TextAlignment.Centered, btn.TextAlignment); Assert.Equal ('_', btn.HotKeySpecifier); Assert.True (btn.CanFocus); + Assert.Equal (new Rect (0, 0, 10, 1), btn.Bounds); Assert.Equal (new Rect (3, 4, 10, 1), btn.Frame); Assert.Equal (Key.T, btn.HotKey); expected = @" @@ -76,7 +79,7 @@ public void KeyBindings_Command () { var clicked = false; Button btn = new Button ("Test"); - btn.Clicked += (s,e) => clicked = true; + btn.Clicked += (s, e) => clicked = true; Application.Top.Add (btn); Application.Begin (Application.Top); @@ -119,7 +122,7 @@ public void ChangeHotKey () { var clicked = false; Button btn = new Button ("Test"); - btn.Clicked += (s,e) => clicked = true; + btn.Clicked += (s, e) => clicked = true; Application.Top.Add (btn); Application.Begin (Application.Top); @@ -146,7 +149,7 @@ public void KeyBindingExample () { int pressed = 0; var btn = new Button ("Press Me"); - btn.Clicked += (s,e) => pressed++; + btn.Clicked += (s, e) => pressed++; // The Button class supports the Accept command Assert.Contains (Command.Accept, btn.GetSupportedCommands ()); @@ -593,12 +596,12 @@ public void Button_HotKeyChanged_EventFires () object sender = null; KeyChangedEventArgs args = null; - btn.HotKeyChanged += (s, e) =>{ + btn.HotKeyChanged += (s, e) => { sender = s; args = e; }; - + btn.HotKey = Key.r; Assert.Same (btn, sender); Assert.Equal (Key.Y, args.OldKey);