restructure

This commit is contained in:
Tig
2024-06-16 16:07:40 -07:00
parent f99a744ef8
commit f43596c878
7 changed files with 304 additions and 414 deletions

View File

@@ -1,5 +1,6 @@
using System;
using System.Linq;
using System.Reflection;
using Microsoft.CodeAnalysis;
namespace Terminal.Gui;
@@ -23,9 +24,13 @@ public class Bar : View
Height = Dim.Auto ();
LayoutStarted += Bar_LayoutStarted;
Initialized += Bar_Initialized;
if (shortcuts is null)
{
return;
}
foreach (Shortcut shortcut in shortcuts)
{
Add (shortcut);
@@ -35,7 +40,7 @@ public class Bar : View
private void Bar_Initialized (object sender, EventArgs e)
{
ColorScheme = Colors.ColorSchemes ["Menu"];
AdjustSubviewBorders ();
AdjustSubviews ();
}
/// <inheritdoc />
@@ -45,23 +50,41 @@ public class Bar : View
Border.LineStyle = value;
}
private Orientation _orientation = Orientation.Horizontal;
/// <summary>
/// Gets or sets the <see cref="Orientation"/> for this <see cref="Bar"/>. The default is
/// <see cref="Orientation.Horizontal"/>.
/// </summary>
public Orientation Orientation { get; set; } = Orientation.Horizontal;
public Orientation Orientation
{
get => _orientation;
set
{
_orientation = value;
SetNeedsLayout ();
}
}
private AlignmentModes _alignmentModes = AlignmentModes.StartToEnd;
/// <summary>
/// Gets or sets the <see cref="AlignmentModes"/> for this <see cref="Bar"/>. The default is <see cref="AlignmentModes.StartToEnd"/>.
/// </summary>
public AlignmentModes AlignmentModes { get; set; } = AlignmentModes.StartToEnd;
public bool StatusBarStyle { get; set; } = true;
public AlignmentModes AlignmentModes
{
get => _alignmentModes;
set
{
_alignmentModes = value;
SetNeedsLayout ();
}
}
public override View Add (View view)
{
base.Add (view);
AdjustSubviewBorders ();
AdjustSubviews ();
return view;
}
@@ -70,7 +93,7 @@ public class Bar : View
public override View Remove (View view)
{
base.Remove (view);
AdjustSubviewBorders ();
AdjustSubviews ();
return view;
}
@@ -118,47 +141,31 @@ public class Bar : View
return toRemove as Shortcut;
}
private void AdjustSubviewBorders ()
private void AdjustSubviews ()
{
for (var index = 0; index < Subviews.Count; index++)
{
View barItem = Subviews [index];
barItem.Border.LineStyle = BorderStyle;
barItem.SuperViewRendersLineCanvas = true;
barItem.ColorScheme = ColorScheme;
//barItem.Border.LineStyle = BorderStyle;
//barItem.SuperViewRendersLineCanvas = true;
//barItem.ColorScheme = ColorScheme;
if (!barItem.Visible)
{
continue;
}
//if (!barItem.Visible)
//{
// continue;
//}
if (StatusBarStyle)
{
barItem.BorderStyle = LineStyle.Dashed;
//barItem.BorderStyle = LineStyle.None;
//if (index == 0)
//{
// barItem.Border.Thickness = new Thickness (1, 1, 1, 0);
//}
if (index == Subviews.Count - 1)
{
barItem.Border.Thickness = new Thickness (0, 0, 0, 0);
}
else
{
barItem.Border.Thickness = new Thickness (0, 0, 1, 0);
}
}
else
{
barItem.BorderStyle = LineStyle.None;
if (index == 0)
{
barItem.Border.Thickness = new Thickness (1, 1, 1, 0);
}
if (index == Subviews.Count - 1)
{
barItem.Border.Thickness = new Thickness (1, 0, 1, 1);
}
}
//if (index == Subviews.Count - 1)
//{
// barItem.Border.Thickness = new Thickness (1, 0, 1, 1);
//}
}
}
@@ -173,40 +180,12 @@ public class Bar : View
{
View barItem = Subviews [index];
if (!barItem.Visible)
{
continue;
}
barItem.ColorScheme = ColorScheme;
barItem.X = Pos.Align (Alignment.Start, AlignmentModes);
barItem.Y = 0;//Pos.Center ();
//if (StatusBarStyle)
//{
// barItem.BorderStyle = LineStyle.Dashed;
//}
//else
//{
// barItem.BorderStyle = LineStyle.None;
//}
//if (index == Subviews.Count - 1)
//{
// barItem.Border.Thickness = new Thickness (0, 0, 0, 0);
//}
//else
//{
// barItem.Border.Thickness = new Thickness (0, 0, 1, 0);
//}
if (barItem is Shortcut shortcut)
{
shortcut.X = Pos.Align (Alignment.Start, AlignmentModes);
}
else
{
barItem.X = Pos.Align (Alignment.Start, AlignmentModes);
}
barItem.Y = Pos.Center ();
prevBarItem = barItem;
// HACK: This should not be needed
barItem.SetRelativeLayout (GetContentSize ());
}
break;

View File

@@ -98,6 +98,11 @@ public class Shortcut : View
LayoutStarted += OnLayoutStarted;
Initialized += OnInitialized;
if (key is null)
{
key = Key.Empty;
}
Key = key;
Title = commandText;
Action = action;
@@ -445,7 +450,7 @@ public class Shortcut : View
{
CommandView.Margin.Thickness = GetMarginThickness ();
CommandView.X = Pos.Align (Alignment.End, AlignmentModes);
CommandView.Y = 0; //Pos.Center (),
CommandView.Y = 0;//Pos.Center ();
}
@@ -470,9 +475,9 @@ public class Shortcut : View
{
HelpView.Margin.Thickness = GetMarginThickness ();
HelpView.X = Pos.Align (Alignment.End, AlignmentModes);
HelpView.Y = 0; //Pos.Center (),
HelpView.Y = 0;//Pos.Center ();
HelpView.Width = Dim.Auto (DimAutoStyle.Text);
HelpView.Height = CommandView?.IsAdded == true ? Dim.Height (CommandView) : 1;
HelpView.Height = CommandView?.Visible == true ? Dim.Height (CommandView) : 1;
HelpView.Visible = true;
HelpView.VerticalTextAlignment = Alignment.Center;
@@ -592,9 +597,9 @@ public class Shortcut : View
{
KeyView.Margin.Thickness = GetMarginThickness ();
KeyView.X = Pos.Align (Alignment.End, AlignmentModes);
//KeyView.Y = Pos.Center ();
KeyView.Y = 0;//Pos.Center ();
KeyView.Width = Dim.Auto (DimAutoStyle.Text, Dim.Func (GetMinimumKeyViewSize));
KeyView.Height = CommandView?.IsAdded == true ? Dim.Height (CommandView) : 1;
KeyView.Height = CommandView?.Visible == true ? Dim.Height (CommandView) : 1;
KeyView.Visible = true;
@@ -653,7 +658,7 @@ public class Shortcut : View
}
}
return true;
return false;
}
/// <summary>
@@ -702,7 +707,7 @@ public class Shortcut : View
}
// Set KeyView's colors to show "hot"
if (IsInitialized)
if (IsInitialized && base.ColorScheme is {})
{
var cs = new ColorScheme (base.ColorScheme)
{

View File

@@ -1,3 +1,6 @@
using System;
using System.Reflection;
namespace Terminal.Gui;
/// <summary>
@@ -9,28 +12,61 @@ namespace Terminal.Gui;
/// </summary>
public class StatusBar : Bar
{
/// <inheritdoc />
/// <inheritdoc/>
public StatusBar () : this ([]) { }
/// <inheritdoc />
/// <inheritdoc/>
public StatusBar (IEnumerable<Shortcut> shortcuts) : base (shortcuts)
{
Orientation = Orientation.Horizontal;
Y = Pos.AnchorEnd ();
Width = Dim.Fill ();
StatusBarStyle = true;
Height = Dim.Auto (DimAutoStyle.Content, 1);
BorderStyle = LineStyle.Dashed;
ColorScheme = Colors.ColorSchemes ["Menu"];
LayoutStarted += StatusBar_LayoutStarted;
}
/// <inheritdoc />
// StatusBar arranges the items horizontally.
// The first item has no left border, the last item has no right border.
// The Shortcuts are configured with the command, help, and key views aligned in reverse order (EndToStart).
private void StatusBar_LayoutStarted (object sender, LayoutEventArgs e)
{
for (int index = 0; index < Subviews.Count; index++)
{
View barItem = Subviews [index];
barItem.BorderStyle = BorderStyle;
if (index == Subviews.Count - 1)
{
barItem.Border.Thickness = new Thickness (0, 0, 0, 0);
}
else
{
barItem.Border.Thickness = new Thickness (0, 0, 1, 0);
}
if (barItem is Shortcut shortcut)
{
shortcut.AlignmentModes = AlignmentModes.EndToStart | AlignmentModes.IgnoreFirstOrLast;
}
}
}
/// <inheritdoc/>
public override View Add (View view)
{
view.CanFocus = false;
if (view is Shortcut shortcut)
{
shortcut.KeyBindingScope = KeyBindingScope.Application;
shortcut.AlignmentModes = AlignmentModes.EndToStart | AlignmentModes.IgnoreFirstOrLast;
}
return base.Add (view);
}
}

View File

@@ -36,7 +36,7 @@ public class Bars : Scenario
{
X = Pos.AnchorEnd (),
Width = 50,
Height = Dim.Fill (3),
Height = Dim.Fill (6),
ColorScheme = Colors.ColorSchemes ["Toplevel"],
Source = new ListWrapper<string> (eventSource)
};
@@ -104,15 +104,14 @@ public class Bars : Scenario
// eventLog.MoveDown ();
// };
var bar = new Bar
var vBar = new Bar
{
X = 2,
Y = 2,
Orientation = Orientation.Vertical,
StatusBarStyle = false,
BorderStyle = LineStyle.Rounded
};
bar.Add (shortcut1, shortcut2);
vBar.Add (shortcut1, shortcut2);
////CheckBox hello = new ()
////{
@@ -128,14 +127,48 @@ public class Bars : Scenario
//// };
Application.Top.Add (bar);
Application.Top.Add (vBar);
// BUGBUG: This should not be needed
Application.Top.LayoutSubviews ();
// SetupMenuBar ();
// SetupMenuBar ();
//SetupContentMenu ();
SetupStatusBar ();
Label label = new Label ()
{
Title = " Bar:",
X = 0,
Y = Pos.AnchorEnd () - 6
};
Application.Top.Add (label);
var bar = new Bar
{
Id = "bar",
X = Pos.Right (label),
Y = Pos.Top (label),
Width = Dim.Fill (),
Orientation = Orientation.Horizontal,
};
ConfigStatusBar (bar);
Application.Top.Add (bar);
label = new Label ()
{
Title = "StatusBar:",
X = 0,
Y = Pos.AnchorEnd () - 3
};
Application.Top.Add (label);
bar = new StatusBar()
{
Id = "statusBar",
X = Pos.Right (label),
Y = Pos.Top (label),
Width = Dim.Fill (),
Orientation = Orientation.Horizontal,
};
ConfigStatusBar (bar);
Application.Top.Add (bar);
foreach (Bar barView in Application.Top.Subviews.Where (b => b is Bar)!)
{
@@ -143,14 +176,13 @@ public class Bars : Scenario
{
sh.Accept += (o, args) =>
{
eventSource.Add ($"Accept: {sh!.CommandView.Text}");
eventSource.Add ($"Accept: {sh!.SuperView.Id} {sh!.CommandView.Text}");
eventLog.MoveDown ();
};
}
}
}
private void Button_Clicked (object sender, EventArgs e) { MessageBox.Query ("Hi", $"You clicked {sender}"); }
//private void SetupContentMenu ()
//{
@@ -307,7 +339,6 @@ public class Bars : Scenario
Width = Dim.Fill (),
Height = 1,//Dim.Auto (DimAutoStyle.Content),
Orientation = Orientation.Horizontal,
StatusBarStyle = false,
};
var fileMenuBarItem = new Shortcut
@@ -317,7 +348,7 @@ public class Bars : Scenario
Key = Key.F.WithAlt,
};
fileMenuBarItem.KeyView.Visible = false;
var editMenuBarItem = new Shortcut
{
Title = "_Edit",
@@ -338,8 +369,7 @@ public class Bars : Scenario
X = 1,
Y = 1,
Orientation = Orientation.Vertical,
StatusBarStyle = false,
// Modal = true,
// Modal = true,
Visible = false,
};
@@ -381,7 +411,7 @@ public class Bars : Scenario
{
if (fileMenu.Visible)
{
// fileMenu.RequestStop ();
// fileMenu.RequestStop ();
prevFocus?.SetFocus ();
return;
}
@@ -405,26 +435,18 @@ public class Bars : Scenario
}
private void SetupStatusBar ()
private void ConfigStatusBar (Bar bar)
{
var statusBar = new Bar
{
Id = "statusBar",
X = 0,
Y = Pos.AnchorEnd (),
Width = Dim.Fill (),
};
var shortcut = new Shortcut
{
Height = Dim.Auto (DimAutoStyle.Content, 3),
Text = "Quit",
Title = "Q_uit",
Key = Application.QuitKey,
KeyBindingScope = KeyBindingScope.Application,
CanFocus = false
};
statusBar.Add (shortcut);
bar.Add (shortcut);
shortcut = new Shortcut
{
@@ -432,24 +454,9 @@ public class Bars : Scenario
Title = "Help",
Key = Key.F1,
KeyBindingScope = KeyBindingScope.HotKey,
CanFocus = false
};
var labelHelp = new Label
{
X = Pos.Center (),
Y = Pos.Top (statusBar) - 1,
Text = "Help"
};
Application.Top.Add (labelHelp);
shortcut.Accept += (s, e) =>
{
labelHelp.Text = labelHelp.Text + "!";
e.Cancel = true;
};
statusBar.Add (shortcut);
bar.Add (shortcut);
shortcut = new Shortcut
{
@@ -460,10 +467,9 @@ public class Bars : Scenario
{
Text = "_Show/Hide"
},
CanFocus = false
};
statusBar.Add (shortcut);
bar.Add (shortcut);
var button1 = new Button
{
@@ -471,15 +477,16 @@ public class Bars : Scenario
// Visible = false
};
button1.Accept += Button_Clicked;
statusBar.Add (button1);
bar.Add (button1);
shortcut.Accept += (s, e) =>
{
button1.Visible = !button1.Visible;
button1.Enabled = button1.Visible;
e.Cancel = false;
};
statusBar.Add (new Label
bar.Add (new Label
{
HotKeySpecifier = new Rune ('_'),
Text = "Fo_cusLabel",
@@ -492,11 +499,11 @@ public class Bars : Scenario
};
button2.Accept += (s, e) => Application.RequestStop ();
statusBar.Add (button2);
bar.Add (button2);
statusBar.Initialized += Menu_Initialized;
return;
Application.Top.Add (statusBar);
void Button_Clicked (object sender, EventArgs e) { MessageBox.Query ("Hi", $"You clicked {sender}"); }
}

View File

@@ -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)

View File

@@ -458,8 +458,8 @@ internal class UICatalogApp
StatusBar = new ()
{
Visible = ShowStatusBar,
AlignmentModes = AlignmentModes.StartToEnd | AlignmentModes.IgnoreFirstOrLast
};
StatusBar.AlignmentModes = AlignmentModes.StartToEnd | AlignmentModes.IgnoreFirstOrLast;
Shortcut statusBarShortcut = new Shortcut ()
{

View File

@@ -113,142 +113,6 @@ public class ContextMenuTests (ITestOutputHelper output)
top.Dispose ();
}
[Fact]
[AutoInitShutdown]
public void ContextMenu_On_Toplevel_With_A_MenuBar_TextField_StatusBar ()
{
Thread.CurrentThread.CurrentUICulture = new CultureInfo ("en-US");
var menu = new MenuBar
{
Menus =
[
new MenuBarItem ("File", "", null),
new MenuBarItem ("Edit", "", null)
]
};
var label = new Label { X = 2, Y = 3, Text = "Label:" };
var tf = new TextField { X = Pos.Right (label) + 1, Y = Pos.Top (label), Width = 20, Text = "TextField" };
var statusBar = new StatusBar (
#if V2_STATUSBAR
[
new StatusItem (KeyCode.F1, "~F1~ Help", null),
new StatusItem (KeyCode.CtrlMask | KeyCode.Q, "~^Q~ Quit", null)
]
#endif
);
var top = new Toplevel ();
top.Add (menu, label, tf, statusBar);
((FakeDriver)Application.Driver).SetBufferSize (45, 17);
Application.Begin (top);
Assert.Equal (new Rectangle (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.Draw ();
var expected = @"
File Edit
Label: TextField
┌─────────────────────┐
│ Select All Ctrl+T │
│ Delete All Ctrl+R │
│ Copy Ctrl+C │
│ Cut Ctrl+X │
│ Paste Ctrl+V │
│ Undo Ctrl+Z │
│ Redo Ctrl+Y │
└─────────────────────┘
F1 Help │ ^Q Quit
";
Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rectangle (1, 0, 32, 17), pos);
top.Dispose ();
}
[Fact]
[AutoInitShutdown]
public void ContextMenu_On_Toplevel_With_A_MenuBar_Window_TextField_StatusBar ()
{
Thread.CurrentThread.CurrentUICulture = new CultureInfo ("en-US");
var menu = new MenuBar
{
Menus =
[
new MenuBarItem ("File", "", null),
new MenuBarItem ("Edit", "", null)
]
};
var label = new Label { X = 2, Y = 3, Text = "Label:" };
var tf = new TextField { X = Pos.Right (label) + 1, Y = Pos.Top (label), Width = 20, Text = "TextField" };
var win = new Window ();
win.Add (label, tf);
var statusBar = new StatusBar (
#if V2_STATUSBAR
new []
{
new StatusItem (KeyCode.F1, "~F1~ Help", null),
new StatusItem (KeyCode.CtrlMask | KeyCode.Q, "~^Q~ Quit", null)
}
#endif
);
var top = new Toplevel ();
top.Add (menu, win, statusBar);
Application.Begin (top);
((FakeDriver)Application.Driver).SetBufferSize (44, 17);
Assert.Equal (new Rectangle (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.Draw ();
var expected = @"
File Edit
┌──────────────────────────────────────────┐
│ │
│ │
│ │
│ Label: TextField │
│ ┌─────────────────────┐ │
│ │ Select All Ctrl+T │ │
│ │ Delete All Ctrl+R │ │
│ │ Copy Ctrl+C │ │
│ │ Cut Ctrl+X │ │
│ │ Paste Ctrl+V │ │
│ │ Undo Ctrl+Z │ │
│ │ Redo Ctrl+Y │ │
│ └─────────────────────┘ │
└──────────────────────────────────────────┘
F1 Help │ ^Q Quit
";
Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rectangle (1, 0, 44, 17), pos);
top.Dispose ();
}
[Fact]
[AutoInitShutdown]
public void Draw_A_ContextMenu_Over_A_Borderless_Top ()