public void PathAnnotation_Box() { var gv = GraphViewTests.GetGraph(); var path = new PathAnnotation(); path.Points.Add(new PointF(1, 1)); path.Points.Add(new PointF(1, 3)); path.Points.Add(new PointF(6, 3)); path.Points.Add(new PointF(6, 1)); // list the starting point again so that it draws a complete square // (otherwise it will miss out the last line along the bottom) path.Points.Add(new PointF(1, 1)); gv.Annotations.Add(path); gv.Redraw(gv.Bounds); var expected = @" │...... ┤. . ┤...... 0┼┬┬┬┬┬┬┬┬ 0 5"; GraphViewTests.AssertDriverContentsAre(expected); }
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); }
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); }
public void PathAnnotation_Box() { var gv = GraphViewTests.GetGraph(); var path = new PathAnnotation(); path.Points.Add(new PointF(1, 1)); path.Points.Add(new PointF(1, 3)); path.Points.Add(new PointF(6, 3)); path.Points.Add(new PointF(6, 1)); // list the starting point again so that it draws a complete square // (otherwise it will miss out the last line along the bottom) path.Points.Add(new PointF(1, 1)); gv.Annotations.Add(path); gv.Redraw(gv.Bounds); 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 PathAnnotation_Diamond() { var gv = GraphViewTests.GetGraph(); var path = new PathAnnotation(); path.Points.Add(new PointF(1, 2)); path.Points.Add(new PointF(3, 3)); path.Points.Add(new PointF(6, 2)); path.Points.Add(new PointF(3, 1)); // list the starting point again to close the shape path.Points.Add(new PointF(1, 2)); gv.Annotations.Add(path); gv.Redraw(gv.Bounds); 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 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 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 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 PathAnnotation_Diamond() { var gv = GraphViewTests.GetGraph(); var path = new PathAnnotation(); path.Points.Add(new PointF(1, 2)); path.Points.Add(new PointF(3, 3)); path.Points.Add(new PointF(6, 2)); path.Points.Add(new PointF(3, 1)); // list the starting point again to close the shape path.Points.Add(new PointF(1, 2)); gv.Annotations.Add(path); gv.Redraw(gv.Bounds); var expected = @" │ .. ┤.. .. ┤ ... 0┼┬┬┬┬┬┬┬┬ 0 5"; GraphViewTests.AssertDriverContentsAre(expected); }
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(); }
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); }
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 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 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 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 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_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 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 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(); }
public void LongColumnTest() { GraphViewTests.InitFakeDriver(); var tableView = new TableView(); tableView.ColorScheme = Colors.TopLevel; // 25 characters can be printed into table tableView.Bounds = new Rect(0, 0, 25, 5); tableView.Style.ShowHorizontalHeaderUnderline = true; 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("Very Long Column"); dt.Rows.Add(1, 2, new string('a', 500)); dt.Rows.Add(1, 2, "aaa"); tableView.Table = dt; tableView.Redraw(tableView.Bounds); // default behaviour of TableView is not to render // columns unless there is sufficient space string expected = @" │A│B │ ├─┼─────────────────────► │1│2 │ │1│2 │ "; GraphViewTests.AssertDriverContentsAre(expected, output); // get a style for the long column var style = tableView.Style.GetOrCreateColumnStyle(dt.Columns[2]); // one way the API user can fix this for long columns // is to specify a max width for the column style.MaxWidth = 10; tableView.Redraw(tableView.Bounds); expected = @" │A│B│Very Long │ ├─┼─┼───────────────────┤ │1│2│aaaaaaaaaa │ │1│2│aaa │ "; GraphViewTests.AssertDriverContentsAre(expected, output); // revert the style change style.MaxWidth = TableView.DefaultMaxCellWidth; // another way API user can fix problem is to implement // RepresentationGetter and apply max length there style.RepresentationGetter = (s) => { return(s.ToString().Length < 15 ? s.ToString() : s.ToString().Substring(0, 13) + "..."); }; tableView.Redraw(tableView.Bounds); expected = @" │A│B│Very Long Column │ ├─┼─┼───────────────────┤ │1│2│aaaaaaaaaaaaa... │ │1│2│aaa │ "; GraphViewTests.AssertDriverContentsAre(expected, output); // revert style change style.RepresentationGetter = null; // Both of the above methods rely on having a fixed // size limit for the column. These are awkward if a // table is resizeable e.g. Dim.Fill(). Ideally we want // to render in any space available and truncate the content // of the column dynamically so it fills the free space at // the end of the table. // We can now specify that the column can be any length // (Up to MaxWidth) but the renderer can accept using // less space down to this limit style.MinAcceptableWidth = 5; tableView.Redraw(tableView.Bounds); expected = @" │A│B│Very Long Column │ ├─┼─┼───────────────────┤ │1│2│aaaaaaaaaaaaaaaaaaa│ │1│2│aaa │ "; GraphViewTests.AssertDriverContentsAre(expected, output); // Now test making the width too small for the MinAcceptableWidth // the Column won't fit so should not be rendered Application.Shutdown(); GraphViewTests.InitFakeDriver(); tableView.Bounds = new Rect(0, 0, 9, 5); tableView.Redraw(tableView.Bounds); expected = @" │A│B │ ├─┼─────► │1│2 │ │1│2 │ "; GraphViewTests.AssertDriverContentsAre(expected, output); // setting width to 10 leaves just enough space for the column to // meet MinAcceptableWidth of 5. Column width includes terminator line // symbol (e.g. ┤ or │) tableView.Bounds = new Rect(0, 0, 10, 5); tableView.Redraw(tableView.Bounds); expected = @" │A│B│Very│ ├─┼─┼────┤ │1│2│aaaa│ │1│2│aaa │ "; GraphViewTests.AssertDriverContentsAre(expected, output); Application.Shutdown(); }
public void TestTreeViewColor() { 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); var pink = new Attribute(Color.Magenta, Color.Black); var hotpink = new Attribute(Color.BrightMagenta, Color.Black); tv.ColorScheme = new ColorScheme(); tv.Redraw(tv.Bounds); // Normal drawing of the tree view GraphViewTests.AssertDriverContentsAre( @"├-normal │ ├─pink │ └─normal └─pink ", output); // Should all be the same color GraphViewTests.AssertDriverColorsAre( @"00000000 00000000 0000000000 000000 ", new [] { tv.ColorScheme.Normal, pink }); // create a new color scheme var pinkScheme = new ColorScheme { Normal = pink, Focus = hotpink }; // and a delegate that uses the pink color scheme // for nodes "pink" tv.ColorGetter = (n) => n.Text.Equals("pink") ? pinkScheme : null; // redraw now that the custom color // delegate is registered tv.Redraw(tv.Bounds); // Same text GraphViewTests.AssertDriverContentsAre( @"├-normal │ ├─pink │ └─normal └─pink ", output); // but now the item (only not lines) appear // in pink when they are the word "pink" GraphViewTests.AssertDriverColorsAre( @"00000000 00001111 0000000000 001111 ", new [] { tv.ColorScheme.Normal, pink }); }
public void TestGetObjectRow() { 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.Equal(0, tv.GetObjectRow(n1)); Assert.Equal(1, tv.GetObjectRow(n1_1)); Assert.Equal(2, tv.GetObjectRow(n1_2)); Assert.Equal(3, tv.GetObjectRow(n2)); tv.Collapse(n1); tv.Redraw(tv.Bounds); GraphViewTests.AssertDriverContentsAre( @"├+normal └─pink ", output); Assert.Equal(0, tv.GetObjectRow(n1)); Assert.Null(tv.GetObjectRow(n1_1)); Assert.Null(tv.GetObjectRow(n1_2)); Assert.Equal(1, tv.GetObjectRow(n2)); // scroll down 1 tv.ScrollOffsetVertical = 1; tv.Redraw(tv.Bounds); GraphViewTests.AssertDriverContentsAre( @"└─pink ", output); Assert.Equal(-1, tv.GetObjectRow(n1)); Assert.Null(tv.GetObjectRow(n1_1)); Assert.Null(tv.GetObjectRow(n1_2)); Assert.Equal(0, tv.GetObjectRow(n2)); }
public void ScrollIndicators() { 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 = true; 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); // user can only scroll right so sees right indicator // Because first column in table is A string expected = @" │A│B│C│ ├─┼─┼─► │1│2│3│"; GraphViewTests.AssertDriverContentsAre(expected, output); // Scroll right tableView.ProcessKey(new KeyEvent() { Key = Key.CursorRight }); // since A is now pushed off screen we get indicator showing // that user can scroll left to see first column tableView.Redraw(tableView.Bounds); expected = @" │B│C│D│ ◄─┼─┼─► │2│3│4│"; GraphViewTests.AssertDriverContentsAre(expected, output); // Scroll right twice more (to end of columns) tableView.ProcessKey(new KeyEvent() { Key = Key.CursorRight }); tableView.ProcessKey(new KeyEvent() { Key = Key.CursorRight }); tableView.Redraw(tableView.Bounds); 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 TestThinTabView_WithLongNames() { var tv = GetTabView(out var tab1, out var tab2, false); tv.Width = 10; tv.Height = 5; // Ensures that the tab bar subview gets the bounds of the parent TabView tv.LayoutSubviews(); // Test two tab names that fit tab1.Text = "12"; tab2.Text = "13"; tv.Redraw(tv.Bounds); GraphViewTests.AssertDriverContentsAre(@" ┌──┐ │12│13 │ └─────┐ │hi │ └────────┘", output); // Test first tab name too long tab1.Text = "12345678910"; tab2.Text = "13"; tv.Redraw(tv.Bounds); GraphViewTests.AssertDriverContentsAre(@" ┌───────┐ │1234567│ │ └► │hi │ └────────┘", output); //switch to tab2 tv.SelectedTab = tab2; tv.Redraw(tv.Bounds); GraphViewTests.AssertDriverContentsAre(@" ┌──┐ │13│ ◄ └─────┐ │hi2 │ └────────┘", output); // now make both tabs too long tab1.Text = "12345678910"; tab2.Text = "abcdefghijklmnopq"; tv.Redraw(tv.Bounds); GraphViewTests.AssertDriverContentsAre(@" ┌───────┐ │abcdefg│ ◄ └┐ │hi2 │ └────────┘", output); }
public void TestRendering_MultibarSeries() { GraphViewTests.InitFakeDriver(); var gv = new GraphView(); gv.ColorScheme = new ColorScheme(); // 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.MarginBottom = 1; gv.MarginLeft = 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) { sub.Offset -= 0.001f; } gv.Series.Add(multibarSeries); FakeHAxis fakeXAxis; // 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.Redraw(gv.Bounds); // Since bar series has no bars yet no labels should be displayed 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("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 = @" │ MM │ M MM │ M MM │ MM M MM │ MM M MM │ MM M MM │ MM MM MM │ MM MM MM ┼──┬M──┬M──┬M────── heytherebob "; GraphViewTests.AssertDriverContentsAre(looksLike); }