public void LegendNormalUsage_WithBorder() { var gv = GraphViewTests.GetGraph(); var legend = new LegendAnnotation(new Rect(2, 0, 5, 3)); legend.AddEntry(new GraphCellToRender('A'), "Ant"); legend.AddEntry(new GraphCellToRender('B'), "Bat"); gv.Annotations.Add(legend); gv.Redraw(gv.Bounds); var expected = @" │┌───┐ ┤│AAn│ ┤└───┘ 0┼┬┬┬┬┬┬┬┬ 0 5"; GraphViewTests.AssertDriverContentsAre(expected, output); // Shutdown must be called to safely clean up Application if Init has been called Application.Shutdown(); }
public void LegendNormalUsage_WithoutBorder() { var gv = GraphViewTests.GetGraph(); var legend = new LegendAnnotation(new Rect(2, 0, 5, 3)); legend.AddEntry(new GraphCellToRender('A'), "Ant"); legend.AddEntry(new GraphCellToRender('B'), "?"); // this will exercise pad legend.AddEntry(new GraphCellToRender('C'), "Cat"); legend.AddEntry(new GraphCellToRender('H'), "Hattter"); // not enough space for this oen legend.Border = false; gv.Annotations.Add(legend); gv.Redraw(gv.Bounds); var expected = @" │AAnt ┤B? ┤CCat 0┼┬┬┬┬┬┬┬┬ 0 5"; GraphViewTests.AssertDriverContentsAre(expected, output); // Shutdown must be called to safely clean up Application if Init has been called Application.Shutdown(); }
public void TestTextAnnotation_EmptyText(string whitespace) { var gv = GraphViewTests.GetGraph(); gv.Annotations.Add(new TextAnnotation() { Text = whitespace, GraphPosition = new PointF(4, 2) }); // 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)); gv.Series.Add(points); gv.Redraw(gv.Bounds); var expected = @" │ ┤ x ┤ 0┼┬┬┬┬┬┬┬┬ 0 5"; GraphViewTests.AssertDriverContentsAre(expected, output); // Shutdown must be called to safely clean up Application if Init has been called Application.Shutdown(); }
public void TestTextAnnotation_Offscreen() { var gv = GraphViewTests.GetGraph(); gv.Annotations.Add(new TextAnnotation() { Text = "hey there partner hows it going boy its great", GraphPosition = new PointF(9, 2) }); gv.Redraw(gv.Bounds); // Text is off the screen (graph x axis runs to 8 not 9) var expected = @" │ ┤ ┤ 0┼┬┬┬┬┬┬┬┬ 0 5"; GraphViewTests.AssertDriverContentsAre(expected, output); // Shutdown must be called to safely clean up Application if Init has been called Application.Shutdown(); }
public void TestTextAnnotation_LongText() { var gv = GraphViewTests.GetGraph(); gv.Annotations.Add(new TextAnnotation() { Text = "hey there partner hows it going boy its great", GraphPosition = new PointF(2, 2) }); gv.Redraw(gv.Bounds); // long text should get truncated // margin takes up 1 units // the GraphPosition of the anntation is 2 // Leaving 7 characters of the annotation renderable (including space) var expected = @" │ ┤ hey the ┤ 0┼┬┬┬┬┬┬┬┬ 0 5"; GraphViewTests.AssertDriverContentsAre(expected, output); // Shutdown must be called to safely clean up Application if Init has been called Application.Shutdown(); }
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); }
public void TableView_ColorsTest_ColorGetter() { var tv = SetUpMiniTable(); tv.Style.ExpandLastColumn = false; tv.Style.InvertSelectedCellFirstCharacter = true; // width exactly matches the max col widths tv.Bounds = new Rect(0, 0, 5, 4); // Create a style for column B var bStyle = tv.Style.GetOrCreateColumnStyle(tv.Table.Columns ["B"]); // when B is 2 use the custom highlight colour ColorScheme cellHighlight = new ColorScheme() { Normal = Attribute.Make(Color.BrightCyan, Color.DarkGray) }; bStyle.ColorGetter = (a) => Convert.ToInt32(a.CellValue) == 2 ? cellHighlight : null; tv.Redraw(tv.Bounds); string expected = @" ┌─┬─┐ │A│B│ ├─┼─┤ │1│2│ "; GraphViewTests.AssertDriverContentsAre(expected, output); string expectedColors = @" 00000 00000 00000 01020 "; var invertedNormalColor = Application.Driver.MakeAttribute(tv.ColorScheme.Normal.Background, tv.ColorScheme.Normal.Foreground); GraphViewTests.AssertDriverColorsAre(expectedColors, new Attribute [] { // 0 tv.ColorScheme.Normal, // 1 invertedNormalColor, // 2 cellHighlight.Normal }); // Shutdown must be called to safely clean up Application if Init has been called Application.Shutdown(); }
/// <summary> /// Returns a basic very small graph (10 x 5) /// </summary> /// <returns></returns> public static GraphView GetGraph() { GraphViewTests.InitFakeDriver(); var gv = new GraphView(); gv.ColorScheme = new ColorScheme(); gv.MarginBottom = 1; gv.MarginLeft = 1; gv.Bounds = new Rect(0, 0, 10, 5); return(gv); }
public void TestGetObjectOnRow() { var tv = new TreeView { Width = 20, Height = 10 }; var n1 = new TreeNode("normal"); var n1_1 = new TreeNode("pink"); var n1_2 = new TreeNode("normal"); n1.Children.Add(n1_1); n1.Children.Add(n1_2); var n2 = new TreeNode("pink"); tv.AddObject(n1); tv.AddObject(n2); tv.Expand(n1); tv.ColorScheme = new ColorScheme(); tv.Redraw(tv.Bounds); GraphViewTests.AssertDriverContentsAre( @"├-normal │ ├─pink │ └─normal └─pink ", output); Assert.Same(n1, tv.GetObjectOnRow(0)); Assert.Same(n1_1, tv.GetObjectOnRow(1)); Assert.Same(n1_2, tv.GetObjectOnRow(2)); Assert.Same(n2, tv.GetObjectOnRow(3)); Assert.Null(tv.GetObjectOnRow(4)); tv.Collapse(n1); tv.Redraw(tv.Bounds); GraphViewTests.AssertDriverContentsAre( @"├+normal └─pink ", output); Assert.Same(n1, tv.GetObjectOnRow(0)); Assert.Same(n2, tv.GetObjectOnRow(1)); Assert.Null(tv.GetObjectOnRow(2)); Assert.Null(tv.GetObjectOnRow(3)); Assert.Null(tv.GetObjectOnRow(4)); }
public void TestTabView_Width3() { var tv = GetTabView(out _, out _, false); tv.Width = 3; tv.Height = 5; tv.LayoutSubviews(); tv.Redraw(tv.Bounds); GraphViewTests.AssertDriverContentsAre(@" ┌─┐ │hi └─┘", output); }
private GraphView GetGraph(out FakeHAxis axisX, out FakeVAxis axisY) { GraphViewTests.InitFakeDriver(); var gv = new GraphView(); gv.ColorScheme = new ColorScheme(); gv.Bounds = new Rect(0, 0, 50, 30); // graph can't be completely empty or it won't draw gv.Series.Add(new ScatterSeries()); axisX = new FakeHAxis(); axisY = new FakeVAxis(); gv.AxisX = axisX; gv.AxisY = axisY; return(gv); }
public void TableView_ExpandLastColumn_False() { var tv = SetUpMiniTable(); // the thing we are testing tv.Style.ExpandLastColumn = false; tv.Redraw(tv.Bounds); string expected = @" ┌─┬─┬────┐ │A│B│ │ ├─┼─┼────┤ │1│2│ │ "; GraphViewTests.AssertDriverContentsAre(expected); }
public void MenuBar_ButtonPressed_Open_The_Menu_ButtonPressed_Again_Close_The_Menu() { var menu = new MenuBar(new MenuBarItem [] { new MenuBarItem("File", new MenuItem [] { new MenuItem("New", "", null) }), new MenuBarItem("Edit", new MenuItem [] { new MenuItem("Copy", "", null) }) }); Application.Top.Add(menu); Assert.True(menu.MouseEvent(new MouseEvent() { X = 1, Y = 0, Flags = MouseFlags.Button1Pressed, View = menu })); 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(menu.MouseEvent(new MouseEvent() { X = 1, Y = 0, Flags = MouseFlags.Button1Pressed, View = menu })); Assert.False(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); }
public void TestTextAnnotation_GraphUnits() { var gv = GraphViewTests.GetGraph(); gv.Annotations.Add(new TextAnnotation() { Text = "hey!", GraphPosition = new PointF(2, 2) }); gv.Redraw(gv.Bounds); var expected = @" │ ┤ hey! ┤ 0┼┬┬┬┬┬┬┬┬ 0 5"; GraphViewTests.AssertDriverContentsAre(expected, output); // user scrolls up one unit of graph space gv.ScrollOffset = new PointF(0, 1f); gv.Redraw(gv.Bounds); // we expect the text annotation to go down one line since // the scroll offset means that that point of graph space is // lower down in the view. Note the 1 on the axis too, our viewport // (excluding margins) now shows y of 1 to 4 (previously 0 to 5) expected = @" │ ┤ ┤ hey! 1┼┬┬┬┬┬┬┬┬ 0 5"; GraphViewTests.AssertDriverContentsAre(expected, output); // Shutdown must be called to safely clean up Application if Init has been called Application.Shutdown(); }
public void Series_GetsPassedCorrectBounds_AllAtOnce_LargeCellSize() { GraphViewTests.InitFakeDriver(); var gv = new GraphView(); gv.ColorScheme = new ColorScheme(); gv.Bounds = new Rect(0, 0, 50, 30); // the larger the cell size the more condensed (smaller) the graph space is gv.CellSize = new PointF(2, 5); RectangleF fullGraphBounds = RectangleF.Empty; Rect graphScreenBounds = Rect.Empty; var series = new FakeSeries((v, s, g) => { graphScreenBounds = s; fullGraphBounds = g; }); gv.Series.Add(series); gv.Redraw(gv.Bounds); // Since each cell of the console is 2x5 of graph space the graph // bounds to be rendered are larger Assert.Equal(new RectangleF(0, 0, 100, 150), fullGraphBounds); Assert.Equal(new Rect(0, 0, 50, 30), graphScreenBounds); // Graph should not spill into the margins gv.MarginBottom = 2; gv.MarginLeft = 5; // Even with a margin the graph should be drawn from // the origin, we just get less visible width/height gv.Redraw(gv.Bounds); Assert.Equal(new RectangleF(0, 0, 90, 140), fullGraphBounds); // The screen space the graph will be rendered into should // not overspill the margins Assert.Equal(new Rect(5, 0, 45, 28), graphScreenBounds); // Shutdown must be called to safely clean up Application if Init has been called Application.Shutdown(); }
public void TestTextAnnotation_ScreenUnits() { var gv = GraphViewTests.GetGraph(); gv.Annotations.Add(new TextAnnotation() { Text = "hey!", ScreenPosition = new Point(3, 1) }); gv.Redraw(gv.Bounds); var expected = @" │ ┤ hey! ┤ 0┼┬┬┬┬┬┬┬┬ 0 5"; GraphViewTests.AssertDriverContentsAre(expected, output); // user scrolls up one unit of graph space gv.ScrollOffset = new PointF(0, 1f); 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 expected = @" │ ┤ hey! ┤ 1┼┬┬┬┬┬┬┬┬ 0 5"; GraphViewTests.AssertDriverContentsAre(expected, output); // Shutdown must be called to safely clean up Application if Init has been called Application.Shutdown(); }
public void TableView_ExpandLastColumn_False_ExactBounds() { var tv = SetUpMiniTable(); // the thing we are testing tv.Style.ExpandLastColumn = false; // width exactly matches the max col widths tv.Bounds = new Rect(0, 0, 5, 4); tv.Redraw(tv.Bounds); string expected = @" ┌─┬─┐ │A│B│ ├─┼─┤ │1│2│ "; GraphViewTests.AssertDriverContentsAre(expected); }
public void LegendNormalUsage_WithBorder() { var gv = GraphViewTests.GetGraph(); var legend = new LegendAnnotation(new Rect(2, 0, 5, 3)); legend.AddEntry(new GraphCellToRender('A'), "Ant"); legend.AddEntry(new GraphCellToRender('B'), "Bat"); gv.Annotations.Add(legend); gv.Redraw(gv.Bounds); var expected = @" │┌───┐ ┤│AAn│ ┤└───┘ 0┼┬┬┬┬┬┬┬┬ 0 5"; GraphViewTests.AssertDriverContentsAre(expected); }
public void TableView_ExpandLastColumn_False() { var tv = SetUpMiniTable(); // the thing we are testing tv.Style.ExpandLastColumn = false; tv.Redraw(tv.Bounds); string expected = @" ┌─┬─┬────┐ │A│B│ │ ├─┼─┼────┤ │1│2│ │ "; GraphViewTests.AssertDriverContentsAre(expected, output); // Shutdown must be called to safely clean up Application if Init has been called Application.Shutdown(); }
public void Update_Parameterless_Only_On_Or_After_Initialize() { var btn = new Button() { X = Pos.Center(), Y = Pos.Center(), Text = "Say Hello 你" }; var win = new Window() { Width = Dim.Fill(), Height = Dim.Fill(), Title = "Test Demo 你" }; win.Add(btn); Application.Top.Add(win); Assert.False(btn.IsInitialized); Application.Begin(Application.Top); ((FakeDriver)Application.Driver).SetBufferSize(30, 5); Assert.True(btn.IsInitialized); Assert.Equal("Say Hello 你", btn.Text); Assert.Equal("[ Say Hello 你 ]", btn.TextFormatter.Text); Assert.Equal(new Rect(0, 0, 16, 1), btn.Bounds); var expected = @" ┌ Test Demo 你 ──────────────┐ │ │ │ [ Say Hello 你 ] │ │ │ └────────────────────────────┘ "; var pos = GraphViewTests.AssertDriverContentsWithFrameAre(expected, output); Assert.Equal(new Rect(0, 0, 30, 5), pos); }
public void Series_GetsPassedCorrectBounds_AllAtOnce() { GraphViewTests.InitFakeDriver(); var gv = new GraphView(); gv.ColorScheme = new ColorScheme(); gv.Bounds = new Rect(0, 0, 50, 30); RectangleF fullGraphBounds = RectangleF.Empty; Rect graphScreenBounds = Rect.Empty; var series = new FakeSeries((v, s, g) => { graphScreenBounds = s; fullGraphBounds = g; }); gv.Series.Add(series); gv.Redraw(gv.Bounds); Assert.Equal(new RectangleF(0, 0, 50, 30), fullGraphBounds); Assert.Equal(new Rect(0, 0, 50, 30), graphScreenBounds); // Now we put a margin in // Graph should not spill into the margins gv.MarginBottom = 2; gv.MarginLeft = 5; // Even with a margin the graph should be drawn from // the origin, we just get less visible width/height gv.Redraw(gv.Bounds); Assert.Equal(new RectangleF(0, 0, 45, 28), fullGraphBounds); // The screen space the graph will be rendered into should // not overspill the margins Assert.Equal(new Rect(5, 0, 45, 28), graphScreenBounds); // Shutdown must be called to safely clean up Application if Init has been called Application.Shutdown(); }
public void TestTextAnnotation_Offscreen() { var gv = GraphViewTests.GetGraph(); gv.Annotations.Add(new TextAnnotation() { Text = "hey there partner hows it going boy its great", GraphPosition = new PointF(9, 2) }); gv.Redraw(gv.Bounds); // Text is off the screen (graph x axis runs to 8 not 9) var expected = @" │ ┤ ┤ 0┼┬┬┬┬┬┬┬┬ 0 5"; GraphViewTests.AssertDriverContentsAre(expected); }
public void TableView_ExpandLastColumn_False_ExactBounds() { var tv = SetUpMiniTable(); // the thing we are testing tv.Style.ExpandLastColumn = false; // width exactly matches the max col widths tv.Bounds = new Rect(0, 0, 5, 4); tv.Redraw(tv.Bounds); string expected = @" ┌─┬─┐ │A│B│ ├─┼─┤ │1│2│ "; GraphViewTests.AssertDriverContentsAre(expected, output); // Shutdown must be called to safely clean up Application if Init has been called Application.Shutdown(); }
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); }
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); }
public void DrawFrame_With_Negative_Positions() { var menu = new MenuBar(new MenuBarItem [] { new MenuBarItem(new MenuItem [] { new MenuItem("One", "", null), new MenuItem("Two", "", null) }) }) { X = -1, Y = -1 }; Assert.Equal(new Point(-1, -1), new Point(menu.Frame.X, menu.Frame.Y)); menu.OpenMenu(); Application.Begin(Application.Top); var expected = @" ──────┐ One │ Two │ ──────┘ "; 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); menu.OpenMenu(); Application.Refresh(); expected = @" One │ Two │ ──────┘ "; 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); ((FakeDriver)Application.Driver).SetBufferSize(7, 5); menu.OpenMenu(); Application.Refresh(); expected = @" ┌────── │ One │ Two └────── "; 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); ((FakeDriver)Application.Driver).SetBufferSize(7, 4); menu.OpenMenu(); Application.Refresh(); expected = @" ┌────── │ One │ Two "; pos = GraphViewTests.AssertDriverContentsWithFrameAre(expected, output); Assert.Equal(new Rect(0, 1, 7, 3), pos); }
public void MenuBar_Position_And_Size_With_HotKeys_Is_The_Same_As_Without_HotKeys() { // With HotKeys var menu = new MenuBar(new MenuBarItem [] { new MenuBarItem("_File", new MenuItem [] { new MenuItem("_New", "", null) }), new MenuBarItem("_Edit", new MenuItem [] { new MenuItem("_Copy", "", null) }) }); Application.Top.Add(menu); Assert.True(menu.ProcessHotKey(new (Key.F9, new KeyModifiers()))); 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.CursorRight, null))); 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, 16, 4), pos); Assert.True(menu.ProcessHotKey(new (Key.F9, new KeyModifiers()))); Assert.False(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); // Without HotKeys menu = new MenuBar(new MenuBarItem [] { new MenuBarItem("File", new MenuItem [] { new MenuItem("New", "", null) }), new MenuBarItem("Edit", new MenuItem [] { new MenuItem("Copy", "", null) }) }); Assert.True(menu.ProcessHotKey(new (Key.F9, new KeyModifiers()))); Assert.True(menu.IsMenuOpen); Application.Top.Redraw(Application.Top.Bounds); expected = @" File Edit ┌──────┐ │ New │ └──────┘ "; pos = GraphViewTests.AssertDriverContentsWithFrameAre(expected, output); Assert.Equal(new Rect(2, 0, 13, 4), pos); Assert.True(Application.Top.Subviews [1].ProcessKey(new (Key.CursorRight, null))); 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, 16, 4), pos); }
public void MenuOpening_MenuOpened_MenuClosing_Events() { var miAction = ""; var isMenuClosed = true; var cancelClosing = false; var menu = new MenuBar(new MenuBarItem [] { new MenuBarItem("_File", new MenuItem [] { new MenuItem("_New", "Creates new file.", New) }) }); menu.MenuOpening += (e) => { Assert.Equal("_File", e.CurrentMenu.Title); Assert.Equal("_New", e.CurrentMenu.Children [0].Title); Assert.Equal("Creates new file.", e.CurrentMenu.Children [0].Help); Assert.Equal(New, e.CurrentMenu.Children [0].Action); e.CurrentMenu.Children [0].Action(); Assert.Equal("New", miAction); e.NewMenuBarItem = new MenuBarItem("_Edit", new MenuItem [] { new MenuItem("_Copy", "Copies the selection.", Copy) }); }; menu.MenuOpened += (e) => { Assert.Equal("_Edit", e.Parent.Title); Assert.Equal("_Copy", e.Title); Assert.Equal("Copies the selection.", e.Help); Assert.Equal(Copy, e.Action); e.Action(); Assert.Equal("Copy", miAction); }; menu.MenuClosing += (e) => { Assert.False(isMenuClosed); if (cancelClosing) { e.Cancel = true; isMenuClosed = false; } else { isMenuClosed = true; } }; Application.Top.Add(menu); Assert.True(menu.ProcessHotKey(new KeyEvent(Key.F9, new KeyModifiers()))); Assert.True(menu.IsMenuOpen); isMenuClosed = !menu.IsMenuOpen; Assert.False(isMenuClosed); Application.Top.Redraw(Application.Top.Bounds); var expected = @" Edit ┌──────────────────────────────┐ │ Copy Copies the selection. │ └──────────────────────────────┘ "; GraphViewTests.AssertDriverContentsAre(expected, output); cancelClosing = true; Assert.True(menu.ProcessHotKey(new KeyEvent(Key.F9, new KeyModifiers()))); Assert.True(menu.IsMenuOpen); Assert.False(isMenuClosed); Application.Top.Redraw(Application.Top.Bounds); expected = @" Edit ┌──────────────────────────────┐ │ Copy Copies the selection. │ └──────────────────────────────┘ "; GraphViewTests.AssertDriverContentsAre(expected, output); cancelClosing = false; Assert.True(menu.ProcessHotKey(new KeyEvent(Key.F9, new KeyModifiers()))); Assert.False(menu.IsMenuOpen); Assert.True(isMenuClosed); Application.Top.Redraw(Application.Top.Bounds); expected = @" Edit "; GraphViewTests.AssertDriverContentsAre(expected, output); void New() => miAction = "New"; void Copy() => miAction = "Copy"; }
public void ScrollRight_WithoutSmoothScrolling() { GraphViewTests.InitFakeDriver(); var tableView = new TableView(); tableView.ColorScheme = Colors.TopLevel; // 3 columns are visibile tableView.Bounds = new Rect(0, 0, 7, 5); tableView.Style.ShowHorizontalHeaderUnderline = false; tableView.Style.ShowHorizontalHeaderOverline = false; tableView.Style.AlwaysShowHeaders = true; tableView.Style.SmoothHorizontalScrolling = false; var dt = new DataTable(); dt.Columns.Add("A"); dt.Columns.Add("B"); dt.Columns.Add("C"); dt.Columns.Add("D"); dt.Columns.Add("E"); dt.Columns.Add("F"); dt.Rows.Add(1, 2, 3, 4, 5, 6); tableView.Table = dt; // select last visible column tableView.SelectedColumn = 2; // column C tableView.Redraw(tableView.Bounds); string expected = @" │A│B│C│ │1│2│3│"; GraphViewTests.AssertDriverContentsAre(expected, output); // Scroll right tableView.ProcessKey(new KeyEvent() { Key = Key.CursorRight }); tableView.Redraw(tableView.Bounds); // notice that without smooth scrolling we just update the first column // rendered in the table to the newly exposed column (D). This is fast // since we don't have to worry about repeatedly measuring the content // area as we scroll until the new column (D) is exposed. But it makes // the view 'jump' to expose all new columns expected = @" │D│E│F│ │4│5│6│"; GraphViewTests.AssertDriverContentsAre(expected, output); // Shutdown must be called to safely clean up Application if Init has been called Application.Shutdown(); }
public void ScrollRight_SmoothScrolling() { GraphViewTests.InitFakeDriver(); var tableView = new TableView(); tableView.ColorScheme = Colors.TopLevel; // 3 columns are visibile tableView.Bounds = new Rect(0, 0, 7, 5); tableView.Style.ShowHorizontalHeaderUnderline = false; tableView.Style.ShowHorizontalHeaderOverline = false; tableView.Style.AlwaysShowHeaders = true; tableView.Style.SmoothHorizontalScrolling = true; var dt = new DataTable(); dt.Columns.Add("A"); dt.Columns.Add("B"); dt.Columns.Add("C"); dt.Columns.Add("D"); dt.Columns.Add("E"); dt.Columns.Add("F"); dt.Rows.Add(1, 2, 3, 4, 5, 6); tableView.Table = dt; // select last visible column tableView.SelectedColumn = 2; // column C tableView.Redraw(tableView.Bounds); string expected = @" │A│B│C│ │1│2│3│"; GraphViewTests.AssertDriverContentsAre(expected, output); // Scroll right tableView.ProcessKey(new KeyEvent() { Key = Key.CursorRight }); tableView.Redraw(tableView.Bounds); // Note that with SmoothHorizontalScrolling only a single new column // is exposed when scrolling right. This is not always the case though // sometimes if the leftmost column is long (i.e. A is a long column) // then when A is pushed off the screen multiple new columns could be exposed // (not just D but also E and F). This is because TableView never shows // 'half cells' or scrolls by console unit (scrolling is done by table row/column increments). expected = @" │B│C│D│ │2│3│4│"; GraphViewTests.AssertDriverContentsAre(expected, output); // Shutdown must be called to safely clean up Application if Init has been called Application.Shutdown(); }