mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2026-01-01 16:59:35 +01:00
Merge pull request #1634 from BDisp/UseSubMenusSingleFrame-feature
Feature to display the sub-menus on a single frame instead multiple frames.
This commit is contained in:
@@ -42,7 +42,7 @@ namespace Terminal.Gui.Core {
|
||||
new MenuItem ("Two", "", null)
|
||||
})
|
||||
);
|
||||
Assert.Equal (new Point (6, 10), cm.Position);
|
||||
Assert.Equal (new Point (5, 10), cm.Position);
|
||||
Assert.Equal (2, cm.MenuItens.Children.Length);
|
||||
Assert.NotNull (cm.Host);
|
||||
}
|
||||
@@ -269,8 +269,8 @@ namespace Terminal.Gui.Core {
|
||||
└──────┘
|
||||
";
|
||||
|
||||
var pos = GraphViewTests.AssertDriverContentsWithPosAre (expected, output);
|
||||
Assert.Equal (new Point (72, 21), pos);
|
||||
var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
||||
Assert.Equal (new Rect (72, 21, 80, 4), pos);
|
||||
|
||||
cm.Hide ();
|
||||
Assert.Equal (new Point (80, 25), cm.Position);
|
||||
@@ -279,64 +279,100 @@ namespace Terminal.Gui.Core {
|
||||
[Fact, AutoInitShutdown]
|
||||
public void Show_Ensures_Display_Inside_The_Container_Without_Overlap_The_Host ()
|
||||
{
|
||||
var cm = new ContextMenu (new View () { X = 69, Y = 24, Width = 10, Height = 1 },
|
||||
var view = new View ("View") {
|
||||
X = Pos.AnchorEnd (10),
|
||||
Y = Pos.AnchorEnd (1),
|
||||
Width = 10,
|
||||
Height = 1
|
||||
};
|
||||
var cm = new ContextMenu (view,
|
||||
new MenuBarItem (new MenuItem [] {
|
||||
new MenuItem ("One", "", null),
|
||||
new MenuItem ("Two", "", null)
|
||||
})
|
||||
);
|
||||
|
||||
Assert.Equal (new Point (70, 25), cm.Position);
|
||||
Application.Top.Add (view);
|
||||
Application.Begin (Application.Top);
|
||||
|
||||
Assert.Equal (new Rect (70, 24, 10, 1), view.Frame);
|
||||
Assert.Equal (new Point (0, 0), cm.Position);
|
||||
|
||||
cm.Show ();
|
||||
Assert.Equal (new Point (70, 25), cm.Position);
|
||||
Application.Begin (Application.Top);
|
||||
Assert.Equal (new Point (70, 24), cm.Position);
|
||||
Application.Top.Redraw (Application.Top.Bounds);
|
||||
|
||||
var expected = @"
|
||||
┌──────┐
|
||||
│ One │
|
||||
│ Two │
|
||||
└──────┘
|
||||
View
|
||||
";
|
||||
|
||||
var pos = GraphViewTests.AssertDriverContentsWithPosAre (expected, output);
|
||||
Assert.Equal (new Point (70, 21), pos);
|
||||
var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
||||
Assert.Equal (new Rect (70, 20, 78, 5), pos);
|
||||
|
||||
cm.Hide ();
|
||||
Assert.Equal (new Point (70, 25), cm.Position);
|
||||
Assert.Equal (new Point (70, 24), cm.Position);
|
||||
}
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
public void Show_Display_Below_The_Bottom_Host_If_Has_Enough_Space ()
|
||||
{
|
||||
var cm = new ContextMenu (new View () { X = 10, Y = 5, Width = 10, Height = 1 },
|
||||
var view = new View ("View") { X = 10, Y = 5, Width = 10, Height = 1 };
|
||||
var cm = new ContextMenu (view,
|
||||
new MenuBarItem (new MenuItem [] {
|
||||
new MenuItem ("One", "", null),
|
||||
new MenuItem ("Two", "", null)
|
||||
})
|
||||
);
|
||||
|
||||
Assert.Equal (new Point (11, 6), cm.Position);
|
||||
|
||||
cm.Host.X = 5;
|
||||
cm.Host.Y = 10;
|
||||
|
||||
cm.Show ();
|
||||
Assert.Equal (new Point (6, 11), cm.Position);
|
||||
Application.Top.Add (view);
|
||||
Application.Begin (Application.Top);
|
||||
|
||||
Assert.Equal (new Point (10, 5), cm.Position);
|
||||
|
||||
cm.Show ();
|
||||
Application.Top.Redraw (Application.Top.Bounds);
|
||||
Assert.Equal (new Point (10, 5), cm.Position);
|
||||
|
||||
var expected = @"
|
||||
┌──────┐
|
||||
│ One │
|
||||
│ Two │
|
||||
└──────┘
|
||||
View
|
||||
┌──────┐
|
||||
│ One │
|
||||
│ Two │
|
||||
└──────┘
|
||||
";
|
||||
|
||||
var pos = GraphViewTests.AssertDriverContentsWithPosAre (expected, output);
|
||||
Assert.Equal (new Point (6, 12), pos);
|
||||
var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
||||
Assert.Equal (new Rect (10, 5, 18, 5), pos);
|
||||
|
||||
cm.Hide ();
|
||||
Assert.Equal (new Point (6, 11), cm.Position);
|
||||
Assert.Equal (new Point (10, 5), cm.Position);
|
||||
cm.Host.X = 5;
|
||||
cm.Host.Y = 10;
|
||||
cm.Host.Height = 3;
|
||||
|
||||
cm.Show ();
|
||||
Application.Top.Redraw (Application.Top.Bounds);
|
||||
Assert.Equal (new Point (5, 12), cm.Position);
|
||||
|
||||
expected = @"
|
||||
View
|
||||
|
||||
|
||||
┌──────┐
|
||||
│ One │
|
||||
│ Two │
|
||||
└──────┘
|
||||
";
|
||||
|
||||
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
||||
Assert.Equal (new Rect (5, 10, 13, 7), pos);
|
||||
|
||||
cm.Hide ();
|
||||
Assert.Equal (new Point (5, 12), cm.Position);
|
||||
}
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
@@ -363,8 +399,8 @@ namespace Terminal.Gui.Core {
|
||||
└────
|
||||
";
|
||||
|
||||
var pos = GraphViewTests.AssertDriverContentsWithPosAre (expected, output);
|
||||
Assert.Equal (new Point (0, 1), pos);
|
||||
var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
||||
Assert.Equal (new Rect (0, 1, 5, 4), pos);
|
||||
|
||||
cm.Hide ();
|
||||
Assert.Equal (new Point (0, 0), cm.Position);
|
||||
@@ -393,8 +429,8 @@ namespace Terminal.Gui.Core {
|
||||
│ Two │
|
||||
";
|
||||
|
||||
var pos = GraphViewTests.AssertDriverContentsWithPosAre (expected, output);
|
||||
Assert.Equal (new Point (0, 1), pos);
|
||||
var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
||||
Assert.Equal (new Rect (0, 1, 8, 3), pos);
|
||||
|
||||
cm.Hide ();
|
||||
Assert.Equal (new Point (0, 0), cm.Position);
|
||||
@@ -446,8 +482,8 @@ namespace Terminal.Gui.Core {
|
||||
└──────┘
|
||||
";
|
||||
|
||||
var pos = GraphViewTests.AssertDriverContentsWithPosAre (expected, output);
|
||||
Assert.Equal (new Point (0, 1), pos);
|
||||
var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
||||
Assert.Equal (new Rect (0, 1, 8, 4), pos);
|
||||
|
||||
cm.ForceMinimumPosToZero = false;
|
||||
cm.Show ();
|
||||
@@ -460,8 +496,8 @@ namespace Terminal.Gui.Core {
|
||||
──────┘
|
||||
";
|
||||
|
||||
pos = GraphViewTests.AssertDriverContentsWithPosAre (expected, output);
|
||||
Assert.Equal (new Point (1, 0), pos);
|
||||
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
||||
Assert.Equal (new Rect (1, 0, 7, 3), pos);
|
||||
}
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
@@ -515,5 +551,127 @@ namespace Terminal.Gui.Core {
|
||||
Assert.Equal (menu, Application.mouseGrabView);
|
||||
Assert.True (menu.IsMenuOpen);
|
||||
}
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
public void ContextMenu_On_Toplevel_With_A_MenuBar_TextField_StatusBar ()
|
||||
{
|
||||
var menu = new MenuBar (new MenuBarItem [] {
|
||||
new MenuBarItem ("File", "", null),
|
||||
new MenuBarItem ("Edit", "", null)
|
||||
});
|
||||
|
||||
var label = new Label ("Label:") {
|
||||
X = 2,
|
||||
Y = 3
|
||||
};
|
||||
|
||||
var tf = new TextField ("TextField") {
|
||||
X = Pos.Right (label) + 1,
|
||||
Y = Pos.Top (label),
|
||||
Width = 20
|
||||
};
|
||||
|
||||
var statusBar = new StatusBar (new StatusItem [] {
|
||||
new StatusItem(Key.F1, "~F1~ Help", null),
|
||||
new StatusItem(Key.CtrlMask | Key.Q, "~^Q~ Quit", null)
|
||||
});
|
||||
|
||||
Application.Top.Add (menu, label, tf, statusBar);
|
||||
Application.Begin (Application.Top);
|
||||
((FakeDriver)Application.Driver).SetBufferSize (45, 17);
|
||||
|
||||
Assert.Equal (new Rect (9, 3, 20, 1), tf.Frame);
|
||||
Assert.True (tf.HasFocus);
|
||||
|
||||
tf.ContextMenu.Show ();
|
||||
Assert.True (ContextMenu.IsShow);
|
||||
Assert.Equal (new Point (9, 3), tf.ContextMenu.Position);
|
||||
Application.Top.Redraw (Application.Top.Bounds);
|
||||
var expected = @"
|
||||
File Edit
|
||||
|
||||
|
||||
Label: TextField
|
||||
┌────────────────────────────┐
|
||||
│ Select All Ctrl+T │
|
||||
│ Delete All Ctrl+Shift+D │
|
||||
│ Copy Ctrl+C │
|
||||
│ Cut Ctrl+X │
|
||||
│ Paste Ctrl+V │
|
||||
│ Undo Ctrl+Z │
|
||||
│ Redo Ctrl+Y │
|
||||
└────────────────────────────┘
|
||||
|
||||
|
||||
|
||||
F1 Help │ ^Q Quit
|
||||
";
|
||||
|
||||
var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
||||
Assert.Equal (new Rect (2, 0, 39, 17), pos);
|
||||
}
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
public void ContextMenu_On_Toplevel_With_A_MenuBar_Window_TextField_StatusBar ()
|
||||
{
|
||||
var menu = new MenuBar (new MenuBarItem [] {
|
||||
new MenuBarItem ("File", "", null),
|
||||
new MenuBarItem ("Edit", "", null)
|
||||
});
|
||||
|
||||
var label = new Label ("Label:") {
|
||||
X = 2,
|
||||
Y = 3
|
||||
};
|
||||
|
||||
var tf = new TextField ("TextField") {
|
||||
X = Pos.Right (label) + 1,
|
||||
Y = Pos.Top (label),
|
||||
Width = 20
|
||||
};
|
||||
|
||||
var win = new Window ("Window");
|
||||
win.Add (label, tf);
|
||||
|
||||
var statusBar = new StatusBar (new StatusItem [] {
|
||||
new StatusItem(Key.F1, "~F1~ Help", null),
|
||||
new StatusItem(Key.CtrlMask | Key.Q, "~^Q~ Quit", null)
|
||||
});
|
||||
|
||||
Application.Top.Add (menu, win, statusBar);
|
||||
Application.Begin (Application.Top);
|
||||
((FakeDriver)Application.Driver).SetBufferSize (45, 17);
|
||||
|
||||
|
||||
Assert.Equal (new Rect (9, 3, 20, 1), tf.Frame);
|
||||
Assert.True (tf.HasFocus);
|
||||
|
||||
tf.ContextMenu.Show ();
|
||||
Assert.True (ContextMenu.IsShow);
|
||||
Assert.Equal (new Point (10, 5), tf.ContextMenu.Position);
|
||||
Application.Top.Redraw (Application.Top.Bounds);
|
||||
var expected = @"
|
||||
File Edit
|
||||
┌ Window ───────────────────────────────────┐
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ Label: TextField │
|
||||
│ ┌────────────────────────────┐ │
|
||||
│ │ Select All Ctrl+T │ │
|
||||
│ │ Delete All Ctrl+Shift+D │ │
|
||||
│ │ Copy Ctrl+C │ │
|
||||
│ │ Cut Ctrl+X │ │
|
||||
│ │ Paste Ctrl+V │ │
|
||||
│ │ Undo Ctrl+Z │ │
|
||||
│ │ Redo Ctrl+Y │ │
|
||||
│ └────────────────────────────┘ │
|
||||
└───────────────────────────────────────────┘
|
||||
F1 Help │ ^Q Quit
|
||||
";
|
||||
|
||||
var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
||||
Assert.Equal (new Rect (2, 0, 45, 17), pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,40 +11,40 @@ using System.Text.RegularExpressions;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace Terminal.Gui.Views {
|
||||
|
||||
|
||||
#region Helper Classes
|
||||
class FakeHAxis : HorizontalAxis {
|
||||
|
||||
public List<Point> DrawAxisLinePoints = new List<Point> ();
|
||||
public List<int> LabelPoints = new List<int>();
|
||||
public List<int> LabelPoints = new List<int> ();
|
||||
|
||||
protected override void DrawAxisLine (GraphView graph, int x, int y)
|
||||
{
|
||||
base.DrawAxisLine (graph, x, y);
|
||||
DrawAxisLinePoints.Add (new Point(x, y));
|
||||
DrawAxisLinePoints.Add (new Point (x, y));
|
||||
}
|
||||
|
||||
public override void DrawAxisLabel (GraphView graph, int screenPosition, string text)
|
||||
{
|
||||
base.DrawAxisLabel (graph, screenPosition, text);
|
||||
LabelPoints.Add(screenPosition);
|
||||
LabelPoints.Add (screenPosition);
|
||||
}
|
||||
}
|
||||
|
||||
class FakeVAxis : VerticalAxis {
|
||||
|
||||
public List<Point> DrawAxisLinePoints = new List<Point> ();
|
||||
public List<int> LabelPoints = new List<int>();
|
||||
public List<int> LabelPoints = new List<int> ();
|
||||
|
||||
protected override void DrawAxisLine (GraphView graph, int x, int y)
|
||||
{
|
||||
base.DrawAxisLine (graph, x, y);
|
||||
DrawAxisLinePoints.Add (new Point(x, y));
|
||||
DrawAxisLinePoints.Add (new Point (x, y));
|
||||
}
|
||||
public override void DrawAxisLabel (GraphView graph, int screenPosition, string text)
|
||||
{
|
||||
base.DrawAxisLabel (graph, screenPosition, text);
|
||||
LabelPoints.Add(screenPosition);
|
||||
LabelPoints.Add (screenPosition);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
@@ -99,13 +99,13 @@ namespace Terminal.Gui.Views {
|
||||
if (!string.Equals (expectedLook, actualLook)) {
|
||||
|
||||
// ignore trailing whitespace on each line
|
||||
var trailingWhitespace = new Regex (@"\s+$",RegexOptions.Multiline);
|
||||
|
||||
var trailingWhitespace = new Regex (@"\s+$", RegexOptions.Multiline);
|
||||
|
||||
// get rid of trailing whitespace on each line (and leading/trailing whitespace of start/end of full string)
|
||||
expectedLook = trailingWhitespace.Replace(expectedLook,"").Trim();
|
||||
expectedLook = trailingWhitespace.Replace (expectedLook, "").Trim ();
|
||||
actualLook = trailingWhitespace.Replace (actualLook, "").Trim ();
|
||||
|
||||
// standardise line endings for the comparison
|
||||
// standardize line endings for the comparison
|
||||
expectedLook = expectedLook.Replace ("\r\n", "\n");
|
||||
actualLook = actualLook.Replace ("\r\n", "\n");
|
||||
|
||||
@@ -116,48 +116,92 @@ namespace Terminal.Gui.Views {
|
||||
}
|
||||
}
|
||||
|
||||
public static Point AssertDriverContentsWithPosAre (string expectedLook, ITestOutputHelper output)
|
||||
public static Rect AssertDriverContentsWithFrameAre (string expectedLook, ITestOutputHelper output)
|
||||
{
|
||||
var lines = new List<List<char>> ();
|
||||
var sb = new StringBuilder ();
|
||||
var driver = ((FakeDriver)Application.Driver);
|
||||
var x = -1;
|
||||
var y = -1;
|
||||
int w = -1;
|
||||
int h = -1;
|
||||
|
||||
var contents = driver.Contents;
|
||||
|
||||
for (int r = 0; r < driver.Rows; r++) {
|
||||
var runes = new List<char> ();
|
||||
for (int c = 0; c < driver.Cols; c++) {
|
||||
var rune = (char)contents [r, c, 0];
|
||||
if (x == -1 && rune != ' ') {
|
||||
x = c;
|
||||
y = r;
|
||||
if (rune != ' ') {
|
||||
if (x == -1) {
|
||||
x = c;
|
||||
y = r;
|
||||
for (int i = 0; i < c; i++) {
|
||||
runes.InsertRange (i, new List<char> () { ' ' });
|
||||
}
|
||||
}
|
||||
if (c > w) {
|
||||
w = c;
|
||||
}
|
||||
h = r - y;
|
||||
}
|
||||
if (x > -1) {
|
||||
runes.Add (rune);
|
||||
}
|
||||
sb.Append (rune);
|
||||
}
|
||||
sb.AppendLine ();
|
||||
if (runes.Count > 0) {
|
||||
lines.Add (runes);
|
||||
}
|
||||
}
|
||||
|
||||
// Remove unnecessary empty lines
|
||||
for (int r = lines.Count - 1; r > h; r--) {
|
||||
lines.RemoveAt (r);
|
||||
}
|
||||
|
||||
// Remove trailing whitespace on each line
|
||||
for (int r = 0; r < lines.Count; r++) {
|
||||
List<char> row = lines [r];
|
||||
for (int c = row.Count - 1; c >= 0; c--) {
|
||||
if (row [c] != ' ') {
|
||||
break;
|
||||
}
|
||||
row.RemoveAt (c);
|
||||
}
|
||||
}
|
||||
|
||||
// Convert char list to string
|
||||
for (int r = 0; r < lines.Count; r++) {
|
||||
var line = new string (lines [r].ToArray ());
|
||||
if (r == lines.Count - 1) {
|
||||
sb.Append (line);
|
||||
} else {
|
||||
sb.AppendLine (line);
|
||||
}
|
||||
}
|
||||
|
||||
var actualLook = sb.ToString ();
|
||||
|
||||
if (!string.Equals (expectedLook, actualLook)) {
|
||||
|
||||
// ignore trailing whitespace on each line
|
||||
var trailingWhitespace = new Regex (@"\s+$", RegexOptions.Multiline);
|
||||
|
||||
// get rid of trailing whitespace on each line (and leading/trailing whitespace of start/end of full string)
|
||||
expectedLook = trailingWhitespace.Replace (expectedLook, "").Trim ();
|
||||
actualLook = trailingWhitespace.Replace (actualLook, "").Trim ();
|
||||
|
||||
// standardise line endings for the comparison
|
||||
// standardize line endings for the comparison
|
||||
expectedLook = expectedLook.Replace ("\r\n", "\n");
|
||||
actualLook = actualLook.Replace ("\r\n", "\n");
|
||||
|
||||
// Remove the first and the last line ending from the expectedLook
|
||||
if (expectedLook.StartsWith ("\n")) {
|
||||
expectedLook = expectedLook [1..];
|
||||
}
|
||||
if (expectedLook.EndsWith ("\n")) {
|
||||
expectedLook = expectedLook [..^1];
|
||||
}
|
||||
|
||||
output?.WriteLine ("Expected:" + Environment.NewLine + expectedLook);
|
||||
output?.WriteLine ("But Was:" + Environment.NewLine + actualLook);
|
||||
|
||||
Assert.Equal (expectedLook, actualLook);
|
||||
}
|
||||
return new Point (x, y);
|
||||
return new Rect (x, y, w > -1 ? w + 1 : 0, h > -1 ? h + 1 : 0);
|
||||
}
|
||||
|
||||
#pragma warning disable xUnit1013 // Public method should be marked as test
|
||||
@@ -168,11 +212,11 @@ namespace Terminal.Gui.Views {
|
||||
/// </summary>
|
||||
/// <param name="expectedLook">Numbers between 0 and 9 for each row/col of the console. Must be valid indexes of <paramref name="expectedColors"/></param>
|
||||
/// <param name="expectedColors"></param>
|
||||
public static void AssertDriverColorsAre (string expectedLook, Attribute[] expectedColors)
|
||||
public static void AssertDriverColorsAre (string expectedLook, Attribute [] expectedColors)
|
||||
{
|
||||
#pragma warning restore xUnit1013 // Public method should be marked as test
|
||||
|
||||
if(expectedColors.Length > 10) {
|
||||
if (expectedColors.Length > 10) {
|
||||
throw new ArgumentException ("This method only works for UIs that use at most 10 colors");
|
||||
}
|
||||
|
||||
@@ -182,7 +226,7 @@ namespace Terminal.Gui.Views {
|
||||
var contents = driver.Contents;
|
||||
|
||||
int r = 0;
|
||||
foreach(var line in expectedLook.Split ('\n').Select(l=>l.Trim())) {
|
||||
foreach (var line in expectedLook.Split ('\n').Select (l => l.Trim ())) {
|
||||
|
||||
for (int c = 0; c < line.Length; c++) {
|
||||
|
||||
@@ -195,10 +239,10 @@ namespace Terminal.Gui.Views {
|
||||
throw new ArgumentException ($"Bad value for expectedColors, {match.Count} Attributes had the same Value");
|
||||
}
|
||||
|
||||
var colorUsed = Array.IndexOf(expectedColors,match[0]).ToString()[0];
|
||||
var colorUsed = Array.IndexOf (expectedColors, match [0]).ToString () [0];
|
||||
var userExpected = line [c];
|
||||
|
||||
if( colorUsed != userExpected) {
|
||||
if (colorUsed != userExpected) {
|
||||
throw new Exception ($"Colors used did not match expected at row {r} and col {c}. Color index used was {colorUsed} but test expected {userExpected} (these are indexes into the expectedColors array)");
|
||||
}
|
||||
}
|
||||
@@ -434,7 +478,7 @@ namespace Terminal.Gui.Views {
|
||||
/// is mutable a sensible place to check this is in redraw.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void CellSizeZero()
|
||||
public void CellSizeZero ()
|
||||
{
|
||||
InitFakeDriver ();
|
||||
|
||||
@@ -442,8 +486,8 @@ namespace Terminal.Gui.Views {
|
||||
gv.ColorScheme = new ColorScheme ();
|
||||
gv.Bounds = new Rect (0, 0, 50, 30);
|
||||
gv.Series.Add (new ScatterSeries () { Points = new List<PointF> { new PointF (1, 1) } });
|
||||
gv.CellSize= new PointF(0,5);
|
||||
var ex = Assert.Throws<Exception>(()=>gv.Redraw (gv.Bounds));
|
||||
gv.CellSize = new PointF (0, 5);
|
||||
var ex = Assert.Throws<Exception> (() => gv.Redraw (gv.Bounds));
|
||||
|
||||
Assert.Equal ("CellSize cannot be 0", ex.Message);
|
||||
|
||||
@@ -451,7 +495,7 @@ namespace Terminal.Gui.Views {
|
||||
Application.Shutdown ();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Tests that each point in the screen space maps to a rectangle of
|
||||
@@ -488,7 +532,7 @@ namespace Terminal.Gui.Views {
|
||||
Assert.Equal (x, p.X);
|
||||
Assert.Equal (y, p.Y);
|
||||
|
||||
p = gv.GraphSpaceToScreen (new PointF (graphSpace.Right - epsilon , graphSpace.Top + epsilon));
|
||||
p = gv.GraphSpaceToScreen (new PointF (graphSpace.Right - epsilon, graphSpace.Top + epsilon));
|
||||
Assert.Equal (x, p.X);
|
||||
Assert.Equal (y, p.Y);
|
||||
|
||||
@@ -613,33 +657,35 @@ namespace Terminal.Gui.Views {
|
||||
}
|
||||
}
|
||||
|
||||
public class MultiBarSeriesTests{
|
||||
public class MultiBarSeriesTests {
|
||||
|
||||
readonly ITestOutputHelper output;
|
||||
|
||||
public MultiBarSeriesTests(ITestOutputHelper output)
|
||||
public MultiBarSeriesTests (ITestOutputHelper output)
|
||||
{
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MultiBarSeries_BarSpacing(){
|
||||
|
||||
public void MultiBarSeries_BarSpacing ()
|
||||
{
|
||||
|
||||
// Creates clusters of 5 adjacent bars with 2 spaces between clusters
|
||||
var series = new MultiBarSeries(5,7,1);
|
||||
var series = new MultiBarSeries (5, 7, 1);
|
||||
|
||||
Assert.Equal(5,series.SubSeries.Count);
|
||||
Assert.Equal (5, series.SubSeries.Count);
|
||||
|
||||
Assert.Equal(0,series.SubSeries.ElementAt(0).Offset);
|
||||
Assert.Equal(1,series.SubSeries.ElementAt(1).Offset);
|
||||
Assert.Equal(2,series.SubSeries.ElementAt(2).Offset);
|
||||
Assert.Equal(3,series.SubSeries.ElementAt(3).Offset);
|
||||
Assert.Equal(4,series.SubSeries.ElementAt(4).Offset);
|
||||
Assert.Equal (0, series.SubSeries.ElementAt (0).Offset);
|
||||
Assert.Equal (1, series.SubSeries.ElementAt (1).Offset);
|
||||
Assert.Equal (2, series.SubSeries.ElementAt (2).Offset);
|
||||
Assert.Equal (3, series.SubSeries.ElementAt (3).Offset);
|
||||
Assert.Equal (4, series.SubSeries.ElementAt (4).Offset);
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void MultiBarSeriesColors_WrongNumber(){
|
||||
public void MultiBarSeriesColors_WrongNumber ()
|
||||
{
|
||||
|
||||
var fake = new FakeDriver ();
|
||||
|
||||
@@ -648,8 +694,8 @@ namespace Terminal.Gui.Views {
|
||||
};
|
||||
|
||||
// user passes 1 color only but asks for 5 bars
|
||||
var ex = Assert.Throws<ArgumentException>(()=>new MultiBarSeries(5,7,1,colors));
|
||||
Assert.Equal("Number of colors must match the number of bars (Parameter 'numberOfBarsPerCategory')",ex.Message);
|
||||
var ex = Assert.Throws<ArgumentException> (() => new MultiBarSeries (5, 7, 1, colors));
|
||||
Assert.Equal ("Number of colors must match the number of bars (Parameter 'numberOfBarsPerCategory')", ex.Message);
|
||||
|
||||
// Shutdown must be called to safely clean up Application if Init has been called
|
||||
Application.Shutdown ();
|
||||
@@ -657,7 +703,8 @@ namespace Terminal.Gui.Views {
|
||||
|
||||
|
||||
[Fact]
|
||||
public void MultiBarSeriesColors_RightNumber(){
|
||||
public void MultiBarSeriesColors_RightNumber ()
|
||||
{
|
||||
|
||||
var fake = new FakeDriver ();
|
||||
|
||||
@@ -668,11 +715,11 @@ namespace Terminal.Gui.Views {
|
||||
};
|
||||
|
||||
// user passes 3 colors and asks for 3 bars
|
||||
var series = new MultiBarSeries(3,7,1,colors);
|
||||
var series = new MultiBarSeries (3, 7, 1, colors);
|
||||
|
||||
Assert.Equal(series.SubSeries.ElementAt(0).OverrideBarColor,colors[0]);
|
||||
Assert.Equal(series.SubSeries.ElementAt(1).OverrideBarColor,colors[1]);
|
||||
Assert.Equal(series.SubSeries.ElementAt(2).OverrideBarColor,colors[2]);
|
||||
Assert.Equal (series.SubSeries.ElementAt (0).OverrideBarColor, colors [0]);
|
||||
Assert.Equal (series.SubSeries.ElementAt (1).OverrideBarColor, colors [1]);
|
||||
Assert.Equal (series.SubSeries.ElementAt (2).OverrideBarColor, colors [2]);
|
||||
|
||||
// Shutdown must be called to safely clean up Application if Init has been called
|
||||
Application.Shutdown ();
|
||||
@@ -680,20 +727,22 @@ namespace Terminal.Gui.Views {
|
||||
|
||||
|
||||
[Fact]
|
||||
public void MultiBarSeriesAddValues_WrongNumber(){
|
||||
|
||||
public void MultiBarSeriesAddValues_WrongNumber ()
|
||||
{
|
||||
|
||||
// user asks for 3 bars per category
|
||||
var series = new MultiBarSeries(3,7,1);
|
||||
var series = new MultiBarSeries (3, 7, 1);
|
||||
|
||||
var ex = Assert.Throws<ArgumentException>(()=>series.AddBars("Cars",'#',1));
|
||||
var ex = Assert.Throws<ArgumentException> (() => series.AddBars ("Cars", '#', 1));
|
||||
|
||||
Assert.Equal("Number of values must match the number of bars per category (Parameter 'values')",ex.Message);
|
||||
Assert.Equal ("Number of values must match the number of bars per category (Parameter 'values')", ex.Message);
|
||||
}
|
||||
|
||||
|
||||
|
||||
[Fact]
|
||||
public void TestRendering_MultibarSeries(){
|
||||
public void TestRendering_MultibarSeries ()
|
||||
{
|
||||
|
||||
GraphViewTests.InitFakeDriver ();
|
||||
|
||||
@@ -703,14 +752,14 @@ namespace Terminal.Gui.Views {
|
||||
// y axis goes from 0.1 to 1 across 10 console rows
|
||||
// x axis goes from 0 to 20 across 20 console columns
|
||||
gv.Bounds = new Rect (0, 0, 20, 10);
|
||||
gv.CellSize = new PointF(1f,0.1f);
|
||||
gv.CellSize = new PointF (1f, 0.1f);
|
||||
gv.MarginBottom = 1;
|
||||
gv.MarginLeft = 1;
|
||||
|
||||
var multibarSeries = new MultiBarSeries (2,4,1);
|
||||
|
||||
var multibarSeries = new MultiBarSeries (2, 4, 1);
|
||||
|
||||
//nudge them left to avoid float rounding errors at the boundaries of cells
|
||||
foreach(var sub in multibarSeries.SubSeries) {
|
||||
foreach (var sub in multibarSeries.SubSeries) {
|
||||
sub.Offset -= 0.001f;
|
||||
}
|
||||
|
||||
@@ -720,28 +769,28 @@ namespace Terminal.Gui.Views {
|
||||
|
||||
// don't show axis labels that means any labels
|
||||
// that appaer are explicitly from the bars
|
||||
gv.AxisX = fakeXAxis = new FakeHAxis(){Increment=0};
|
||||
gv.AxisY = new FakeVAxis(){Increment=0};
|
||||
gv.AxisX = fakeXAxis = new FakeHAxis () { Increment = 0 };
|
||||
gv.AxisY = new FakeVAxis () { Increment = 0 };
|
||||
|
||||
gv.Redraw(gv.Bounds);
|
||||
gv.Redraw (gv.Bounds);
|
||||
|
||||
// Since bar series has no bars yet no labels should be displayed
|
||||
Assert.Empty(fakeXAxis.LabelPoints);
|
||||
Assert.Empty (fakeXAxis.LabelPoints);
|
||||
|
||||
multibarSeries.AddBars("hey",'M',0.5001f, 0.5001f);
|
||||
fakeXAxis.LabelPoints.Clear();
|
||||
gv.Redraw(gv.Bounds);
|
||||
|
||||
Assert.Equal(4,fakeXAxis.LabelPoints.Single());
|
||||
multibarSeries.AddBars ("hey", 'M', 0.5001f, 0.5001f);
|
||||
fakeXAxis.LabelPoints.Clear ();
|
||||
gv.Redraw (gv.Bounds);
|
||||
|
||||
multibarSeries.AddBars("there",'M',0.24999f,0.74999f);
|
||||
multibarSeries.AddBars("bob",'M',1,2);
|
||||
fakeXAxis.LabelPoints.Clear();
|
||||
gv.Redraw(gv.Bounds);
|
||||
Assert.Equal (4, fakeXAxis.LabelPoints.Single ());
|
||||
|
||||
Assert.Equal(3,fakeXAxis.LabelPoints.Count);
|
||||
Assert.Equal(4,fakeXAxis.LabelPoints[0]);
|
||||
Assert.Equal(8,fakeXAxis.LabelPoints[1]);
|
||||
multibarSeries.AddBars ("there", 'M', 0.24999f, 0.74999f);
|
||||
multibarSeries.AddBars ("bob", 'M', 1, 2);
|
||||
fakeXAxis.LabelPoints.Clear ();
|
||||
gv.Redraw (gv.Bounds);
|
||||
|
||||
Assert.Equal (3, fakeXAxis.LabelPoints.Count);
|
||||
Assert.Equal (4, fakeXAxis.LabelPoints [0]);
|
||||
Assert.Equal (8, fakeXAxis.LabelPoints [1]);
|
||||
Assert.Equal (12, fakeXAxis.LabelPoints [2]);
|
||||
|
||||
string looksLike =
|
||||
@@ -763,7 +812,7 @@ namespace Terminal.Gui.Views {
|
||||
}
|
||||
}
|
||||
|
||||
public class BarSeriesTests{
|
||||
public class BarSeriesTests {
|
||||
|
||||
|
||||
private GraphView GetGraph (out FakeBarSeries series, out FakeHAxis axisX, out FakeVAxis axisY)
|
||||
@@ -776,46 +825,47 @@ namespace Terminal.Gui.Views {
|
||||
// y axis goes from 0.1 to 1 across 10 console rows
|
||||
// x axis goes from 0 to 10 across 20 console columns
|
||||
gv.Bounds = new Rect (0, 0, 20, 10);
|
||||
gv.CellSize = new PointF(0.5f,0.1f);
|
||||
gv.CellSize = new PointF (0.5f, 0.1f);
|
||||
|
||||
gv.Series.Add (series = new FakeBarSeries ());
|
||||
|
||||
// don't show axis labels that means any labels
|
||||
// that appaer are explicitly from the bars
|
||||
gv.AxisX = axisX = new FakeHAxis(){Increment=0};
|
||||
gv.AxisY = axisY = new FakeVAxis(){Increment=0};
|
||||
gv.AxisX = axisX = new FakeHAxis () { Increment = 0 };
|
||||
gv.AxisY = axisY = new FakeVAxis () { Increment = 0 };
|
||||
|
||||
return gv;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestZeroHeightBar_WithName(){
|
||||
public void TestZeroHeightBar_WithName ()
|
||||
{
|
||||
|
||||
var graph = GetGraph(out FakeBarSeries barSeries, out FakeHAxis axisX, out FakeVAxis axisY);
|
||||
graph.Redraw(graph.Bounds);
|
||||
var graph = GetGraph (out FakeBarSeries barSeries, out FakeHAxis axisX, out FakeVAxis axisY);
|
||||
graph.Redraw (graph.Bounds);
|
||||
|
||||
// no bars
|
||||
Assert.Empty(barSeries.BarScreenStarts);
|
||||
Assert.Empty(axisX.LabelPoints);
|
||||
Assert.Empty(axisY.LabelPoints);
|
||||
Assert.Empty (barSeries.BarScreenStarts);
|
||||
Assert.Empty (axisX.LabelPoints);
|
||||
Assert.Empty (axisY.LabelPoints);
|
||||
|
||||
// bar of height 0
|
||||
barSeries.Bars.Add(new BarSeries.Bar("hi",new GraphCellToRender('.'),0));
|
||||
barSeries.Bars.Add (new BarSeries.Bar ("hi", new GraphCellToRender ('.'), 0));
|
||||
barSeries.Orientation = Orientation.Vertical;
|
||||
|
||||
// redraw graph
|
||||
graph.Redraw(graph.Bounds);
|
||||
graph.Redraw (graph.Bounds);
|
||||
|
||||
// bar should not be drawn
|
||||
Assert.Empty(barSeries.BarScreenStarts);
|
||||
Assert.Empty (barSeries.BarScreenStarts);
|
||||
|
||||
Assert.NotEmpty(axisX.LabelPoints);
|
||||
Assert.Empty(axisY.LabelPoints);
|
||||
Assert.NotEmpty (axisX.LabelPoints);
|
||||
Assert.Empty (axisY.LabelPoints);
|
||||
|
||||
// but bar name should be
|
||||
// Screen position x=2 because bars are drawn every 1f of
|
||||
// graph space and CellSize.X is 0.5f
|
||||
Assert.Contains(2, axisX.LabelPoints);
|
||||
Assert.Contains (2, axisX.LabelPoints);
|
||||
|
||||
// Shutdown must be called to safely clean up Application if Init has been called
|
||||
Application.Shutdown ();
|
||||
@@ -823,71 +873,73 @@ namespace Terminal.Gui.Views {
|
||||
|
||||
|
||||
[Fact]
|
||||
public void TestTwoTallBars_WithOffset(){
|
||||
public void TestTwoTallBars_WithOffset ()
|
||||
{
|
||||
|
||||
var graph = GetGraph(out FakeBarSeries barSeries, out FakeHAxis axisX, out FakeVAxis axisY);
|
||||
graph.Redraw(graph.Bounds);
|
||||
var graph = GetGraph (out FakeBarSeries barSeries, out FakeHAxis axisX, out FakeVAxis axisY);
|
||||
graph.Redraw (graph.Bounds);
|
||||
|
||||
// no bars
|
||||
Assert.Empty(barSeries.BarScreenStarts);
|
||||
Assert.Empty(axisX.LabelPoints);
|
||||
Assert.Empty(axisY.LabelPoints);
|
||||
Assert.Empty (barSeries.BarScreenStarts);
|
||||
Assert.Empty (axisX.LabelPoints);
|
||||
Assert.Empty (axisY.LabelPoints);
|
||||
|
||||
// 0.5 units of graph fit every screen cell
|
||||
// so 1 unit of graph space is 2 screen columns
|
||||
graph.CellSize = new PointF(0.5f,0.1f);
|
||||
graph.CellSize = new PointF (0.5f, 0.1f);
|
||||
|
||||
// Start bar 1 screen unit along
|
||||
barSeries.Offset = 0.5f;
|
||||
barSeries.BarEvery = 1f;
|
||||
|
||||
barSeries.Bars.Add(
|
||||
new BarSeries.Bar("hi1",new GraphCellToRender('.'),100));
|
||||
barSeries.Bars.Add(
|
||||
new BarSeries.Bar("hi2",new GraphCellToRender('.'),100));
|
||||
barSeries.Bars.Add (
|
||||
new BarSeries.Bar ("hi1", new GraphCellToRender ('.'), 100));
|
||||
barSeries.Bars.Add (
|
||||
new BarSeries.Bar ("hi2", new GraphCellToRender ('.'), 100));
|
||||
|
||||
barSeries.Orientation = Orientation.Vertical;
|
||||
|
||||
// redraw graph
|
||||
graph.Redraw(graph.Bounds);
|
||||
graph.Redraw (graph.Bounds);
|
||||
|
||||
// bar should be drawn at BarEvery 1f + offset 0.5f = 3 screen units
|
||||
Assert.Equal(3,barSeries.BarScreenStarts[0].X);
|
||||
Assert.Equal(3,barSeries.BarScreenEnds[0].X);
|
||||
Assert.Equal (3, barSeries.BarScreenStarts [0].X);
|
||||
Assert.Equal (3, barSeries.BarScreenEnds [0].X);
|
||||
|
||||
// second bar should be BarEveryx2 = 2f + offset 0.5f = 5 screen units
|
||||
Assert.Equal(5,barSeries.BarScreenStarts[1].X);
|
||||
Assert.Equal(5,barSeries.BarScreenEnds[1].X);
|
||||
Assert.Equal (5, barSeries.BarScreenStarts [1].X);
|
||||
Assert.Equal (5, barSeries.BarScreenEnds [1].X);
|
||||
|
||||
// both bars should have labels
|
||||
Assert.Equal(2,axisX.LabelPoints.Count);
|
||||
Assert.Contains(3, axisX.LabelPoints);
|
||||
Assert.Contains(5, axisX.LabelPoints);
|
||||
Assert.Equal (2, axisX.LabelPoints.Count);
|
||||
Assert.Contains (3, axisX.LabelPoints);
|
||||
Assert.Contains (5, axisX.LabelPoints);
|
||||
|
||||
// bars are very tall but should not draw up off top of screen
|
||||
Assert.Equal(9,barSeries.BarScreenStarts[0].Y);
|
||||
Assert.Equal(0,barSeries.BarScreenEnds[0].Y);
|
||||
Assert.Equal(9,barSeries.BarScreenStarts[1].Y);
|
||||
Assert.Equal(0,barSeries.BarScreenEnds[1].Y);
|
||||
Assert.Equal (9, barSeries.BarScreenStarts [0].Y);
|
||||
Assert.Equal (0, barSeries.BarScreenEnds [0].Y);
|
||||
Assert.Equal (9, barSeries.BarScreenStarts [1].Y);
|
||||
Assert.Equal (0, barSeries.BarScreenEnds [1].Y);
|
||||
|
||||
// Shutdown must be called to safely clean up Application if Init has been called
|
||||
Application.Shutdown ();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestOneLongOneShortHorizontalBars_WithOffset(){
|
||||
public void TestOneLongOneShortHorizontalBars_WithOffset ()
|
||||
{
|
||||
|
||||
var graph = GetGraph(out FakeBarSeries barSeries, out FakeHAxis axisX, out FakeVAxis axisY);
|
||||
graph.Redraw(graph.Bounds);
|
||||
var graph = GetGraph (out FakeBarSeries barSeries, out FakeHAxis axisX, out FakeVAxis axisY);
|
||||
graph.Redraw (graph.Bounds);
|
||||
|
||||
// no bars
|
||||
Assert.Empty(barSeries.BarScreenStarts);
|
||||
Assert.Empty(axisX.LabelPoints);
|
||||
Assert.Empty(axisY.LabelPoints);
|
||||
Assert.Empty (barSeries.BarScreenStarts);
|
||||
Assert.Empty (axisX.LabelPoints);
|
||||
Assert.Empty (axisY.LabelPoints);
|
||||
|
||||
// 0.1 units of graph y fit every screen row
|
||||
// so 1 unit of graph y space is 10 screen rows
|
||||
graph.CellSize = new PointF(0.5f,0.1f);
|
||||
graph.CellSize = new PointF (0.5f, 0.1f);
|
||||
|
||||
// Start bar 3 screen units up (y = height-3)
|
||||
barSeries.Offset = 0.25f;
|
||||
@@ -896,64 +948,64 @@ namespace Terminal.Gui.Views {
|
||||
barSeries.Orientation = Orientation.Horizontal;
|
||||
|
||||
// 1 bar that is very wide (100 graph units horizontally = screen pos 50 but bounded by screen)
|
||||
barSeries.Bars.Add(
|
||||
new BarSeries.Bar("hi1",new GraphCellToRender('.'),100));
|
||||
barSeries.Bars.Add (
|
||||
new BarSeries.Bar ("hi1", new GraphCellToRender ('.'), 100));
|
||||
|
||||
// 1 bar that is shorter
|
||||
barSeries.Bars.Add(
|
||||
new BarSeries.Bar("hi2",new GraphCellToRender('.'),5));
|
||||
barSeries.Bars.Add (
|
||||
new BarSeries.Bar ("hi2", new GraphCellToRender ('.'), 5));
|
||||
|
||||
// redraw graph
|
||||
graph.Redraw(graph.Bounds);
|
||||
graph.Redraw (graph.Bounds);
|
||||
|
||||
// since bars are horizontal all have the same X start cordinates
|
||||
Assert.Equal(0,barSeries.BarScreenStarts[0].X);
|
||||
Assert.Equal(0,barSeries.BarScreenStarts[1].X);
|
||||
Assert.Equal (0, barSeries.BarScreenStarts [0].X);
|
||||
Assert.Equal (0, barSeries.BarScreenStarts [1].X);
|
||||
|
||||
// bar goes all the way to the end so bumps up against right screen boundary
|
||||
// width of graph is 20
|
||||
Assert.Equal(19,barSeries.BarScreenEnds[0].X);
|
||||
Assert.Equal (19, barSeries.BarScreenEnds [0].X);
|
||||
|
||||
// shorter bar is 5 graph units wide which is 10 screen units
|
||||
Assert.Equal(10,barSeries.BarScreenEnds[1].X);
|
||||
Assert.Equal (10, barSeries.BarScreenEnds [1].X);
|
||||
|
||||
// first bar should be offset 6 screen units (0.25f + 0.3f graph units)
|
||||
// since height of control is 10 then first bar should be at screen row 4 (10-6)
|
||||
Assert.Equal(4,barSeries.BarScreenStarts[0].Y);
|
||||
Assert.Equal (4, barSeries.BarScreenStarts [0].Y);
|
||||
|
||||
// second bar should be offset 9 screen units (0.25f + 0.6f graph units)
|
||||
// since height of control is 10 then second bar should be at screen row 1 (10-9)
|
||||
Assert.Equal(1,barSeries.BarScreenStarts[1].Y);
|
||||
Assert.Equal (1, barSeries.BarScreenStarts [1].Y);
|
||||
|
||||
// both bars should have labels but on the y axis
|
||||
Assert.Equal(2,axisY.LabelPoints.Count);
|
||||
Assert.Empty(axisX.LabelPoints);
|
||||
Assert.Equal (2, axisY.LabelPoints.Count);
|
||||
Assert.Empty (axisX.LabelPoints);
|
||||
|
||||
// labels should align with the bars (same screen y axis point)
|
||||
Assert.Contains(4, axisY.LabelPoints);
|
||||
Assert.Contains(1, axisY.LabelPoints);
|
||||
Assert.Contains (4, axisY.LabelPoints);
|
||||
Assert.Contains (1, axisY.LabelPoints);
|
||||
|
||||
// Shutdown must be called to safely clean up Application if Init has been called
|
||||
Application.Shutdown ();
|
||||
}
|
||||
|
||||
private class FakeBarSeries : BarSeries{
|
||||
private class FakeBarSeries : BarSeries {
|
||||
public GraphCellToRender FinalColor { get; private set; }
|
||||
|
||||
public List<Point> BarScreenStarts { get; private set; } = new List<Point>();
|
||||
public List<Point> BarScreenEnds { get; private set; } = new List<Point>();
|
||||
|
||||
public List<Point> BarScreenStarts { get; private set; } = new List<Point> ();
|
||||
public List<Point> BarScreenEnds { get; private set; } = new List<Point> ();
|
||||
|
||||
protected override GraphCellToRender AdjustColor (GraphCellToRender graphCellToRender)
|
||||
{
|
||||
return FinalColor = base.AdjustColor (graphCellToRender);
|
||||
return FinalColor = base.AdjustColor (graphCellToRender);
|
||||
}
|
||||
|
||||
protected override void DrawBarLine (GraphView graph, Point start, Point end, Bar beingDrawn)
|
||||
{
|
||||
base.DrawBarLine (graph, start, end, beingDrawn);
|
||||
|
||||
BarScreenStarts.Add(start);
|
||||
BarScreenEnds.Add(end);
|
||||
|
||||
BarScreenStarts.Add (start);
|
||||
BarScreenEnds.Add (end);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -965,11 +1017,11 @@ namespace Terminal.Gui.Views {
|
||||
|
||||
private GraphView GetGraph (out FakeHAxis axis)
|
||||
{
|
||||
return GetGraph(out axis, out _);
|
||||
return GetGraph (out axis, out _);
|
||||
}
|
||||
private GraphView GetGraph (out FakeVAxis axis)
|
||||
{
|
||||
return GetGraph(out _, out axis);
|
||||
return GetGraph (out _, out axis);
|
||||
}
|
||||
private GraphView GetGraph (out FakeHAxis axisX, out FakeVAxis axisY)
|
||||
{
|
||||
@@ -1003,15 +1055,15 @@ namespace Terminal.Gui.Views {
|
||||
gv.Redraw (gv.Bounds);
|
||||
|
||||
Assert.DoesNotContain (new Point (-1, 29), axis.DrawAxisLinePoints);
|
||||
Assert.Contains (new Point (0, 29),axis.DrawAxisLinePoints);
|
||||
Assert.Contains (new Point (0, 29), axis.DrawAxisLinePoints);
|
||||
Assert.Contains (new Point (1, 29), axis.DrawAxisLinePoints);
|
||||
|
||||
|
||||
Assert.Contains (new Point (48, 29), axis.DrawAxisLinePoints);
|
||||
Assert.Contains (new Point (49, 29), axis.DrawAxisLinePoints);
|
||||
Assert.DoesNotContain (new Point (50, 29), axis.DrawAxisLinePoints);
|
||||
|
||||
Assert.InRange(axis.LabelPoints.Max(),0,49);
|
||||
Assert.InRange(axis.LabelPoints.Min(),0,49);
|
||||
Assert.InRange (axis.LabelPoints.Max (), 0, 49);
|
||||
Assert.InRange (axis.LabelPoints.Min (), 0, 49);
|
||||
|
||||
// Shutdown must be called to safely clean up Application if Init has been called
|
||||
Application.Shutdown ();
|
||||
@@ -1033,8 +1085,8 @@ namespace Terminal.Gui.Views {
|
||||
Assert.Contains (new Point (49, 19), axis.DrawAxisLinePoints);
|
||||
Assert.DoesNotContain (new Point (50, 19), axis.DrawAxisLinePoints);
|
||||
|
||||
Assert.InRange(axis.LabelPoints.Max(),0,49);
|
||||
Assert.InRange(axis.LabelPoints.Min(),0,49);
|
||||
Assert.InRange (axis.LabelPoints.Max (), 0, 49);
|
||||
Assert.InRange (axis.LabelPoints.Min (), 0, 49);
|
||||
|
||||
// Shutdown must be called to safely clean up Application if Init has been called
|
||||
Application.Shutdown ();
|
||||
@@ -1057,8 +1109,8 @@ namespace Terminal.Gui.Views {
|
||||
Assert.DoesNotContain (new Point (50, 29), axis.DrawAxisLinePoints);
|
||||
|
||||
// Axis lables should not be drawn in the margin
|
||||
Assert.InRange(axis.LabelPoints.Max(),5,49);
|
||||
Assert.InRange(axis.LabelPoints.Min(),5,49);
|
||||
Assert.InRange (axis.LabelPoints.Max (), 5, 49);
|
||||
Assert.InRange (axis.LabelPoints.Min (), 5, 49);
|
||||
|
||||
// Shutdown must be called to safely clean up Application if Init has been called
|
||||
Application.Shutdown ();
|
||||
@@ -1081,15 +1133,15 @@ namespace Terminal.Gui.Views {
|
||||
gv.Redraw (gv.Bounds);
|
||||
|
||||
Assert.DoesNotContain (new Point (0, -1), axis.DrawAxisLinePoints);
|
||||
Assert.Contains (new Point (0, 1),axis.DrawAxisLinePoints);
|
||||
Assert.Contains (new Point (0, 1), axis.DrawAxisLinePoints);
|
||||
Assert.Contains (new Point (0, 2), axis.DrawAxisLinePoints);
|
||||
|
||||
|
||||
Assert.Contains (new Point (0, 28), axis.DrawAxisLinePoints);
|
||||
Assert.Contains (new Point (0, 29), axis.DrawAxisLinePoints);
|
||||
Assert.DoesNotContain (new Point (0, 30), axis.DrawAxisLinePoints);
|
||||
|
||||
Assert.InRange(axis.LabelPoints.Max(),0,29);
|
||||
Assert.InRange(axis.LabelPoints.Min(),0,29);
|
||||
Assert.InRange (axis.LabelPoints.Max (), 0, 29);
|
||||
Assert.InRange (axis.LabelPoints.Min (), 0, 29);
|
||||
|
||||
// Shutdown must be called to safely clean up Application if Init has been called
|
||||
Application.Shutdown ();
|
||||
@@ -1104,16 +1156,16 @@ namespace Terminal.Gui.Views {
|
||||
gv.Redraw (gv.Bounds);
|
||||
|
||||
Assert.DoesNotContain (new Point (0, -1), axis.DrawAxisLinePoints);
|
||||
Assert.Contains (new Point (0, 1),axis.DrawAxisLinePoints);
|
||||
Assert.Contains (new Point (0, 1), axis.DrawAxisLinePoints);
|
||||
Assert.Contains (new Point (0, 2), axis.DrawAxisLinePoints);
|
||||
|
||||
|
||||
Assert.Contains (new Point (0, 18), axis.DrawAxisLinePoints);
|
||||
Assert.Contains (new Point (0, 19), axis.DrawAxisLinePoints);
|
||||
Assert.DoesNotContain (new Point (0, 20), axis.DrawAxisLinePoints);
|
||||
|
||||
// Labels should not be drawn into the axis
|
||||
Assert.InRange(axis.LabelPoints.Max(),0,19);
|
||||
Assert.InRange(axis.LabelPoints.Min(),0,19);
|
||||
Assert.InRange (axis.LabelPoints.Max (), 0, 19);
|
||||
Assert.InRange (axis.LabelPoints.Min (), 0, 19);
|
||||
|
||||
// Shutdown must be called to safely clean up Application if Init has been called
|
||||
Application.Shutdown ();
|
||||
@@ -1128,15 +1180,15 @@ namespace Terminal.Gui.Views {
|
||||
gv.Redraw (gv.Bounds);
|
||||
|
||||
Assert.DoesNotContain (new Point (5, -1), axis.DrawAxisLinePoints);
|
||||
Assert.Contains (new Point (5, 1),axis.DrawAxisLinePoints);
|
||||
Assert.Contains (new Point (5, 1), axis.DrawAxisLinePoints);
|
||||
Assert.Contains (new Point (5, 2), axis.DrawAxisLinePoints);
|
||||
|
||||
|
||||
Assert.Contains (new Point (5, 28), axis.DrawAxisLinePoints);
|
||||
Assert.Contains (new Point (5, 29), axis.DrawAxisLinePoints);
|
||||
Assert.DoesNotContain (new Point (5, 30), axis.DrawAxisLinePoints);
|
||||
|
||||
Assert.InRange(axis.LabelPoints.Max(),0,29);
|
||||
Assert.InRange(axis.LabelPoints.Min(),0,29);
|
||||
Assert.InRange (axis.LabelPoints.Max (), 0, 29);
|
||||
Assert.InRange (axis.LabelPoints.Min (), 0, 29);
|
||||
|
||||
// Shutdown must be called to safely clean up Application if Init has been called
|
||||
Application.Shutdown ();
|
||||
@@ -1148,13 +1200,13 @@ namespace Terminal.Gui.Views {
|
||||
public class TextAnnotationTests {
|
||||
readonly ITestOutputHelper output;
|
||||
|
||||
public TextAnnotationTests(ITestOutputHelper output)
|
||||
public TextAnnotationTests (ITestOutputHelper output)
|
||||
{
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestTextAnnotation_ScreenUnits()
|
||||
public void TestTextAnnotation_ScreenUnits ()
|
||||
{
|
||||
var gv = GraphViewTests.GetGraph ();
|
||||
|
||||
@@ -1177,8 +1229,8 @@ namespace Terminal.Gui.Views {
|
||||
|
||||
// user scrolls up one unit of graph space
|
||||
gv.ScrollOffset = new PointF (0, 1f);
|
||||
gv.Redraw (gv.Bounds);
|
||||
|
||||
gv.Redraw (gv.Bounds);
|
||||
|
||||
// we expect no change in the location of the annotation (only the axis label changes)
|
||||
// this is because screen units are constant and do not change as the viewport into
|
||||
// graph space scrolls to different areas of the graph
|
||||
@@ -1301,7 +1353,7 @@ namespace Terminal.Gui.Views {
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null)]
|
||||
[InlineData (null)]
|
||||
[InlineData (" ")]
|
||||
[InlineData ("\t\t")]
|
||||
public void TestTextAnnotation_EmptyText (string whitespace)
|
||||
@@ -1316,7 +1368,7 @@ namespace Terminal.Gui.Views {
|
||||
// add a point a bit further along the graph so if the whitespace were rendered
|
||||
// the test would pick it up (AssertDriverContentsAre ignores trailing whitespace on lines)
|
||||
var points = new ScatterSeries ();
|
||||
points.Points.Add(new PointF(7, 2));
|
||||
points.Points.Add (new PointF (7, 2));
|
||||
gv.Series.Add (points);
|
||||
|
||||
gv.Redraw (gv.Bounds);
|
||||
@@ -1340,7 +1392,7 @@ namespace Terminal.Gui.Views {
|
||||
public class LegendTests {
|
||||
readonly ITestOutputHelper output;
|
||||
|
||||
public LegendTests(ITestOutputHelper output)
|
||||
public LegendTests (ITestOutputHelper output)
|
||||
{
|
||||
this.output = output;
|
||||
}
|
||||
@@ -1349,7 +1401,7 @@ namespace Terminal.Gui.Views {
|
||||
public void LegendNormalUsage_WithBorder ()
|
||||
{
|
||||
var gv = GraphViewTests.GetGraph ();
|
||||
var legend = new LegendAnnotation(new Rect(2,0,5,3));
|
||||
var legend = new LegendAnnotation (new Rect (2, 0, 5, 3));
|
||||
legend.AddEntry (new GraphCellToRender ('A'), "Ant");
|
||||
legend.AddEntry (new GraphCellToRender ('B'), "Bat");
|
||||
|
||||
@@ -1404,13 +1456,13 @@ namespace Terminal.Gui.Views {
|
||||
public class PathAnnotationTests {
|
||||
readonly ITestOutputHelper output;
|
||||
|
||||
public PathAnnotationTests( ITestOutputHelper output)
|
||||
public PathAnnotationTests (ITestOutputHelper output)
|
||||
{
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PathAnnotation_Box()
|
||||
public void PathAnnotation_Box ()
|
||||
{
|
||||
var gv = GraphViewTests.GetGraph ();
|
||||
|
||||
@@ -1480,9 +1532,9 @@ namespace Terminal.Gui.Views {
|
||||
// Shutdown must be called to safely clean up Application if Init has been called
|
||||
Application.Shutdown ();
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void XAxisLabels_With_MarginLeft()
|
||||
public void XAxisLabels_With_MarginLeft ()
|
||||
{
|
||||
GraphViewTests.InitFakeDriver ();
|
||||
var gv = new GraphView {
|
||||
@@ -1499,7 +1551,7 @@ namespace Terminal.Gui.Views {
|
||||
});
|
||||
|
||||
// reserve 3 cells of the left for the margin
|
||||
gv.MarginLeft = 3;
|
||||
gv.MarginLeft = 3;
|
||||
gv.MarginBottom = 1;
|
||||
|
||||
gv.Redraw (gv.Bounds);
|
||||
@@ -1515,7 +1567,7 @@ namespace Terminal.Gui.Views {
|
||||
0 5
|
||||
|
||||
";
|
||||
GraphViewTests.AssertDriverContentsAre (expected, output);
|
||||
GraphViewTests.AssertDriverContentsAre (expected, output);
|
||||
|
||||
|
||||
// Shutdown must be called to safely clean up Application if Init has been called
|
||||
@@ -1599,7 +1651,7 @@ namespace Terminal.Gui.Views {
|
||||
0┼┬┬┬┬┬┬┬┬
|
||||
0 5";
|
||||
|
||||
GraphViewTests.AssertDriverContentsAre (expected,output);
|
||||
GraphViewTests.AssertDriverContentsAre (expected, output);
|
||||
|
||||
|
||||
// Shutdown must be called to safely clean up Application if Init has been called
|
||||
@@ -1657,11 +1709,11 @@ namespace Terminal.Gui.Views {
|
||||
}
|
||||
}
|
||||
|
||||
public class AxisIncrementToRenderTests {
|
||||
public class AxisIncrementToRenderTests {
|
||||
[Fact]
|
||||
public void AxisIncrementToRenderTests_Constructor ()
|
||||
{
|
||||
var render = new AxisIncrementToRender (Orientation.Horizontal,1,6.6f);
|
||||
var render = new AxisIncrementToRender (Orientation.Horizontal, 1, 6.6f);
|
||||
|
||||
Assert.Equal (Orientation.Horizontal, render.Orientation);
|
||||
Assert.Equal (1, render.ScreenLocation);
|
||||
|
||||
@@ -512,8 +512,8 @@ Edit
|
||||
└──────┘
|
||||
";
|
||||
|
||||
var pos = GraphViewTests.AssertDriverContentsWithPosAre (expected, output);
|
||||
Assert.Equal (new Point (0, 1), pos);
|
||||
var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
||||
Assert.Equal (new Rect (0, 1, 8, 4), pos);
|
||||
}
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
@@ -541,8 +541,8 @@ Edit
|
||||
──────┘
|
||||
";
|
||||
|
||||
var pos = GraphViewTests.AssertDriverContentsWithPosAre (expected, output);
|
||||
Assert.Equal (new Point (0, 0), pos);
|
||||
var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
||||
Assert.Equal (new Rect (0, 0, 7, 4), pos);
|
||||
|
||||
menu.CloseAllMenus ();
|
||||
menu.Frame = new Rect (-1, -2, menu.Frame.Width, menu.Frame.Height);
|
||||
@@ -555,8 +555,8 @@ Edit
|
||||
──────┘
|
||||
";
|
||||
|
||||
pos = GraphViewTests.AssertDriverContentsWithPosAre (expected, output);
|
||||
Assert.Equal (new Point (1, 0), pos);
|
||||
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
||||
Assert.Equal (new Rect (1, 0, 7, 3), pos);
|
||||
|
||||
menu.CloseAllMenus ();
|
||||
menu.Frame = new Rect (0, 0, menu.Frame.Width, menu.Frame.Height);
|
||||
@@ -566,13 +566,13 @@ Edit
|
||||
|
||||
expected = @"
|
||||
┌──────
|
||||
│ One
|
||||
│ Two
|
||||
│ One
|
||||
│ Two
|
||||
└──────
|
||||
";
|
||||
|
||||
pos = GraphViewTests.AssertDriverContentsWithPosAre (expected, output);
|
||||
Assert.Equal (new Point (0, 1), pos);
|
||||
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
||||
Assert.Equal (new Rect (0, 1, 7, 4), pos);
|
||||
|
||||
menu.CloseAllMenus ();
|
||||
menu.Frame = new Rect (0, 0, menu.Frame.Width, menu.Frame.Height);
|
||||
@@ -582,12 +582,483 @@ Edit
|
||||
|
||||
expected = @"
|
||||
┌──────
|
||||
│ One
|
||||
│ Two
|
||||
│ One
|
||||
│ Two
|
||||
";
|
||||
|
||||
pos = GraphViewTests.AssertDriverContentsWithPosAre (expected, output);
|
||||
Assert.Equal (new Point (0, 1), pos);
|
||||
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
||||
Assert.Equal (new Rect (0, 1, 7, 3), pos);
|
||||
}
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
public void UseSubMenusSingleFrame_False_By_Keyboard ()
|
||||
{
|
||||
var menu = new MenuBar (new MenuBarItem [] {
|
||||
new MenuBarItem ("Numbers", new MenuItem [] {
|
||||
new MenuItem ("One", "", null),
|
||||
new MenuBarItem ("Two", new MenuItem [] {
|
||||
new MenuItem ("Sub-Menu 1", "", null),
|
||||
new MenuItem ("Sub-Menu 2", "", null)
|
||||
}),
|
||||
new MenuItem ("Three", "", null),
|
||||
})
|
||||
});
|
||||
|
||||
Application.Top.Add (menu);
|
||||
|
||||
Assert.Equal (Point.Empty, new Point (menu.Frame.X, menu.Frame.Y));
|
||||
Assert.False (menu.UseSubMenusSingleFrame);
|
||||
|
||||
Application.Top.Redraw (Application.Top.Bounds);
|
||||
var expected = @"
|
||||
Numbers
|
||||
";
|
||||
|
||||
var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
||||
Assert.Equal (new Rect (2, 0, 9, 1), pos);
|
||||
|
||||
Assert.True (menu.ProcessHotKey (new KeyEvent (Key.F9, null)));
|
||||
Application.Top.Redraw (Application.Top.Bounds);
|
||||
expected = @"
|
||||
Numbers
|
||||
┌────────┐
|
||||
│ One │
|
||||
│ Two ►│
|
||||
│ Three │
|
||||
└────────┘
|
||||
";
|
||||
|
||||
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
||||
Assert.Equal (new Rect (2, 0, 10, 6), pos);
|
||||
|
||||
Assert.True (Application.Top.Subviews [1].ProcessKey (new KeyEvent (Key.CursorDown, null)));
|
||||
Application.Top.Redraw (Application.Top.Bounds);
|
||||
expected = @"
|
||||
Numbers
|
||||
┌────────┐
|
||||
│ One │
|
||||
│ Two ►│┌─────────────┐
|
||||
│ Three ││ Sub-Menu 1 │
|
||||
└────────┘│ Sub-Menu 2 │
|
||||
└─────────────┘
|
||||
";
|
||||
|
||||
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
||||
Assert.Equal (new Rect (2, 0, 25, 7), pos);
|
||||
|
||||
Assert.True (Application.Top.Subviews [2].ProcessKey (new KeyEvent (Key.CursorLeft, null)));
|
||||
Application.Top.Redraw (Application.Top.Bounds);
|
||||
expected = @"
|
||||
Numbers
|
||||
┌────────┐
|
||||
│ One │
|
||||
│ Two ►│
|
||||
│ Three │
|
||||
└────────┘
|
||||
";
|
||||
|
||||
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
||||
Assert.Equal (new Rect (2, 0, 10, 6), pos);
|
||||
|
||||
Assert.True (Application.Top.Subviews [1].ProcessKey (new KeyEvent (Key.Esc, null)));
|
||||
Application.Top.Redraw (Application.Top.Bounds);
|
||||
expected = @"
|
||||
Numbers
|
||||
";
|
||||
|
||||
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
||||
Assert.Equal (new Rect (2, 0, 9, 1), pos);
|
||||
}
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
public void UseSubMenusSingleFrame_False_By_Mouse ()
|
||||
{
|
||||
var menu = new MenuBar (new MenuBarItem [] {
|
||||
new MenuBarItem ("Numbers", new MenuItem [] {
|
||||
new MenuItem ("One", "", null),
|
||||
new MenuBarItem ("Two", new MenuItem [] {
|
||||
new MenuItem ("Sub-Menu 1", "", null),
|
||||
new MenuItem ("Sub-Menu 2", "", null)
|
||||
}),
|
||||
new MenuItem ("Three", "", null),
|
||||
})
|
||||
});
|
||||
|
||||
Application.Top.Add (menu);
|
||||
|
||||
Assert.Equal (Point.Empty, new Point (menu.Frame.X, menu.Frame.Y));
|
||||
Assert.False (menu.UseSubMenusSingleFrame);
|
||||
|
||||
Application.Top.Redraw (Application.Top.Bounds);
|
||||
var expected = @"
|
||||
Numbers
|
||||
";
|
||||
|
||||
var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
||||
Assert.Equal (new Rect (2, 0, 9, 1), pos);
|
||||
|
||||
Assert.True (menu.MouseEvent (new MouseEvent () {
|
||||
X = 1,
|
||||
Y = 0,
|
||||
Flags = MouseFlags.Button1Pressed,
|
||||
View = menu
|
||||
}));
|
||||
Application.Top.Redraw (Application.Top.Bounds);
|
||||
expected = @"
|
||||
Numbers
|
||||
┌────────┐
|
||||
│ One │
|
||||
│ Two ►│
|
||||
│ Three │
|
||||
└────────┘
|
||||
";
|
||||
|
||||
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
||||
Assert.Equal (new Rect (2, 0, 10, 6), pos);
|
||||
|
||||
Assert.False (menu.MouseEvent (new MouseEvent () {
|
||||
X = 1,
|
||||
Y = 3,
|
||||
Flags = MouseFlags.ReportMousePosition,
|
||||
View = Application.Top.Subviews [1]
|
||||
}));
|
||||
Application.Top.Redraw (Application.Top.Bounds);
|
||||
expected = @"
|
||||
Numbers
|
||||
┌────────┐
|
||||
│ One │
|
||||
│ Two ►│┌─────────────┐
|
||||
│ Three ││ Sub-Menu 1 │
|
||||
└────────┘│ Sub-Menu 2 │
|
||||
└─────────────┘
|
||||
";
|
||||
|
||||
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
||||
Assert.Equal (new Rect (2, 0, 25, 7), pos);
|
||||
|
||||
Assert.False (menu.MouseEvent (new MouseEvent () {
|
||||
X = 1,
|
||||
Y = 2,
|
||||
Flags = MouseFlags.ReportMousePosition,
|
||||
View = Application.Top.Subviews [1]
|
||||
}));
|
||||
Application.Top.Redraw (Application.Top.Bounds);
|
||||
expected = @"
|
||||
Numbers
|
||||
┌────────┐
|
||||
│ One │
|
||||
│ Two ►│
|
||||
│ Three │
|
||||
└────────┘
|
||||
";
|
||||
|
||||
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
||||
Assert.Equal (new Rect (2, 0, 10, 6), pos);
|
||||
|
||||
Assert.False (menu.MouseEvent (new MouseEvent () {
|
||||
X = 70,
|
||||
Y = 2,
|
||||
Flags = MouseFlags.Button1Clicked,
|
||||
View = Application.Top
|
||||
}));
|
||||
Application.Top.Redraw (Application.Top.Bounds);
|
||||
expected = @"
|
||||
Numbers
|
||||
";
|
||||
|
||||
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
||||
Assert.Equal (new Rect (2, 0, 9, 1), pos);
|
||||
}
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
public void UseSubMenusSingleFrame_True_By_Keyboard ()
|
||||
{
|
||||
var menu = new MenuBar (new MenuBarItem [] {
|
||||
new MenuBarItem ("Numbers", new MenuItem [] {
|
||||
new MenuItem ("One", "", null),
|
||||
new MenuBarItem ("Two", new MenuItem [] {
|
||||
new MenuItem ("Sub-Menu 1", "", null),
|
||||
new MenuItem ("Sub-Menu 2", "", null)
|
||||
}),
|
||||
new MenuItem ("Three", "", null),
|
||||
})
|
||||
});
|
||||
|
||||
Application.Top.Add (menu);
|
||||
|
||||
Assert.Equal (Point.Empty, new Point (menu.Frame.X, menu.Frame.Y));
|
||||
Assert.False (menu.UseSubMenusSingleFrame);
|
||||
menu.UseSubMenusSingleFrame = true;
|
||||
Assert.True (menu.UseSubMenusSingleFrame);
|
||||
|
||||
Application.Top.Redraw (Application.Top.Bounds);
|
||||
var expected = @"
|
||||
Numbers
|
||||
";
|
||||
|
||||
var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
||||
Assert.Equal (new Rect (2, 0, 9, 1), pos);
|
||||
|
||||
Assert.True (menu.ProcessHotKey (new KeyEvent (Key.F9, null)));
|
||||
Application.Top.Redraw (Application.Top.Bounds);
|
||||
expected = @"
|
||||
Numbers
|
||||
┌────────┐
|
||||
│ One │
|
||||
│ Two ►│
|
||||
│ Three │
|
||||
└────────┘
|
||||
";
|
||||
|
||||
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
||||
Assert.Equal (new Rect (2, 0, 10, 6), pos);
|
||||
|
||||
Assert.True (Application.Top.Subviews [1].ProcessKey (new KeyEvent (Key.CursorDown, null)));
|
||||
Assert.True (Application.Top.Subviews [1].ProcessKey (new KeyEvent (Key.Enter, null)));
|
||||
Application.Top.Redraw (Application.Top.Bounds);
|
||||
expected = @"
|
||||
Numbers
|
||||
┌─────────────┐
|
||||
│◄ Two │
|
||||
├─────────────┤
|
||||
│ Sub-Menu 1 │
|
||||
│ Sub-Menu 2 │
|
||||
└─────────────┘
|
||||
";
|
||||
|
||||
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
||||
Assert.Equal (new Rect (2, 0, 15, 7), pos);
|
||||
|
||||
Assert.True (Application.Top.Subviews [2].ProcessKey (new KeyEvent (Key.Enter, null)));
|
||||
Application.Top.Redraw (Application.Top.Bounds);
|
||||
expected = @"
|
||||
Numbers
|
||||
┌────────┐
|
||||
│ One │
|
||||
│ Two ►│
|
||||
│ Three │
|
||||
└────────┘
|
||||
";
|
||||
|
||||
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
||||
Assert.Equal (new Rect (2, 0, 10, 6), pos);
|
||||
|
||||
Assert.True (Application.Top.Subviews [1].ProcessKey (new KeyEvent (Key.Esc, null)));
|
||||
Application.Top.Redraw (Application.Top.Bounds);
|
||||
expected = @"
|
||||
Numbers
|
||||
";
|
||||
|
||||
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
||||
Assert.Equal (new Rect (2, 0, 9, 1), pos);
|
||||
}
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
public void UseSubMenusSingleFrame_True_By_Mouse ()
|
||||
{
|
||||
var menu = new MenuBar (new MenuBarItem [] {
|
||||
new MenuBarItem ("Numbers", new MenuItem [] {
|
||||
new MenuItem ("One", "", null),
|
||||
new MenuBarItem ("Two", new MenuItem [] {
|
||||
new MenuItem ("Sub-Menu 1", "", null),
|
||||
new MenuItem ("Sub-Menu 2", "", null)
|
||||
}),
|
||||
new MenuItem ("Three", "", null),
|
||||
})
|
||||
});
|
||||
|
||||
Application.Top.Add (menu);
|
||||
|
||||
Assert.Equal (Point.Empty, new Point (menu.Frame.X, menu.Frame.Y));
|
||||
Assert.False (menu.UseSubMenusSingleFrame);
|
||||
menu.UseSubMenusSingleFrame = true;
|
||||
Assert.True (menu.UseSubMenusSingleFrame);
|
||||
|
||||
Application.Top.Redraw (Application.Top.Bounds);
|
||||
var expected = @"
|
||||
Numbers
|
||||
";
|
||||
|
||||
var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
||||
Assert.Equal (new Rect (2, 0, 9, 1), pos);
|
||||
|
||||
Assert.True (menu.MouseEvent (new MouseEvent () {
|
||||
X = 1,
|
||||
Y = 0,
|
||||
Flags = MouseFlags.Button1Pressed,
|
||||
View = menu
|
||||
}));
|
||||
Application.Top.Redraw (Application.Top.Bounds);
|
||||
expected = @"
|
||||
Numbers
|
||||
┌────────┐
|
||||
│ One │
|
||||
│ Two ►│
|
||||
│ Three │
|
||||
└────────┘
|
||||
";
|
||||
|
||||
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
||||
Assert.Equal (new Rect (2, 0, 10, 6), pos);
|
||||
|
||||
Assert.False (menu.MouseEvent (new MouseEvent () {
|
||||
X = 1,
|
||||
Y = 3,
|
||||
Flags = MouseFlags.Button1Clicked,
|
||||
View = Application.Top.Subviews [1]
|
||||
}));
|
||||
Application.Top.Redraw (Application.Top.Bounds);
|
||||
expected = @"
|
||||
Numbers
|
||||
┌─────────────┐
|
||||
│◄ Two │
|
||||
├─────────────┤
|
||||
│ Sub-Menu 1 │
|
||||
│ Sub-Menu 2 │
|
||||
└─────────────┘
|
||||
";
|
||||
|
||||
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
||||
Assert.Equal (new Rect (2, 0, 15, 7), pos);
|
||||
|
||||
Assert.False (menu.MouseEvent (new MouseEvent () {
|
||||
X = 1,
|
||||
Y = 2,
|
||||
Flags = MouseFlags.Button1Clicked,
|
||||
View = Application.Top.Subviews [2]
|
||||
}));
|
||||
Application.Top.Redraw (Application.Top.Bounds);
|
||||
expected = @"
|
||||
Numbers
|
||||
┌────────┐
|
||||
│ One │
|
||||
│ Two ►│
|
||||
│ Three │
|
||||
└────────┘
|
||||
";
|
||||
|
||||
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
||||
Assert.Equal (new Rect (2, 0, 10, 6), pos);
|
||||
|
||||
Assert.False (menu.MouseEvent (new MouseEvent () {
|
||||
X = 70,
|
||||
Y = 2,
|
||||
Flags = MouseFlags.Button1Clicked,
|
||||
View = Application.Top
|
||||
}));
|
||||
Application.Top.Redraw (Application.Top.Bounds);
|
||||
expected = @"
|
||||
Numbers
|
||||
";
|
||||
|
||||
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
||||
Assert.Equal (new Rect (2, 0, 9, 1), pos);
|
||||
}
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
public void HotKey_MenuBar_OnKeyDown_OnKeyUp_ProcessHotKey_ProcessKey ()
|
||||
{
|
||||
var newAction = false;
|
||||
var copyAction = false;
|
||||
|
||||
var menu = new MenuBar (new MenuBarItem [] {
|
||||
new MenuBarItem ("_File", new MenuItem [] {
|
||||
new MenuItem ("_New", "", () => newAction = true)
|
||||
}),
|
||||
new MenuBarItem ("_Edit", new MenuItem [] {
|
||||
new MenuItem ("_Copy", "", () => copyAction = true)
|
||||
})
|
||||
});
|
||||
|
||||
Application.Top.Add (menu);
|
||||
|
||||
Assert.False (newAction);
|
||||
Assert.False (copyAction);
|
||||
|
||||
Assert.False (menu.OnKeyDown (new (Key.AltMask, new KeyModifiers () { Alt = true })));
|
||||
Assert.True (menu.OnKeyUp (new (Key.AltMask, new KeyModifiers () { Alt = true })));
|
||||
Assert.True (menu.IsMenuOpen);
|
||||
Application.Top.Redraw (Application.Top.Bounds);
|
||||
var expected = @"
|
||||
File Edit
|
||||
";
|
||||
|
||||
var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
||||
Assert.Equal (new Rect (2, 0, 13, 1), pos);
|
||||
|
||||
Assert.True (menu.ProcessKey (new (Key.N, null)));
|
||||
Application.MainLoop.MainIteration ();
|
||||
Assert.True (newAction);
|
||||
|
||||
Assert.True (menu.ProcessHotKey (new (Key.AltMask, new KeyModifiers () { Alt = true })));
|
||||
Assert.True (menu.IsMenuOpen);
|
||||
Application.Top.Redraw (Application.Top.Bounds);
|
||||
expected = @"
|
||||
File Edit
|
||||
";
|
||||
|
||||
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
||||
Assert.Equal (new Rect (2, 0, 13, 1), pos);
|
||||
|
||||
Assert.True (menu.ProcessKey (new (Key.CursorRight, null)));
|
||||
Assert.True (menu.ProcessKey (new (Key.C, null)));
|
||||
Application.MainLoop.MainIteration ();
|
||||
Assert.True (copyAction);
|
||||
}
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
public void HotKey_MenuBar_ProcessHotKey_Menu_ProcessKey ()
|
||||
{
|
||||
var newAction = false;
|
||||
var copyAction = false;
|
||||
|
||||
var menu = new MenuBar (new MenuBarItem [] {
|
||||
new MenuBarItem ("_File", new MenuItem [] {
|
||||
new MenuItem ("_New", "", () => newAction = true)
|
||||
}),
|
||||
new MenuBarItem ("_Edit", new MenuItem [] {
|
||||
new MenuItem ("_Copy", "", () => copyAction = true)
|
||||
})
|
||||
});
|
||||
|
||||
Application.Top.Add (menu);
|
||||
|
||||
Assert.False (newAction);
|
||||
Assert.False (copyAction);
|
||||
|
||||
Assert.True (menu.ProcessHotKey (new (Key.AltMask | Key.F, new KeyModifiers () { Alt = true })));
|
||||
Assert.True (menu.IsMenuOpen);
|
||||
Application.Top.Redraw (Application.Top.Bounds);
|
||||
var expected = @"
|
||||
File Edit
|
||||
┌───────┐
|
||||
│ New │
|
||||
└───────┘
|
||||
";
|
||||
|
||||
var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
||||
Assert.Equal (new Rect (2, 0, 13, 4), pos);
|
||||
|
||||
Assert.True (Application.Top.Subviews [1].ProcessKey (new (Key.N, null)));
|
||||
Application.MainLoop.MainIteration ();
|
||||
Assert.True (newAction);
|
||||
|
||||
Assert.True (menu.ProcessHotKey (new (Key.AltMask | Key.E, new KeyModifiers () { Alt = true })));
|
||||
Assert.True (menu.IsMenuOpen);
|
||||
Application.Top.Redraw (Application.Top.Bounds);
|
||||
expected = @"
|
||||
File Edit
|
||||
┌────────┐
|
||||
│ Copy │
|
||||
└────────┘
|
||||
";
|
||||
|
||||
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
||||
Assert.Equal (new Rect (2, 0, 17, 4), pos);
|
||||
|
||||
Assert.True (Application.Top.Subviews [1].ProcessKey (new (Key.C, null)));
|
||||
Application.MainLoop.MainIteration ();
|
||||
Assert.True (copyAction);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1876,8 +1876,8 @@ namespace Terminal.Gui.Core {
|
||||
└──────┘
|
||||
";
|
||||
|
||||
var pos = GraphViewTests.AssertDriverContentsWithPosAre (expected, output);
|
||||
Assert.Equal (new Point (0, 0), pos);
|
||||
var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
||||
Assert.Equal (new Rect (0, 0, 8, 4), pos);
|
||||
}
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
@@ -1900,8 +1900,8 @@ namespace Terminal.Gui.Core {
|
||||
──────┘
|
||||
";
|
||||
|
||||
var pos = GraphViewTests.AssertDriverContentsWithPosAre (expected, output);
|
||||
Assert.Equal (new Point (0, 0), pos);
|
||||
var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
||||
Assert.Equal (new Rect (0, 0, 7, 4), pos);
|
||||
|
||||
view.Frame = new Rect (-1, -1, 8, 4);
|
||||
Application.Refresh ();
|
||||
@@ -1912,33 +1912,33 @@ namespace Terminal.Gui.Core {
|
||||
──────┘
|
||||
";
|
||||
|
||||
pos = GraphViewTests.AssertDriverContentsWithPosAre (expected, output);
|
||||
Assert.Equal (new Point (6, 0), pos);
|
||||
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
||||
Assert.Equal (new Rect (6, 0, 7, 3), pos);
|
||||
|
||||
view.Frame = new Rect (0, 0, 8, 4);
|
||||
((FakeDriver)Application.Driver).SetBufferSize (7, 4);
|
||||
|
||||
expected = @"
|
||||
┌──────
|
||||
│
|
||||
│
|
||||
│
|
||||
│
|
||||
└──────
|
||||
";
|
||||
|
||||
pos = GraphViewTests.AssertDriverContentsWithPosAre (expected, output);
|
||||
Assert.Equal (new Point (0, 0), pos);
|
||||
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
||||
Assert.Equal (new Rect (0, 0, 7, 4), pos);
|
||||
|
||||
view.Frame = new Rect (0, 0, 8, 4);
|
||||
((FakeDriver)Application.Driver).SetBufferSize (7, 3);
|
||||
|
||||
expected = @"
|
||||
┌──────
|
||||
│
|
||||
│
|
||||
│
|
||||
│
|
||||
";
|
||||
|
||||
pos = GraphViewTests.AssertDriverContentsWithPosAre (expected, output);
|
||||
Assert.Equal (new Point (0, 0), pos);
|
||||
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
||||
Assert.Equal (new Rect (0, 0, 7, 3), pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user