diff --git a/Terminal.Gui/Core/Application.cs b/Terminal.Gui/Core/Application.cs index 9526c64bb..2d27d66a3 100644 --- a/Terminal.Gui/Core/Application.cs +++ b/Terminal.Gui/Core/Application.cs @@ -118,9 +118,9 @@ namespace Terminal.Gui { if (Driver == null) { throw new ArgumentNullException ("The driver must be initialized first."); } - Driver.HeightAsBuffer = value; - } + Driver.HeightAsBuffer = value; } + } /// /// Used only by to forcing always moving the cursor position when writing to the screen. @@ -902,7 +902,7 @@ namespace Terminal.Gui { MainLoop.MainIteration (); Iteration?.Invoke (); - EnsureModalAlwaysOnTop (state.Toplevel); + EnsureModalOrVisibleAlwaysOnTop (state.Toplevel); if ((state.Toplevel != Current && Current?.Modal == true) || (state.Toplevel != Current && Current?.Modal == false)) { MdiTop?.OnDeactivate (state.Toplevel); @@ -940,9 +940,9 @@ namespace Terminal.Gui { } } - static void EnsureModalAlwaysOnTop (Toplevel toplevel) + static void EnsureModalOrVisibleAlwaysOnTop (Toplevel toplevel) { - if (!toplevel.Running || toplevel == Current || MdiTop == null || toplevels.Peek ().Modal) { + if (!toplevel.Running || (toplevel == Current && toplevel.Visible) || MdiTop == null || toplevels.Peek ().Modal) { return; } @@ -952,6 +952,9 @@ namespace Terminal.Gui { return; } } + if (!toplevel.Visible && toplevel == Current) { + MoveNext (); + } } static bool MdiChildNeedsDisplay () @@ -1200,7 +1203,14 @@ namespace Terminal.Gui { if (MdiTop != null && !Current.Modal) { lock (toplevels) { toplevels.MoveNext (); + var isMdi = false; while (toplevels.Peek () == MdiTop || !toplevels.Peek ().Visible) { + if (!isMdi && toplevels.Peek () == MdiTop) { + isMdi = true; + } else if (isMdi && toplevels.Peek () == MdiTop) { + MoveCurrent (Top); + break; + } toplevels.MoveNext (); } Current = toplevels.Peek (); @@ -1216,10 +1226,15 @@ namespace Terminal.Gui { if (MdiTop != null && !Current.Modal) { lock (toplevels) { toplevels.MovePrevious (); + var isMdi = false; while (toplevels.Peek () == MdiTop || !toplevels.Peek ().Visible) { - lock (toplevels) { - toplevels.MovePrevious (); + if (!isMdi && toplevels.Peek () == MdiTop) { + isMdi = true; + } else if (isMdi && toplevels.Peek () == MdiTop) { + MoveCurrent (Top); + break; } + toplevels.MovePrevious (); } Current = toplevels.Peek (); } diff --git a/Terminal.Gui/Core/View.cs b/Terminal.Gui/Core/View.cs index e53a85c51..d13f8d38b 100644 --- a/Terminal.Gui/Core/View.cs +++ b/Terminal.Gui/Core/View.cs @@ -1394,7 +1394,7 @@ namespace Terminal.Gui { if (textFormatter != null) { textFormatter.NeedsFormat = true; } - textFormatter?.Draw (ViewToScreen (Bounds), HasFocus ? ColorScheme.Focus : GetNormalColor (), + textFormatter?.Draw (ViewToScreen (bounds), HasFocus ? ColorScheme.Focus : GetNormalColor (), HasFocus ? ColorScheme.HotFocus : Enabled ? ColorScheme.HotNormal : ColorScheme.Disabled); } @@ -1411,8 +1411,14 @@ namespace Terminal.Gui { // Draw the subview // Use the view's bounds (view-relative; Location will always be (0,0) if (view.Visible && view.Frame.Width > 0 && view.Frame.Height > 0) { - view.OnDrawContent (view.Bounds); - view.Redraw (view.Bounds); + var rect = new Rect () { + X = Math.Min (view.Bounds.X, view.NeedDisplay.X), + Y = Math.Min (view.Bounds.Y, view.NeedDisplay.Y), + Width = Math.Max (view.Bounds.Width, view.NeedDisplay.Width), + Height = Math.Max (view.Bounds.Height, view.NeedDisplay.Height) + }; + view.OnDrawContent (rect); + view.Redraw (rect); } } view.NeedDisplay = Rect.Empty; @@ -2081,6 +2087,7 @@ namespace Terminal.Gui { get => textFormatter.Text; set { textFormatter.Text = value; + var prevSize = frame.Size; var canResize = ResizeView (autoSize); if (canResize && textFormatter.Size != Bounds.Size) { Bounds = new Rect (new Point (Bounds.X, Bounds.Y), textFormatter.Size); @@ -2088,7 +2095,8 @@ namespace Terminal.Gui { textFormatter.Size = Bounds.Size; } SetNeedsLayout (); - SetNeedsDisplay (); + SetNeedsDisplay (new Rect (new Point (0, 0), + new Size (Math.Max (frame.Width, prevSize.Width), Math.Max (frame.Height, prevSize.Height)))); } }