mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-30 17:57:57 +01:00
restructure
This commit is contained in:
@@ -4,7 +4,6 @@ using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Terminal.Gui;
|
||||
using static System.Net.Mime.MediaTypeNames;
|
||||
using Application = Terminal.Gui.Application;
|
||||
|
||||
namespace UICatalog.Scenarios;
|
||||
@@ -44,101 +43,101 @@ public class GraphViewExample : Scenario
|
||||
{
|
||||
Menus =
|
||||
[
|
||||
new MenuBarItem (
|
||||
"_File",
|
||||
new MenuItem []
|
||||
{
|
||||
new (
|
||||
"Scatter _Plot",
|
||||
"",
|
||||
() => _graphs [_currentGraph =
|
||||
0] ()
|
||||
),
|
||||
new (
|
||||
"_V Bar Graph",
|
||||
"",
|
||||
() => _graphs [_currentGraph =
|
||||
1] ()
|
||||
),
|
||||
new (
|
||||
"_H Bar Graph",
|
||||
"",
|
||||
() => _graphs [_currentGraph =
|
||||
2] ()
|
||||
),
|
||||
new (
|
||||
"P_opulation Pyramid",
|
||||
"",
|
||||
() => _graphs [_currentGraph =
|
||||
3] ()
|
||||
),
|
||||
new (
|
||||
"_Line Graph",
|
||||
"",
|
||||
() => _graphs [_currentGraph =
|
||||
4] ()
|
||||
),
|
||||
new (
|
||||
"Sine _Wave",
|
||||
"",
|
||||
() => _graphs [_currentGraph =
|
||||
5] ()
|
||||
),
|
||||
new (
|
||||
"Silent _Disco",
|
||||
"",
|
||||
() => _graphs [_currentGraph =
|
||||
6] ()
|
||||
),
|
||||
new (
|
||||
"_Multi Bar Graph",
|
||||
"",
|
||||
() => _graphs [_currentGraph =
|
||||
7] ()
|
||||
),
|
||||
new ("_Quit", "", () => Quit ())
|
||||
}
|
||||
),
|
||||
new MenuBarItem (
|
||||
"_View",
|
||||
new []
|
||||
{
|
||||
new ("Zoom _In", "", () => Zoom (0.5f)),
|
||||
new ("Zoom _Out", "", () => Zoom (2f)),
|
||||
new ("MarginLeft++", "", () => Margin (true, true)),
|
||||
new ("MarginLeft--", "", () => Margin (true, false)),
|
||||
new ("MarginBottom++", "", () => Margin (false, true)),
|
||||
new ("MarginBottom--", "", () => Margin (false, false)),
|
||||
_miShowBorder = new MenuItem (
|
||||
"_Enable Margin, Border, and Padding",
|
||||
"",
|
||||
() => ShowBorder ()
|
||||
)
|
||||
{
|
||||
Checked = true,
|
||||
CheckType = MenuItemCheckStyle
|
||||
.Checked
|
||||
},
|
||||
_miDiags = new MenuItem (
|
||||
"_Diagnostics",
|
||||
"",
|
||||
() => ToggleDiagnostics ()
|
||||
)
|
||||
{
|
||||
Checked = View.Diagnostics
|
||||
== (ViewDiagnosticFlags
|
||||
.Padding
|
||||
| ViewDiagnosticFlags
|
||||
.Ruler),
|
||||
CheckType = MenuItemCheckStyle.Checked
|
||||
}
|
||||
}
|
||||
)
|
||||
new (
|
||||
"_File",
|
||||
new MenuItem []
|
||||
{
|
||||
new (
|
||||
"Scatter _Plot",
|
||||
"",
|
||||
() => _graphs [_currentGraph =
|
||||
0] ()
|
||||
),
|
||||
new (
|
||||
"_V Bar Graph",
|
||||
"",
|
||||
() => _graphs [_currentGraph =
|
||||
1] ()
|
||||
),
|
||||
new (
|
||||
"_H Bar Graph",
|
||||
"",
|
||||
() => _graphs [_currentGraph =
|
||||
2] ()
|
||||
),
|
||||
new (
|
||||
"P_opulation Pyramid",
|
||||
"",
|
||||
() => _graphs [_currentGraph =
|
||||
3] ()
|
||||
),
|
||||
new (
|
||||
"_Line Graph",
|
||||
"",
|
||||
() => _graphs [_currentGraph =
|
||||
4] ()
|
||||
),
|
||||
new (
|
||||
"Sine _Wave",
|
||||
"",
|
||||
() => _graphs [_currentGraph =
|
||||
5] ()
|
||||
),
|
||||
new (
|
||||
"Silent _Disco",
|
||||
"",
|
||||
() => _graphs [_currentGraph =
|
||||
6] ()
|
||||
),
|
||||
new (
|
||||
"_Multi Bar Graph",
|
||||
"",
|
||||
() => _graphs [_currentGraph =
|
||||
7] ()
|
||||
),
|
||||
new ("_Quit", "", () => Quit ())
|
||||
}
|
||||
),
|
||||
new (
|
||||
"_View",
|
||||
new []
|
||||
{
|
||||
new ("Zoom _In", "", () => Zoom (0.5f)),
|
||||
new ("Zoom _Out", "", () => Zoom (2f)),
|
||||
new ("MarginLeft++", "", () => Margin (true, true)),
|
||||
new ("MarginLeft--", "", () => Margin (true, false)),
|
||||
new ("MarginBottom++", "", () => Margin (false, true)),
|
||||
new ("MarginBottom--", "", () => Margin (false, false)),
|
||||
_miShowBorder = new (
|
||||
"_Enable Margin, Border, and Padding",
|
||||
"",
|
||||
() => ShowBorder ()
|
||||
)
|
||||
{
|
||||
Checked = true,
|
||||
CheckType = MenuItemCheckStyle
|
||||
.Checked
|
||||
},
|
||||
_miDiags = new (
|
||||
"_Diagnostics",
|
||||
"",
|
||||
() => ToggleDiagnostics ()
|
||||
)
|
||||
{
|
||||
Checked = View.Diagnostics
|
||||
== (ViewDiagnosticFlags
|
||||
.Padding
|
||||
| ViewDiagnosticFlags
|
||||
.Ruler),
|
||||
CheckType = MenuItemCheckStyle.Checked
|
||||
}
|
||||
}
|
||||
)
|
||||
]
|
||||
};
|
||||
app.Add (menu);
|
||||
|
||||
_graphView = new GraphView
|
||||
_graphView = new()
|
||||
{
|
||||
X = 0,
|
||||
Y = 1,
|
||||
@@ -162,7 +161,7 @@ public class GraphViewExample : Scenario
|
||||
};
|
||||
|
||||
frameRight.Add (
|
||||
_about = new TextView { Width = Dim.Fill (), Height = Dim.Fill () }
|
||||
_about = new() { Width = Dim.Fill (), Height = Dim.Fill () }
|
||||
);
|
||||
|
||||
app.Add (frameRight);
|
||||
@@ -172,15 +171,15 @@ public class GraphViewExample : Scenario
|
||||
{
|
||||
new (Key.G.WithCtrl, "Next Graph", () => _graphs [_currentGraph++ % _graphs.Length] ()),
|
||||
new (Key.CursorUp, "Zoom In", () => Zoom (0.5f)),
|
||||
new (Key.CursorDown, "Zoom Out", () => Zoom (2f)),
|
||||
new (Key.CursorDown, "Zoom Out", () => Zoom (2f))
|
||||
}
|
||||
);
|
||||
app.Add (statusBar);
|
||||
|
||||
var diagShortcut = new Shortcut ()
|
||||
var diagShortcut = new Shortcut
|
||||
{
|
||||
Key = Key.F10,
|
||||
CommandView = new CheckBox ()
|
||||
CommandView = new CheckBox
|
||||
{
|
||||
Title = "Diagnostics",
|
||||
CanFocus = false
|
||||
@@ -195,12 +194,12 @@ public class GraphViewExample : Scenario
|
||||
View.Diagnostics = _viewDiagnostics;
|
||||
app.Dispose ();
|
||||
Application.Shutdown ();
|
||||
|
||||
}
|
||||
|
||||
private void DiagShortcut_Accept (object sender, CancelEventArgs e)
|
||||
{
|
||||
ToggleDiagnostics();
|
||||
ToggleDiagnostics ();
|
||||
|
||||
if (sender is Shortcut shortcut && shortcut.CommandView is CheckBox checkBox)
|
||||
{
|
||||
checkBox.Checked = _miDiags.Checked;
|
||||
@@ -212,9 +211,9 @@ public class GraphViewExample : Scenario
|
||||
_miDiags.Checked = !_miDiags.Checked;
|
||||
|
||||
View.Diagnostics = _miDiags.Checked == true
|
||||
? ViewDiagnosticFlags.Padding
|
||||
| ViewDiagnosticFlags.Ruler
|
||||
: ViewDiagnosticFlags.Off;
|
||||
? ViewDiagnosticFlags.Padding
|
||||
| ViewDiagnosticFlags.Ruler
|
||||
: ViewDiagnosticFlags.Off;
|
||||
Application.Refresh ();
|
||||
}
|
||||
|
||||
@@ -241,7 +240,7 @@ public class GraphViewExample : Scenario
|
||||
_about.Text = "Housing Expenditures by income thirds 1996-2003";
|
||||
|
||||
Color fore = _graphView.ColorScheme.Normal.Foreground == new Color (ColorName.Black)
|
||||
? new Color (ColorName.White)
|
||||
? new (ColorName.White)
|
||||
: _graphView.ColorScheme.Normal.Foreground;
|
||||
var black = new Attribute (fore, Color.Black);
|
||||
var cyan = new Attribute (Color.BrightCyan, Color.Black);
|
||||
@@ -263,7 +262,7 @@ public class GraphViewExample : Scenario
|
||||
series.AddBars ("'02", stiple, 6600, 11000, 16700);
|
||||
series.AddBars ("'03", stiple, 7000, 12000, 17000);
|
||||
|
||||
_graphView.CellSize = new PointF (0.25f, 1000);
|
||||
_graphView.CellSize = new (0.25f, 1000);
|
||||
_graphView.Series.Add (series);
|
||||
_graphView.SetNeedsDisplay ();
|
||||
|
||||
@@ -279,20 +278,20 @@ public class GraphViewExample : Scenario
|
||||
|
||||
_graphView.AxisY.Minimum = 0;
|
||||
|
||||
var legend = new LegendAnnotation (new Rectangle (_graphView.Viewport.Width - 20, 0, 20, 5));
|
||||
var legend = new LegendAnnotation (new (_graphView.Viewport.Width - 20, 0, 20, 5));
|
||||
|
||||
legend.AddEntry (
|
||||
new GraphCellToRender (stiple, series.SubSeries.ElementAt (0).OverrideBarColor),
|
||||
new (stiple, series.SubSeries.ElementAt (0).OverrideBarColor),
|
||||
"Lower Third"
|
||||
);
|
||||
|
||||
legend.AddEntry (
|
||||
new GraphCellToRender (stiple, series.SubSeries.ElementAt (1).OverrideBarColor),
|
||||
new (stiple, series.SubSeries.ElementAt (1).OverrideBarColor),
|
||||
"Middle Third"
|
||||
);
|
||||
|
||||
legend.AddEntry (
|
||||
new GraphCellToRender (stiple, series.SubSeries.ElementAt (2).OverrideBarColor),
|
||||
new (stiple, series.SubSeries.ElementAt (2).OverrideBarColor),
|
||||
"Upper Third"
|
||||
);
|
||||
_graphView.Annotations.Add (legend);
|
||||
@@ -324,7 +323,7 @@ public class GraphViewExample : Scenario
|
||||
for (var i = 0; i < 31; i++)
|
||||
{
|
||||
bars.Add (
|
||||
new BarSeriesBar (null, stiple, r.Next (0, 100))
|
||||
new (null, stiple, r.Next (0, 100))
|
||||
{
|
||||
//ColorGetter = colorDelegate
|
||||
}
|
||||
@@ -344,7 +343,7 @@ public class GraphViewExample : Scenario
|
||||
_graphView.Series.Add (series);
|
||||
|
||||
// How much graph space each cell of the console depicts
|
||||
_graphView.CellSize = new PointF (1, 10);
|
||||
_graphView.CellSize = new (1, 10);
|
||||
_graphView.AxisX.Increment = 0; // No graph ticks
|
||||
_graphView.AxisX.ShowLabelsEvery = 0; // no labels
|
||||
|
||||
@@ -399,7 +398,7 @@ public class GraphViewExample : Scenario
|
||||
|
||||
var barSeries = new BarSeries
|
||||
{
|
||||
Bars = new List<BarSeriesBar>
|
||||
Bars = new()
|
||||
{
|
||||
new ("Switzerland", softStiple, 83.4f),
|
||||
new (
|
||||
@@ -476,7 +475,7 @@ public class GraphViewExample : Scenario
|
||||
barSeries.Orientation = Orientation.Vertical;
|
||||
|
||||
// How much graph space each cell of the console depicts
|
||||
_graphView.CellSize = new PointF (0.1f, 0.25f);
|
||||
_graphView.CellSize = new (0.1f, 0.25f);
|
||||
|
||||
// No axis marks since Bar will add it's own categorical marks
|
||||
_graphView.AxisX.Increment = 0f;
|
||||
@@ -494,14 +493,14 @@ public class GraphViewExample : Scenario
|
||||
_graphView.MarginLeft = 6;
|
||||
|
||||
// Start the graph at 80 years because that is where most of our data is
|
||||
_graphView.ScrollOffset = new PointF (0, 80);
|
||||
_graphView.ScrollOffset = new (0, 80);
|
||||
}
|
||||
else
|
||||
{
|
||||
barSeries.Orientation = Orientation.Horizontal;
|
||||
|
||||
// How much graph space each cell of the console depicts
|
||||
_graphView.CellSize = new PointF (0.1f, 1f);
|
||||
_graphView.CellSize = new (0.1f, 1f);
|
||||
|
||||
// No axis marks since Bar will add it's own categorical marks
|
||||
_graphView.AxisY.Increment = 0f;
|
||||
@@ -520,7 +519,7 @@ public class GraphViewExample : Scenario
|
||||
_graphView.MarginLeft = (uint)barSeries.Bars.Max (b => b.Text.Length) + 2;
|
||||
|
||||
// Start the graph at 80 years because that is where most of our data is
|
||||
_graphView.ScrollOffset = new PointF (80, 0);
|
||||
_graphView.ScrollOffset = new (80, 0);
|
||||
}
|
||||
|
||||
_graphView.SetNeedsDisplay ();
|
||||
@@ -547,7 +546,7 @@ public class GraphViewExample : Scenario
|
||||
|
||||
for (var i = 0; i < 10; i++)
|
||||
{
|
||||
randomPoints.Add (new PointF (r.Next (100), r.Next (100)));
|
||||
randomPoints.Add (new (r.Next (100), r.Next (100)));
|
||||
}
|
||||
|
||||
var points = new ScatterSeries { Points = randomPoints };
|
||||
@@ -560,14 +559,14 @@ public class GraphViewExample : Scenario
|
||||
_graphView.Series.Add (points);
|
||||
_graphView.Annotations.Add (line);
|
||||
|
||||
randomPoints = new List<PointF> ();
|
||||
randomPoints = new ();
|
||||
|
||||
for (var i = 0; i < 10; i++)
|
||||
{
|
||||
randomPoints.Add (new PointF (r.Next (100), r.Next (100)));
|
||||
randomPoints.Add (new (r.Next (100), r.Next (100)));
|
||||
}
|
||||
|
||||
var points2 = new ScatterSeries { Points = randomPoints, Fill = new GraphCellToRender ((Rune)'x', red) };
|
||||
var points2 = new ScatterSeries { Points = randomPoints, Fill = new ((Rune)'x', red) };
|
||||
|
||||
var line2 = new PathAnnotation
|
||||
{
|
||||
@@ -578,7 +577,7 @@ public class GraphViewExample : Scenario
|
||||
_graphView.Annotations.Add (line2);
|
||||
|
||||
// How much graph space each cell of the console depicts
|
||||
_graphView.CellSize = new PointF (2, 5);
|
||||
_graphView.CellSize = new (2, 5);
|
||||
|
||||
// leave space for axis labels
|
||||
_graphView.MarginBottom = 2;
|
||||
@@ -599,10 +598,10 @@ public class GraphViewExample : Scenario
|
||||
new TextAnnotation
|
||||
{
|
||||
Text = "(Max)",
|
||||
GraphPosition = new PointF (
|
||||
max.X + 2 * _graphView.CellSize.X,
|
||||
max.Y
|
||||
)
|
||||
GraphPosition = new (
|
||||
max.X + 2 * _graphView.CellSize.X,
|
||||
max.Y
|
||||
)
|
||||
}
|
||||
);
|
||||
|
||||
@@ -622,7 +621,7 @@ public class GraphViewExample : Scenario
|
||||
_graphView.Series.Add (
|
||||
new ScatterSeries
|
||||
{
|
||||
Points = new List<PointF>
|
||||
Points = new()
|
||||
{
|
||||
new (1, 1.007f),
|
||||
new (2, 4.002f),
|
||||
@@ -744,7 +743,7 @@ public class GraphViewExample : Scenario
|
||||
);
|
||||
|
||||
// How much graph space each cell of the console depicts
|
||||
_graphView.CellSize = new PointF (1, 5);
|
||||
_graphView.CellSize = new (1, 5);
|
||||
|
||||
// leave space for axis labels
|
||||
_graphView.MarginBottom = 2;
|
||||
@@ -797,10 +796,10 @@ public class GraphViewExample : Scenario
|
||||
_graphView.Reset ();
|
||||
|
||||
// How much graph space each cell of the console depicts
|
||||
_graphView.CellSize = new PointF (100_000, 1);
|
||||
_graphView.CellSize = new (100_000, 1);
|
||||
|
||||
//center the x axis in middle of screen to show both sides
|
||||
_graphView.ScrollOffset = new PointF (-3_000_000, 0);
|
||||
_graphView.ScrollOffset = new (-3_000_000, 0);
|
||||
|
||||
_graphView.AxisX.Text = "Number Of People";
|
||||
_graphView.AxisX.Increment = 500_000;
|
||||
@@ -826,7 +825,7 @@ public class GraphViewExample : Scenario
|
||||
var malesSeries = new BarSeries
|
||||
{
|
||||
Orientation = Orientation.Horizontal,
|
||||
Bars = new List<BarSeriesBar>
|
||||
Bars = new()
|
||||
{
|
||||
new ("0-4", stiple, -2009363),
|
||||
new ("5-9", stiple, -2108550),
|
||||
@@ -857,7 +856,7 @@ public class GraphViewExample : Scenario
|
||||
var femalesSeries = new BarSeries
|
||||
{
|
||||
Orientation = Orientation.Horizontal,
|
||||
Bars = new List<BarSeriesBar>
|
||||
Bars = new()
|
||||
{
|
||||
new ("0-4", stiple, 1915127),
|
||||
new ("5-9", stiple, 2011016),
|
||||
@@ -920,15 +919,15 @@ public class GraphViewExample : Scenario
|
||||
// Generate line graph with 2,000 points
|
||||
for (float x = -500; x < 500; x += 0.5f)
|
||||
{
|
||||
points.Points.Add (new PointF (x, (float)Math.Sin (x)));
|
||||
line.Points.Add (new PointF (x, (float)Math.Sin (x)));
|
||||
points.Points.Add (new (x, (float)Math.Sin (x)));
|
||||
line.Points.Add (new (x, (float)Math.Sin (x)));
|
||||
}
|
||||
|
||||
_graphView.Series.Add (points);
|
||||
_graphView.Annotations.Add (line);
|
||||
|
||||
// How much graph space each cell of the console depicts
|
||||
_graphView.CellSize = new PointF (0.1f, 0.1f);
|
||||
_graphView.CellSize = new (0.1f, 0.1f);
|
||||
|
||||
// leave space for axis labels
|
||||
_graphView.MarginBottom = 2;
|
||||
@@ -945,7 +944,7 @@ public class GraphViewExample : Scenario
|
||||
_graphView.AxisY.Text = "↑Y";
|
||||
_graphView.AxisY.LabelGetter = v => v.Value.ToString ("N2");
|
||||
|
||||
_graphView.ScrollOffset = new PointF (-2.5f, -1);
|
||||
_graphView.ScrollOffset = new (-2.5f, -1);
|
||||
|
||||
_graphView.SetNeedsDisplay ();
|
||||
}
|
||||
@@ -971,10 +970,10 @@ public class GraphViewExample : Scenario
|
||||
|
||||
private void Zoom (float factor)
|
||||
{
|
||||
_graphView.CellSize = new PointF (
|
||||
_graphView.CellSize.X * factor,
|
||||
_graphView.CellSize.Y * factor
|
||||
);
|
||||
_graphView.CellSize = new (
|
||||
_graphView.CellSize.X * factor,
|
||||
_graphView.CellSize.Y * factor
|
||||
);
|
||||
|
||||
_graphView.AxisX.Increment *= factor;
|
||||
_graphView.AxisY.Increment *= factor;
|
||||
@@ -992,11 +991,11 @@ public class GraphViewExample : Scenario
|
||||
|
||||
public DiscoBarSeries ()
|
||||
{
|
||||
_green = new Attribute (Color.BrightGreen, Color.Black);
|
||||
_brightgreen = new Attribute (Color.Green, Color.Black);
|
||||
_brightyellow = new Attribute (Color.BrightYellow, Color.Black);
|
||||
_red = new Attribute (Color.Red, Color.Black);
|
||||
_brightred = new Attribute (Color.BrightRed, Color.Black);
|
||||
_green = new (Color.BrightGreen, Color.Black);
|
||||
_brightgreen = new (Color.Green, Color.Black);
|
||||
_brightyellow = new (Color.BrightYellow, Color.Black);
|
||||
_red = new (Color.Red, Color.Black);
|
||||
_brightred = new (Color.BrightRed, Color.Black);
|
||||
}
|
||||
|
||||
protected override void DrawBarLine (GraphView graph, Point start, Point end, BarSeriesBar beingDrawn)
|
||||
|
||||
Reference in New Issue
Block a user