Skip to content

Commit

Permalink
More cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
tig committed Mar 18, 2023
1 parent f08e45f commit 8bd9ac7
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 31 deletions.
4 changes: 2 additions & 2 deletions Terminal.Gui/Core/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1216,7 +1216,7 @@ public static void RunMainLoopIteration (ref RunState state, bool wait, ref bool
MdiTop?.OnDeactivate (state.Toplevel);
state.Toplevel = Current;
MdiTop?.OnActivate (state.Toplevel);
Top.SetChildNeedsDisplay ();
Top.SetSubViewNeedsDisplay ();
Refresh ();
}
if (Driver.EnsureCursorVisibility ()) {
Expand Down Expand Up @@ -1280,7 +1280,7 @@ static bool MdiChildNeedsDisplay ()

foreach (var top in toplevels) {
if (top != Current && top.Visible && (!top.NeedDisplay.IsEmpty || top.ChildNeedsDisplay || top.LayoutNeeded)) {
MdiTop.SetChildNeedsDisplay ();
MdiTop.SetSubViewNeedsDisplay ();
return true;
}
}
Expand Down
16 changes: 11 additions & 5 deletions Terminal.Gui/Core/Toplevel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ internal virtual void OnAllChildClosed ()
internal virtual void OnChildClosed (Toplevel top)
{
if (IsMdiContainer) {
SetChildNeedsDisplay ();
SetSubViewNeedsDisplay ();
}
ChildClosed?.Invoke (top);
}
Expand Down Expand Up @@ -208,6 +208,10 @@ void Initialize ()
{
ColorScheme = Colors.TopLevel;

// TODO: v2 - ALL Views (Responders??!?!) should support the commands related to
// - Focus
// Move the appropriate AddCommand calls to `Responder`

// Things this view knows how to do
AddCommand (Command.QuitToplevel, () => { QuitToplevel (); return true; });
AddCommand (Command.Suspend, () => { Driver.Suspend (); ; return true; });
Expand Down Expand Up @@ -357,7 +361,7 @@ public bool IsMdiChild {

/// <summary>
/// <see langword="true"/> if was already loaded by the <see cref="Application.Begin(Toplevel)"/>
/// <see langword="false"/>, otherwise. This is used to avoid the <see cref="View.NeedDisplay"/>
/// <see langword="false"/>, otherwise. This is used to avoid the <see cref="View._needsDisplay"/>
/// having wrong values while this was not yet loaded.
/// </summary>
public bool IsLoaded { get; private set; }
Expand Down Expand Up @@ -595,7 +599,7 @@ internal void RemoveMenuStatusBar (View view)
}

internal View EnsureVisibleBounds (Toplevel top, int x, int y,
out int nx, out int ny, out View mb, out View sb)
out int nx, out int ny, out MenuBar mb, out StatusBar sb)
{
int l;
View superView;
Expand Down Expand Up @@ -668,13 +672,14 @@ internal void PositionToplevels ()
}

/// <summary>
/// Adjusts the location and size of <paramref name="top"/> within this Toplevel.
/// Virtual method enabling implementation of specific positions for inherited <see cref="Toplevel"/> views.
/// </summary>
/// <param name="top">The toplevel.</param>
/// <param name="top">The Toplevel to adjust.</param>
public virtual void PositionToplevel (Toplevel top)
{
var superView = EnsureVisibleBounds (top, top.Frame.X, top.Frame.Y,
out int nx, out int ny, out _, out View sb);
out int nx, out int ny, out _, out StatusBar sb);
bool layoutSubviews = false;
if ((top?.SuperView != null || (top != Application.Top && top.Modal)
|| (top?.SuperView == null && top.IsMdiChild))
Expand All @@ -690,6 +695,7 @@ public virtual void PositionToplevel (Toplevel top)
}
}

// TODO: v2 - This is a hack to get the StatusBar to be positioned correctly.
if (sb != null && ny + top.Frame.Height != superView.Frame.Height - (sb.Visible ? 1 : 0)
&& top.Height is Dim.DimFill && -top.Height.Anchor (0) < 1) {

Expand Down
10 changes: 5 additions & 5 deletions Terminal.Gui/Core/View.cs
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,7 @@ public void SetNeedsDisplay (Rect region)
var h = Math.Max (NeedDisplay.Height, region.Height);
NeedDisplay = new Rect (x, y, w, h);
}
container?.SetChildNeedsDisplay ();
container?.SetSubViewNeedsDisplay ();

if (subviews == null)
return;
Expand All @@ -937,11 +937,11 @@ public void SetNeedsDisplay (Rect region)
/// <summary>
/// Indicates that any child views (in the <see cref="Subviews"/> list) need to be repainted.
/// </summary>
public void SetChildNeedsDisplay ()
public void SetSubViewNeedsDisplay ()
{
ChildNeedsDisplay = true;
if (container != null)
container.SetChildNeedsDisplay ();
container.SetSubViewNeedsDisplay ();
}

internal bool addingView;
Expand Down Expand Up @@ -1547,14 +1547,14 @@ public virtual void Redraw (Rect bounds)
(!NeedDisplay.IsEmpty || ChildNeedsDisplay || LayoutNeeded)) {

Clear ();
SetChildNeedsDisplay ();
SetSubViewNeedsDisplay ();
}

if (!ustring.IsNullOrEmpty (TextFormatter.Text)) {
Rect containerBounds = GetContainerBounds ();
if (!containerBounds.IsEmpty) {
Clear (GetNeedDisplay (containerBounds));
SetChildNeedsDisplay ();
SetSubViewNeedsDisplay ();
// Draw any Text
if (TextFormatter != null) {
TextFormatter.NeedsFormat = true;
Expand Down
2 changes: 1 addition & 1 deletion Terminal.Gui/Types/Rect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public void Inflate (Size size)
///
/// <remarks>
/// Produces a new Rectangle by intersecting 2 existing
/// Rectangles. Returns null if there is no intersection.
/// Rectangles. Returns Empty if there is no intersection.
/// </remarks>

public static Rect Intersect (Rect a, Rect b)
Expand Down
16 changes: 1 addition & 15 deletions Terminal.Gui/Views/FrameView.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
//
// Authors:
// Miguel de Icaza ([email protected])
//
// NOTE: FrameView is functionally identical to Window with the following exceptions.
// - Is not a Toplevel
// - Does not support mouse dragging
// - Does not support padding (but should)
// - Does not support IEnumerable
// Any udpates done here should probably be done in Window as well; TODO: Merge these classes

using System;
using System.Linq;
using System.Linq;
using System.Text.Json.Serialization;
using NStack;
using Terminal.Gui.Graphs;
Expand Down Expand Up @@ -127,8 +115,6 @@ public ContentView () : base () { }
/// <param name="border">The <see cref="Border"/>.</param>
public FrameView (Rect frame, ustring title = null, View [] views = null, Border border = null) : base (frame)
{
//var cFrame = new Rect (1, 1, Math.Max (frame.Width - 2, 0), Math.Max (frame.Height - 2, 0));

Initialize (frame, title, views, border);
}

Expand Down
4 changes: 2 additions & 2 deletions UICatalog/UICatalog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ public UICatalogTopLevel ()
StatusBar.Visible = !StatusBar.Visible;
ContentPane.Height = Dim.Fill(StatusBar.Visible ? 1 : 0);
LayoutSubviews();
SetChildNeedsDisplay();
SetSubViewNeedsDisplay();
}),
DriverName,
OS
Expand Down Expand Up @@ -393,7 +393,7 @@ void LoadedHandler ()
var height = (StatusBar.Visible ? 1 : 0);// + (MenuBar.Visible ? 1 : 0);
ContentPane.Height = Dim.Fill (height);
LayoutSubviews ();
SetChildNeedsDisplay ();
SetSubViewNeedsDisplay ();
};

Loaded -= LoadedHandler;
Expand Down
2 changes: 1 addition & 1 deletion UnitTests/TopLevels/ToplevelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public void Internal_Tests ()
Assert.Equal (top, Application.Top);

// top is Application.Top without menu and status bar.
var supView = top.EnsureVisibleBounds (top, 2, 2, out int nx, out int ny, out View mb, out View sb);
var supView = top.EnsureVisibleBounds (top, 2, 2, out int nx, out int ny, out MenuBar mb, out StatusBar sb);
Assert.Equal (Application.Top, supView);
Assert.Equal (0, nx);
Assert.Equal (0, ny);
Expand Down

0 comments on commit 8bd9ac7

Please sign in to comment.