From 9e44f0183aa522f93afe72d16f855eb97c6a533c Mon Sep 17 00:00:00 2001 From: BDisp Date: Thu, 17 Nov 2022 16:59:43 +0000 Subject: [PATCH] Fixes #2226. StatusBar misplaced when window maximized (and occasionally on resize). --- Terminal.Gui/Views/StatusBar.cs | 49 +------------------ UnitTests/StatusBarTests.cs | 7 ++- UnitTests/WindowTests.cs | 83 +++++++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+), 52 deletions(-) diff --git a/Terminal.Gui/Views/StatusBar.cs b/Terminal.Gui/Views/StatusBar.cs index f8db8920c..69bc0af63 100644 --- a/Terminal.Gui/Views/StatusBar.cs +++ b/Terminal.Gui/Views/StatusBar.cs @@ -87,39 +87,9 @@ namespace Terminal.Gui { CanFocus = false; ColorScheme = Colors.Menu; X = 0; + Y = Pos.AnchorEnd (1); Width = Dim.Fill (); Height = 1; - - Initialized += StatusBar_Initialized; - Application.Resized += Application_Resized (); - } - - private void StatusBar_Initialized (object sender, EventArgs e) - { - if (SuperView.Frame == Rect.Empty) { - ((Toplevel)SuperView).Loaded += StatusBar_Loaded; - } else { - Y = Math.Max (SuperView.Frame.Height - (Visible ? 1 : 0), 0); - } - } - - private void StatusBar_Loaded () - { - Y = Math.Max (SuperView.Frame.Height - (Visible ? 1 : 0), 0); - ((Toplevel)SuperView).Loaded -= StatusBar_Loaded; - } - - private Action Application_Resized () - { - return delegate { - X = 0; - Height = 1; - if (SuperView != null || SuperView is Toplevel) { - if (Frame.Y != SuperView.Frame.Height - (Visible ? 1 : 0)) { - Y = SuperView.Frame.Height - (Visible ? 1 : 0); - } - } - }; } static ustring shortcutDelimiter = "-"; @@ -145,12 +115,6 @@ namespace Terminal.Gui { /// public override void Redraw (Rect bounds) { - //if (Frame.Y != Driver.Rows - 1) { - // Frame = new Rect (Frame.X, Driver.Rows - 1, Frame.Width, Frame.Height); - // Y = Driver.Rows - 1; - // SetNeedsDisplay (); - //} - Move (0, 0); Driver.SetAttribute (GetNormalColor ()); for (int i = 0; i < Frame.Width; i++) @@ -228,17 +192,6 @@ namespace Terminal.Gui { }); } - /// - protected override void Dispose (bool disposing) - { - if (!disposedValue) { - if (disposing) { - Application.Resized -= Application_Resized (); - } - disposedValue = true; - } - } - /// public override bool OnEnter (View view) { diff --git a/UnitTests/StatusBarTests.cs b/UnitTests/StatusBarTests.cs index 7e524bf17..ee303d22d 100644 --- a/UnitTests/StatusBarTests.cs +++ b/UnitTests/StatusBarTests.cs @@ -31,11 +31,10 @@ namespace Terminal.Gui.Views { Assert.False (sb.CanFocus); Assert.Equal (Colors.Menu, sb.ColorScheme); Assert.Equal (0, sb.X); + Assert.Equal ("Pos.AnchorEnd(margin=1)", sb.Y.ToString ()); Assert.Equal (Dim.Fill (), sb.Width); Assert.Equal (1, sb.Height); - Assert.Null (sb.Y); - var driver = new FakeDriver (); Application.Init (driver, new FakeMainLoop (() => FakeConsole.ReadKey (true))); @@ -47,11 +46,11 @@ namespace Terminal.Gui.Views { Assert.True (FakeConsole.CursorVisible); Application.Iteration += () => { - Assert.Equal (24, sb.Y); + Assert.Equal (24, sb.Frame.Y); driver.SetWindowSize (driver.Cols, 15); - Assert.Equal (14, sb.Y); + Assert.Equal (14, sb.Frame.Y); sb.OnEnter (null); driver.GetCursorVisibility (out cv); diff --git a/UnitTests/WindowTests.cs b/UnitTests/WindowTests.cs index 4c5778f48..d296ba178 100644 --- a/UnitTests/WindowTests.cs +++ b/UnitTests/WindowTests.cs @@ -153,5 +153,88 @@ namespace Terminal.Gui.Core { Assert.Equal (expected, r.Title.ToString ()); r.Dispose (); } + + [Fact,AutoInitShutdown] + public void MenuBar_And_StatusBar_Inside_Window () + { + var menu = new MenuBar (new MenuBarItem [] { + new MenuBarItem ("File", new MenuItem [] { + new MenuItem ("Open", "", null), + new MenuItem ("Quit", "", null), + }), + new MenuBarItem ("Edit", new MenuItem [] { + new MenuItem ("Copy", "", null), + }) + }); + + var sb = new StatusBar (new StatusItem [] { + new StatusItem (Key.CtrlMask | Key.Q, "~^Q~ Quit", null), + new StatusItem (Key.CtrlMask | Key.O, "~^O~ Open", null), + new StatusItem (Key.CtrlMask | Key.C, "~^C~ Copy", null), + }); + + var fv = new FrameView ("Frame View") { + Y = 1, + Width = Dim.Fill(), + Height = Dim.Fill (1) + }; + var win = new Window (); + win.Add (menu, sb, fv); + var top = Application.Top; + top.Add (win); + Application.Begin (top); + ((FakeDriver)Application.Driver).SetBufferSize (20, 10); + + TestHelpers.AssertDriverContentsWithFrameAre (@" +┌──────────────────┐ +│ File Edit │ +│┌ Frame View ────┐│ +││ ││ +││ ││ +││ ││ +││ ││ +│└────────────────┘│ +│ ^Q Quit │ ^O Open│ +└──────────────────┘", output); + + ((FakeDriver)Application.Driver).SetBufferSize (40, 20); + + TestHelpers.AssertDriverContentsWithFrameAre (@" +┌──────────────────────────────────────┐ +│ File Edit │ +│┌ Frame View ────────────────────────┐│ +││ ││ +││ ││ +││ ││ +││ ││ +││ ││ +││ ││ +││ ││ +││ ││ +││ ││ +││ ││ +││ ││ +││ ││ +││ ││ +││ ││ +│└────────────────────────────────────┘│ +│ ^Q Quit │ ^O Open │ ^C Copy │ +└──────────────────────────────────────┘", output); + + ((FakeDriver)Application.Driver).SetBufferSize (20, 10); + + TestHelpers.AssertDriverContentsWithFrameAre (@" +┌──────────────────┐ +│ File Edit │ +│┌ Frame View ────┐│ +││ ││ +││ ││ +││ ││ +││ ││ +│└────────────────┘│ +│ ^Q Quit │ ^O Open│ +└──────────────────┘", output); + + } } }