mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-27 08:17:53 +01:00
* Empty GraphView with basic axis * Added ISeries * Added zoom * Fixed zoom * Tests and scrolling * Refactored AxisView into abstract base * Added atomic mass example * Added Y axis labels * Added Y axis labels * comments * Refactored axis to not be floating views * Split axis drawing code to seperate draw line from draw labels * Added MarginBottom and MarginLeft * Added bar graph * Fixes horizontal axis label generation * Fixed axis labels changing during scrolling * Added test for overlapping cells * Added TestReversing_ScreenToGraphSpace * Changed graph space from float to decimal * Added axis labels * Fixed issues where labels/axis overspilled bounds * Fixed origin screen coordinates being off by 1 in y axis * Added Orientation to BarSeries * Added comments and standardised Name to Text * Added prototype 'population pyramid' * Fixed bar graphs not stopping at axis * Added Reset and Ctrl to speed up scrolling * Added line graph * Fixed LineSeries implementation * Made LineSeries Points readonly and sort on add * Fixed RectangleD.GetHasCode() * Improved performance of LineSeries * Added color to graph * Fixed colors not working on linux * Added Visible and ColorGetter * Added Ctrl+G Next Graph * Added MultiBarSeries * Fixed layout issue with population pyramid * fixed y label overspill and origin rendering * Fixed warnings * Made examples prettier * Fixed xAxis potentially drawing labels outside of control area * Fixed multi bar example labels * Added IAnnotation * Added example of using GraphPosition in IAnnotation * Fixed Annotations drawing outside of graph bounds * Fixed Reset() not clearing Annotations and sp fixes * Changed line drawing to Bresenham's line algorithm and deleted CohenSutherland Testing for collisions with screen space is very slow and gives quite thick lines. I looked at Xiaolin Wu which supports anti aliasing but this also would require more work to look good (out of the box it just looks thick). * Fixed layout/whitespace * Graph now renders without series if annotations are present * Fixed ScreenToGraphSpace rect overload * Added SeriesDrawMode for when it is easier/faster for a series to draw itself all in one go * Added LegendAnnotation * Added tests for correct bounds * Added more tests * Changed GraphView namespace to Terminal.Gui.Graphs * Made Line2D and Horizontal/Vertical axis private classes * Made AxisIncrementToRender.Text internal to avoid confusing user when implementing `LabelGetterDelegate` * Changed back from decimal to float * Refactored axis label drawing to avoid rounding errors * Fixed over spilling bounds when drawing bars/axis increments * Re-implemented disco colors * Added Minimum to Axis * Fixed tests build and render order * Fixed test by adjusting epsilon * tidyup, docs and warning fixes * Standardised parameter order and added axis test * Fixed x axis line drawing into margins and added tests * Fixed axis increment rendering in margins, tests and tidyup examples * Added test for BarSeries * Added more BarSeriesTests * Split GraphView.cs into sub files as suggested * Fixed pointlessly passing around ConsoleDriver and Bounds * Fixed colored bars not reseting color before drawing labels * spelling fixes * Replaced System.Drawing with code copied from dotnet/corefx repo * Change to trigger CI * Added tests for MultiBarSeries * Added test support for Asserting exact graph contents * Added xml doc where missing from System.Drawing Types * Standardised unit test namespaces to Terminal.Gui * Fixed namespace correctly this time after merging main * Fixed test to avoid using Attribute constructor * Reduced code duplication in test by moving InitFakeDriver to static in GraphViewTests * Added TextAnnotationTests and improved GraphViewTests.AssertDriverContentsAre * Added more TextAnnotation tests and fixed file indentation * Added tests for Legend and Path And fixed TruncateOrPad being off by 1 when truncating * Removed unused paths in TruncateOrPad
217 lines
4.6 KiB
C#
217 lines
4.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Terminal.Gui;
|
|
using Xunit;
|
|
using System.Globalization;
|
|
|
|
namespace Terminal.Gui.Views {
|
|
|
|
public class TabViewTests {
|
|
private TabView GetTabView ()
|
|
{
|
|
return GetTabView (out _, out _);
|
|
}
|
|
|
|
private TabView GetTabView (out TabView.Tab tab1, out TabView.Tab tab2)
|
|
{
|
|
InitFakeDriver ();
|
|
|
|
var tv = new TabView ();
|
|
tv.AddTab (tab1 = new TabView.Tab ("Tab1", new TextField ("hi")), false);
|
|
tv.AddTab (tab2 = new TabView.Tab ("Tab2", new Label ("hi2")), false);
|
|
return tv;
|
|
}
|
|
|
|
[Fact]
|
|
public void AddTwoTabs_SecondIsSelected ()
|
|
{
|
|
InitFakeDriver ();
|
|
|
|
var tv = new TabView ();
|
|
TabView.Tab tab1;
|
|
TabView.Tab tab2;
|
|
tv.AddTab (tab1 = new TabView.Tab ("Tab1", new TextField ("hi")), false);
|
|
tv.AddTab (tab2 = new TabView.Tab ("Tab1", new Label ("hi2")), true);
|
|
|
|
Assert.Equal (2, tv.Tabs.Count);
|
|
Assert.Equal (tab2, tv.SelectedTab);
|
|
}
|
|
|
|
|
|
[Fact]
|
|
public void EnsureSelectedTabVisible_NullSelect ()
|
|
{
|
|
var tv = GetTabView ();
|
|
|
|
tv.SelectedTab = null;
|
|
|
|
Assert.Null (tv.SelectedTab);
|
|
Assert.Equal (0, tv.TabScrollOffset);
|
|
|
|
tv.EnsureSelectedTabIsVisible ();
|
|
|
|
Assert.Null (tv.SelectedTab);
|
|
Assert.Equal (0, tv.TabScrollOffset);
|
|
}
|
|
|
|
[Fact]
|
|
public void EnsureSelectedTabVisible_MustScroll ()
|
|
{
|
|
var tv = GetTabView (out var tab1, out var tab2);
|
|
|
|
// Make tab width small to force only one tab visible at once
|
|
tv.Width = 4;
|
|
|
|
tv.SelectedTab = tab1;
|
|
Assert.Equal (0, tv.TabScrollOffset);
|
|
tv.EnsureSelectedTabIsVisible ();
|
|
Assert.Equal (0, tv.TabScrollOffset);
|
|
|
|
// Asking to show tab2 should automatically move scroll offset accordingly
|
|
tv.SelectedTab = tab2;
|
|
Assert.Equal (1, tv.TabScrollOffset);
|
|
}
|
|
|
|
|
|
[Fact]
|
|
public void SelectedTabChanged_Called ()
|
|
{
|
|
var tv = GetTabView (out var tab1, out var tab2);
|
|
|
|
tv.SelectedTab = tab1;
|
|
|
|
TabView.Tab oldTab = null;
|
|
TabView.Tab newTab = null;
|
|
int called = 0;
|
|
|
|
tv.SelectedTabChanged += (s, e) => {
|
|
oldTab = e.OldTab;
|
|
newTab = e.NewTab;
|
|
called++;
|
|
};
|
|
|
|
tv.SelectedTab = tab2;
|
|
|
|
Assert.Equal (1, called);
|
|
Assert.Equal (tab1, oldTab);
|
|
Assert.Equal (tab2, newTab);
|
|
}
|
|
[Fact]
|
|
public void RemoveTab_ChangesSelection ()
|
|
{
|
|
var tv = GetTabView (out var tab1, out var tab2);
|
|
|
|
tv.SelectedTab = tab1;
|
|
tv.RemoveTab (tab1);
|
|
|
|
Assert.Equal (tab2, tv.SelectedTab);
|
|
}
|
|
|
|
[Fact]
|
|
public void RemoveTab_MultipleCalls_NotAnError ()
|
|
{
|
|
var tv = GetTabView (out var tab1, out var tab2);
|
|
|
|
tv.SelectedTab = tab1;
|
|
|
|
// Repeated calls to remove a tab that is not part of
|
|
// the collection should be ignored
|
|
tv.RemoveTab (tab1);
|
|
tv.RemoveTab (tab1);
|
|
tv.RemoveTab (tab1);
|
|
tv.RemoveTab (tab1);
|
|
|
|
Assert.Equal (tab2, tv.SelectedTab);
|
|
}
|
|
|
|
[Fact]
|
|
public void RemoveAllTabs_ClearsSelection ()
|
|
{
|
|
var tv = GetTabView (out var tab1, out var tab2);
|
|
|
|
tv.SelectedTab = tab1;
|
|
tv.RemoveTab (tab1);
|
|
tv.RemoveTab (tab2);
|
|
|
|
Assert.Null (tv.SelectedTab);
|
|
}
|
|
|
|
[Fact]
|
|
public void SwitchTabBy_NormalUsage ()
|
|
{
|
|
var tv = GetTabView (out var tab1, out var tab2);
|
|
|
|
TabView.Tab tab3;
|
|
TabView.Tab tab4;
|
|
TabView.Tab tab5;
|
|
|
|
tv.AddTab (tab3 = new TabView.Tab (), false);
|
|
tv.AddTab (tab4 = new TabView.Tab (), false);
|
|
tv.AddTab (tab5 = new TabView.Tab (), false);
|
|
|
|
tv.SelectedTab = tab1;
|
|
|
|
int called = 0;
|
|
tv.SelectedTabChanged += (s, e) => { called++; };
|
|
|
|
tv.SwitchTabBy (1);
|
|
|
|
Assert.Equal (1, called);
|
|
Assert.Equal (tab2, tv.SelectedTab);
|
|
|
|
//reset called counter
|
|
called = 0;
|
|
|
|
// go right 2
|
|
tv.SwitchTabBy (2);
|
|
|
|
// even though we go right 2 indexes the event should only be called once
|
|
Assert.Equal (1, called);
|
|
Assert.Equal (tab4, tv.SelectedTab);
|
|
}
|
|
|
|
[Fact]
|
|
public void AddTab_SameTabMoreThanOnce ()
|
|
{
|
|
var tv = GetTabView (out var tab1, out var tab2);
|
|
|
|
Assert.Equal (2, tv.Tabs.Count);
|
|
|
|
// Tab is already part of the control so shouldn't result in duplication
|
|
tv.AddTab (tab1, false);
|
|
tv.AddTab (tab1, false);
|
|
tv.AddTab (tab1, false);
|
|
tv.AddTab (tab1, false);
|
|
|
|
Assert.Equal (2, tv.Tabs.Count);
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
public void SwitchTabBy_OutOfTabsRange ()
|
|
{
|
|
var tv = GetTabView (out var tab1, out var tab2);
|
|
|
|
tv.SelectedTab = tab1;
|
|
tv.SwitchTabBy (500);
|
|
|
|
Assert.Equal (tab2, tv.SelectedTab);
|
|
|
|
tv.SwitchTabBy (-500);
|
|
|
|
Assert.Equal (tab1, tv.SelectedTab);
|
|
|
|
}
|
|
|
|
private void InitFakeDriver ()
|
|
{
|
|
var driver = new FakeDriver ();
|
|
Application.Init (driver, new FakeMainLoop (() => FakeConsole.ReadKey (true)));
|
|
driver.Init (() => { });
|
|
}
|
|
}
|
|
} |