Skip to content

Commit

Permalink
Fixed #3781
Browse files Browse the repository at this point in the history
  • Loading branch information
tig committed Oct 8, 2024
1 parent 3408c41 commit a349af0
Show file tree
Hide file tree
Showing 9 changed files with 175 additions and 164 deletions.
5 changes: 3 additions & 2 deletions Terminal.Gui/View/Adornment/Border.cs
Original file line number Diff line number Diff line change
Expand Up @@ -464,8 +464,9 @@ protected internal override bool OnMouseEvent (MouseEvent mouseEvent)
parentLoc.X - _startGrabPoint.X,
parentLoc.Y - _startGrabPoint.Y,
out int nx,
out int ny,
out _
out int ny
//,
// out _
);

Parent.X = parentLoc.X - _startGrabPoint.X;
Expand Down
47 changes: 24 additions & 23 deletions Terminal.Gui/View/View.Layout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@ public partial class View // Layout APIs
int targetX,
int targetY,
out int nx,
out int ny,
out StatusBar? statusBar
out int ny
//,
// out StatusBar? statusBar
)
{
int maxDimension;
View? superView;
statusBar = null!;
//statusBar = null!;

if (viewToMove is not Toplevel || viewToMove?.SuperView is null || viewToMove == Application.Top || viewToMove?.SuperView == Application.Top)
{
Expand Down Expand Up @@ -112,26 +113,26 @@ out StatusBar? statusBar

ny = Math.Max (targetY, maxDimension);

if (viewToMove?.SuperView is null || viewToMove == Application.Top || viewToMove?.SuperView == Application.Top)
{
statusVisible = Application.Top?.StatusBar?.Visible == true;
statusBar = Application.Top?.StatusBar!;
}
else
{
View? t = viewToMove!.SuperView;

while (t is { } and not Toplevel)
{
t = t.SuperView;
}

if (t is Toplevel topLevel)
{
statusVisible = topLevel.StatusBar?.Visible == true;
statusBar = topLevel.StatusBar!;
}
}
//if (viewToMove?.SuperView is null || viewToMove == Application.Top || viewToMove?.SuperView == Application.Top)
//{
// statusVisible = Application.Top?.StatusBar?.Visible == true;
// statusBar = Application.Top?.StatusBar!;
//}
//else
//{
// View? t = viewToMove!.SuperView;

// while (t is { } and not Toplevel)
// {
// t = t.SuperView;
// }

// if (t is Toplevel topLevel)
// {
// statusVisible = topLevel.StatusBar?.Visible == true;
// statusBar = topLevel.StatusBar!;
// }
//}

if (viewToMove?.SuperView is null || viewToMove == Application.Top || viewToMove?.SuperView == Application.Top)
{
Expand Down
31 changes: 16 additions & 15 deletions Terminal.Gui/Views/Toplevel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ public Toplevel ()
/// <summary>Gets the latest <see cref="MenuBar"/> added into this Toplevel.</summary>
public MenuBar? MenuBar => (MenuBar?)Subviews?.LastOrDefault (s => s is MenuBar);

// TODO: Deprecate - Any view can host a statusbar in v2
/// <summary>Gets the latest <see cref="StatusBar"/> added into this Toplevel.</summary>
public StatusBar? StatusBar => (StatusBar?)Subviews?.LastOrDefault (s => s is StatusBar);
//// TODO: Deprecate - Any view can host a statusbar in v2
///// <summary>Gets the latest <see cref="StatusBar"/> added into this Toplevel.</summary>
//public StatusBar? StatusBar => (StatusBar?)Subviews?.LastOrDefault (s => s is StatusBar);

#endregion

Expand Down Expand Up @@ -225,8 +225,9 @@ public virtual void PositionToplevel (Toplevel? top)
top.Frame.X,
top.Frame.Y,
out int nx,
out int ny,
out StatusBar? sb
out int ny
//,
// out StatusBar? sb
);

if (superView is null)
Expand Down Expand Up @@ -260,16 +261,16 @@ out StatusBar? sb
}
}

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

if (superView.LayoutNeeded || layoutSubviews)
{
Expand Down
22 changes: 11 additions & 11 deletions UICatalog/Scenarios/DynamicStatusBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -390,17 +390,17 @@ public DynamicStatusBarSample ()

_btnAdd.Accepting += (s, e) =>
{
if (StatusBar == null)
{
MessageBox.ErrorQuery (
"StatusBar Bar Error",
"Must add a StatusBar first!",
"Ok"
);
_btnAddStatusBar.SetFocus ();

return;
}
//if (StatusBar == null)
//{
// MessageBox.ErrorQuery (
// "StatusBar Bar Error",
// "Must add a StatusBar first!",
// "Ok"
// );
// _btnAddStatusBar.SetFocus ();

// return;
//}

var frameDetails = new DynamicStatusBarDetails ();
DynamicStatusItem item = frameDetails.EnterStatusItem ();
Expand Down
11 changes: 8 additions & 3 deletions UICatalog/Scenarios/LineViewExample.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text;
using System.Globalization;
using System.Text;
using Terminal.Gui;

namespace UICatalog.Scenarios;
Expand All @@ -24,7 +25,11 @@ public override void Main ()
};
top.Add (menu);

var appWindow = new Window ();
var appWindow = new Window ()
{
Y = 1,
Height = Dim.Fill (1) // BUGBUG: what if StatusBar is taller than 1?
};
appWindow.Add (new Label { Y = 1, Text = "Regular Line" });

// creates a horizontal line
Expand Down Expand Up @@ -79,8 +84,8 @@ public override void Main ()
new (Application.QuitKey, "Quit", Quit)
}
);
top.Add (statusBar);
top.Add (appWindow);
top.Add (statusBar);

// Run - Start the application.
Application.Run (top);
Expand Down
8 changes: 3 additions & 5 deletions UICatalog/Scenarios/ListColumns.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,6 @@ public override void Main ()
]
};

top.Add (menu);

var statusBar = new StatusBar (
new Shortcut []
{
Expand All @@ -222,8 +220,6 @@ public override void Main ()
new (Application.QuitKey, "Quit", Quit)
}
);
top.Add (statusBar);

appWindow.Add (_listColView);

var selectedCellLabel = new Label
Expand Down Expand Up @@ -256,7 +252,9 @@ public override void Main ()

_listColView.KeyBindings.ReplaceCommands (Key.Space, Command.Accept);

top.Add (appWindow);
top.Add (menu, appWindow, statusBar);
appWindow.Y = 1;
appWindow.Height = Dim.Fill(Dim.Func (() => statusBar.Frame.Height));

// Run - Start the application.
Application.Run (top);
Expand Down
13 changes: 9 additions & 4 deletions UICatalog/Scenarios/SingleBackgroundWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,17 @@ public MainApp ()
)
]
};
Add (menu);

var statusBar = new StatusBar (
[
new (Application.QuitKey, "Quit", () => Application.RequestStop ()),
new (Key.R.WithCtrl, "Run Worker", RunWorker)
]);
Add (statusBar);

var workerLogTop = new Toplevel { Title = "Worker Log Top" };
var workerLogTop = new Toplevel
{
Title = "Worker Log Top",
};

workerLogTop.Add (
new Label { X = Pos.Center (), Y = 0, Text = "Worker Log" }
Expand All @@ -81,7 +82,11 @@ public MainApp ()
Source = new ListWrapper<string> (_log)
};
workerLogTop.Add (_listLog);
Add (workerLogTop);

workerLogTop.Y = 1;
workerLogTop.Height = Dim.Fill (Dim.Func (() => statusBar.Frame.Height));

Add (menu, workerLogTop, statusBar);
Title = "MainApp";
}

Expand Down
100 changes: 50 additions & 50 deletions UnitTests/Views/StatusBarTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,55 +139,55 @@ public void StatusBar_Constructor_Default ()
Assert.Equal (1, sb.Frame.Height);
}

[Fact]
public void RemoveAndThenAddStatusBar_ShouldNotChangeWidth ()
{
StatusBar statusBar;
StatusBar statusBar2;

var w = new Window ();
statusBar2 = new StatusBar () { Id = "statusBar2" };
statusBar = new StatusBar () { Id = "statusBar" };
w.Width = Dim.Fill (0);
w.Height = Dim.Fill (0);
w.X = 0;
w.Y = 0;

w.Visible = true;
w.Modal = false;
w.Title = "";
statusBar.Width = Dim.Fill (0);
statusBar.Height = 1;
statusBar.X = 0;
statusBar.Y = 0;
statusBar.Visible = true;
w.Add (statusBar);
Assert.Equal (w.StatusBar, statusBar);

statusBar2.Width = Dim.Fill (0);
statusBar2.Height = 1;
statusBar2.X = 0;
statusBar2.Y = 4;
statusBar2.Visible = true;
w.Add (statusBar2);
Assert.Equal (w.StatusBar, statusBar2);

var menuBars = w.Subviews.OfType<StatusBar> ().ToArray ();
Assert.Equal (2, menuBars.Length);

Assert.Equal (Dim.Fill (0), menuBars [0].Width);
Assert.Equal (Dim.Fill (0), menuBars [1].Width);

// Goes wrong here
w.Remove (statusBar);
w.Remove (statusBar2);

w.Add (statusBar);
w.Add (statusBar2);

// These assertions fail
Assert.Equal (Dim.Fill (0), menuBars [0].Width);
Assert.Equal (Dim.Fill (0), menuBars [1].Width);
}
//[Fact]
//public void RemoveAndThenAddStatusBar_ShouldNotChangeWidth ()
//{
// StatusBar statusBar;
// StatusBar statusBar2;

// var w = new Window ();
// statusBar2 = new StatusBar () { Id = "statusBar2" };
// statusBar = new StatusBar () { Id = "statusBar" };
// w.Width = Dim.Fill (0);
// w.Height = Dim.Fill (0);
// w.X = 0;
// w.Y = 0;

// w.Visible = true;
// w.Modal = false;
// w.Title = "";
// statusBar.Width = Dim.Fill (0);
// statusBar.Height = 1;
// statusBar.X = 0;
// statusBar.Y = 0;
// statusBar.Visible = true;
// w.Add (statusBar);
// Assert.Equal (w.StatusBar, statusBar);

// statusBar2.Width = Dim.Fill (0);
// statusBar2.Height = 1;
// statusBar2.X = 0;
// statusBar2.Y = 4;
// statusBar2.Visible = true;
// w.Add (statusBar2);
// Assert.Equal (w.StatusBar, statusBar2);

// var menuBars = w.Subviews.OfType<StatusBar> ().ToArray ();
// Assert.Equal (2, menuBars.Length);

// Assert.Equal (Dim.Fill (0), menuBars [0].Width);
// Assert.Equal (Dim.Fill (0), menuBars [1].Width);

// // Goes wrong here
// w.Remove (statusBar);
// w.Remove (statusBar2);

// w.Add (statusBar);
// w.Add (statusBar2);

// // These assertions fail
// Assert.Equal (Dim.Fill (0), menuBars [0].Width);
// Assert.Equal (Dim.Fill (0), menuBars [1].Width);
//}

}
Loading

0 comments on commit a349af0

Please sign in to comment.