From 22475fad2f36f1929af0c47068f61911483446fb Mon Sep 17 00:00:00 2001 From: BDisp Date: Thu, 14 May 2020 18:30:08 +0100 Subject: [PATCH] Corrects the position of the StatusBar so that it is always at the bottom of the screen. Works perfectly with curses. --- Terminal.Gui/Core.cs | 36 +++++++++++++++++++-------------- Terminal.Gui/Views/StatusBar.cs | 15 +++++++++----- 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/Terminal.Gui/Core.cs b/Terminal.Gui/Core.cs index 91135771e..2d3c1d6b2 100644 --- a/Terminal.Gui/Core.cs +++ b/Terminal.Gui/Core.cs @@ -1522,12 +1522,12 @@ namespace Terminal.Gui { /// /// Check id current toplevel has menu bar /// - public bool HasMenuBar { get; set; } + public MenuBar MenuBar { get; set; } /// /// Check id current toplevel has status bar /// - public bool HasStatusBar { get; set; } + public StatusBar StatusBar { get; set; } public override bool ProcessKey (KeyEvent keyEvent) { @@ -1584,9 +1584,9 @@ namespace Terminal.Gui { { if (this == Application.Top) { if (view is MenuBar) - HasMenuBar = true; + MenuBar = view as MenuBar; if (view is StatusBar) - HasStatusBar = true; + StatusBar = view as StatusBar; } base.Add (view); } @@ -1595,9 +1595,9 @@ namespace Terminal.Gui { { if (this == Application.Top) { if (view is MenuBar) - HasMenuBar = true; + MenuBar = null; if (view is StatusBar) - HasStatusBar = true; + StatusBar = null; } base.Remove (view); } @@ -1605,8 +1605,8 @@ namespace Terminal.Gui { public override void RemoveAll () { if (this == Application.Top) { - HasMenuBar = false; - HasStatusBar = false; + MenuBar = null; + StatusBar = null; } base.RemoveAll (); } @@ -1617,15 +1617,15 @@ namespace Terminal.Gui { nx = nx + top.Frame.Width > Driver.Cols ? Math.Max(Driver.Cols - top.Frame.Width, 0) : nx; bool m, s; if (SuperView == null) - m = Application.Top.HasMenuBar; + m = Application.Top.MenuBar != null; else - m = ((Toplevel)SuperView).HasMenuBar; + m = ((Toplevel)SuperView).MenuBar != null; int l = m ? 1 : 0; ny = Math.Max (y, l); if (SuperView == null) - s = Application.Top.HasStatusBar; + s = Application.Top.StatusBar != null; else - s = ((Toplevel)SuperView).HasStatusBar; + s = ((Toplevel)SuperView).StatusBar != null; l = s ? Driver.Rows - 1 : Driver.Rows; ny = Math.Min (ny, l); ny = ny + top.Frame.Height > l ? Math.Max(l - top.Frame.Height, m ? 1 : 0) : ny; @@ -1647,9 +1647,15 @@ namespace Terminal.Gui { top.X = nx; top.Y = ny; } - if (HasStatusBar && ny + top.Frame.Height > Driver.Rows - 1) { - if (top.Height is Dim.DimFill) - top.Height = Dim.Fill () - 1; + if (StatusBar != null) { + if (ny + top.Frame.Height > Driver.Rows - 1) { + if (top.Height is Dim.DimFill) + top.Height = Dim.Fill () - 1; + } + if (StatusBar.Frame.Y != Driver.Rows - 1) { + StatusBar.Y = Driver.Rows - 1; + SetNeedsDisplay (); + } } } } diff --git a/Terminal.Gui/Views/StatusBar.cs b/Terminal.Gui/Views/StatusBar.cs index fe1573a91..904072021 100644 --- a/Terminal.Gui/Views/StatusBar.cs +++ b/Terminal.Gui/Views/StatusBar.cs @@ -101,7 +101,12 @@ namespace Terminal.Gui { Items = items; CanFocus = false; ColorScheme = Colors.Menu; + X = 0; + Y = Driver.Rows - 1; + Width = Dim.Fill (); + Height = 1; + // This is never called if it is invoked later on another place. Application.OnLoad += () => { X = 0; Height = 1; @@ -134,11 +139,11 @@ namespace Terminal.Gui { public override void Redraw (Rect region) { - if (Frame.Y != Driver.Rows - 1) { - Frame = new Rect (Frame.X, Driver.Rows - 1, Frame.Width, Frame.Height); - Y = Driver.Rows - 1; - SetNeedsDisplay (); - } + //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 (ColorScheme.Normal);