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

View File

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

View File

@@ -1,3 +1,6 @@
using System;
using System.Reflection;
namespace Terminal.Gui; namespace Terminal.Gui;
/// <summary> /// <summary>
@@ -9,28 +12,61 @@ namespace Terminal.Gui;
/// </summary> /// </summary>
public class StatusBar : Bar public class StatusBar : Bar
{ {
/// <inheritdoc /> /// <inheritdoc/>
public StatusBar () : this ([]) { } public StatusBar () : this ([]) { }
/// <inheritdoc /> /// <inheritdoc/>
public StatusBar (IEnumerable<Shortcut> shortcuts) : base (shortcuts) public StatusBar (IEnumerable<Shortcut> shortcuts) : base (shortcuts)
{ {
Orientation = Orientation.Horizontal; Orientation = Orientation.Horizontal;
Y = Pos.AnchorEnd (); Y = Pos.AnchorEnd ();
Width = Dim.Fill (); 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) public override View Add (View view)
{ {
view.CanFocus = false; view.CanFocus = false;
if (view is Shortcut shortcut) if (view is Shortcut shortcut)
{ {
shortcut.KeyBindingScope = KeyBindingScope.Application; shortcut.KeyBindingScope = KeyBindingScope.Application;
shortcut.AlignmentModes = AlignmentModes.EndToStart | AlignmentModes.IgnoreFirstOrLast;
} }
return base.Add (view); return base.Add (view);
} }
} }

View File

@@ -36,7 +36,7 @@ public class Bars : Scenario
{ {
X = Pos.AnchorEnd (), X = Pos.AnchorEnd (),
Width = 50, Width = 50,
Height = Dim.Fill (3), Height = Dim.Fill (6),
ColorScheme = Colors.ColorSchemes ["Toplevel"], ColorScheme = Colors.ColorSchemes ["Toplevel"],
Source = new ListWrapper<string> (eventSource) Source = new ListWrapper<string> (eventSource)
}; };
@@ -104,15 +104,14 @@ public class Bars : Scenario
// eventLog.MoveDown (); // eventLog.MoveDown ();
// }; // };
var bar = new Bar var vBar = new Bar
{ {
X = 2, X = 2,
Y = 2, Y = 2,
Orientation = Orientation.Vertical, Orientation = Orientation.Vertical,
StatusBarStyle = false,
BorderStyle = LineStyle.Rounded BorderStyle = LineStyle.Rounded
}; };
bar.Add (shortcut1, shortcut2); vBar.Add (shortcut1, shortcut2);
////CheckBox hello = new () ////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 // BUGBUG: This should not be needed
Application.Top.LayoutSubviews (); Application.Top.LayoutSubviews ();
// SetupMenuBar (); // SetupMenuBar ();
//SetupContentMenu (); //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)!) foreach (Bar barView in Application.Top.Subviews.Where (b => b is Bar)!)
{ {
@@ -143,14 +176,13 @@ public class Bars : Scenario
{ {
sh.Accept += (o, args) => sh.Accept += (o, args) =>
{ {
eventSource.Add ($"Accept: {sh!.CommandView.Text}"); eventSource.Add ($"Accept: {sh!.SuperView.Id} {sh!.CommandView.Text}");
eventLog.MoveDown (); eventLog.MoveDown ();
}; };
} }
} }
} }
private void Button_Clicked (object sender, EventArgs e) { MessageBox.Query ("Hi", $"You clicked {sender}"); }
//private void SetupContentMenu () //private void SetupContentMenu ()
//{ //{
@@ -307,7 +339,6 @@ public class Bars : Scenario
Width = Dim.Fill (), Width = Dim.Fill (),
Height = 1,//Dim.Auto (DimAutoStyle.Content), Height = 1,//Dim.Auto (DimAutoStyle.Content),
Orientation = Orientation.Horizontal, Orientation = Orientation.Horizontal,
StatusBarStyle = false,
}; };
var fileMenuBarItem = new Shortcut var fileMenuBarItem = new Shortcut
@@ -317,7 +348,7 @@ public class Bars : Scenario
Key = Key.F.WithAlt, Key = Key.F.WithAlt,
}; };
fileMenuBarItem.KeyView.Visible = false; fileMenuBarItem.KeyView.Visible = false;
var editMenuBarItem = new Shortcut var editMenuBarItem = new Shortcut
{ {
Title = "_Edit", Title = "_Edit",
@@ -338,8 +369,7 @@ public class Bars : Scenario
X = 1, X = 1,
Y = 1, Y = 1,
Orientation = Orientation.Vertical, Orientation = Orientation.Vertical,
StatusBarStyle = false, // Modal = true,
// Modal = true,
Visible = false, Visible = false,
}; };
@@ -381,7 +411,7 @@ public class Bars : Scenario
{ {
if (fileMenu.Visible) if (fileMenu.Visible)
{ {
// fileMenu.RequestStop (); // fileMenu.RequestStop ();
prevFocus?.SetFocus (); prevFocus?.SetFocus ();
return; 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 var shortcut = new Shortcut
{ {
Height = Dim.Auto (DimAutoStyle.Content, 3),
Text = "Quit", Text = "Quit",
Title = "Q_uit", Title = "Q_uit",
Key = Application.QuitKey, Key = Application.QuitKey,
KeyBindingScope = KeyBindingScope.Application, KeyBindingScope = KeyBindingScope.Application,
CanFocus = false
}; };
statusBar.Add (shortcut); bar.Add (shortcut);
shortcut = new Shortcut shortcut = new Shortcut
{ {
@@ -432,24 +454,9 @@ public class Bars : Scenario
Title = "Help", Title = "Help",
Key = Key.F1, Key = Key.F1,
KeyBindingScope = KeyBindingScope.HotKey, KeyBindingScope = KeyBindingScope.HotKey,
CanFocus = false
}; };
var labelHelp = new Label bar.Add (shortcut);
{
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);
shortcut = new Shortcut shortcut = new Shortcut
{ {
@@ -460,10 +467,9 @@ public class Bars : Scenario
{ {
Text = "_Show/Hide" Text = "_Show/Hide"
}, },
CanFocus = false
}; };
statusBar.Add (shortcut); bar.Add (shortcut);
var button1 = new Button var button1 = new Button
{ {
@@ -471,15 +477,16 @@ public class Bars : Scenario
// Visible = false // Visible = false
}; };
button1.Accept += Button_Clicked; button1.Accept += Button_Clicked;
statusBar.Add (button1); bar.Add (button1);
shortcut.Accept += (s, e) => shortcut.Accept += (s, e) =>
{ {
button1.Visible = !button1.Visible; button1.Visible = !button1.Visible;
button1.Enabled = button1.Visible; button1.Enabled = button1.Visible;
e.Cancel = false;
}; };
statusBar.Add (new Label bar.Add (new Label
{ {
HotKeySpecifier = new Rune ('_'), HotKeySpecifier = new Rune ('_'),
Text = "Fo_cusLabel", Text = "Fo_cusLabel",
@@ -492,11 +499,11 @@ public class Bars : Scenario
}; };
button2.Accept += (s, e) => Application.RequestStop (); 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.Linq;
using System.Text; using System.Text;
using Terminal.Gui; using Terminal.Gui;
using static System.Net.Mime.MediaTypeNames;
using Application = Terminal.Gui.Application; using Application = Terminal.Gui.Application;
namespace UICatalog.Scenarios; namespace UICatalog.Scenarios;
@@ -44,101 +43,101 @@ public class GraphViewExample : Scenario
{ {
Menus = Menus =
[ [
new MenuBarItem ( new (
"_File", "_File",
new MenuItem [] new MenuItem []
{ {
new ( new (
"Scatter _Plot", "Scatter _Plot",
"", "",
() => _graphs [_currentGraph = () => _graphs [_currentGraph =
0] () 0] ()
), ),
new ( new (
"_V Bar Graph", "_V Bar Graph",
"", "",
() => _graphs [_currentGraph = () => _graphs [_currentGraph =
1] () 1] ()
), ),
new ( new (
"_H Bar Graph", "_H Bar Graph",
"", "",
() => _graphs [_currentGraph = () => _graphs [_currentGraph =
2] () 2] ()
), ),
new ( new (
"P_opulation Pyramid", "P_opulation Pyramid",
"", "",
() => _graphs [_currentGraph = () => _graphs [_currentGraph =
3] () 3] ()
), ),
new ( new (
"_Line Graph", "_Line Graph",
"", "",
() => _graphs [_currentGraph = () => _graphs [_currentGraph =
4] () 4] ()
), ),
new ( new (
"Sine _Wave", "Sine _Wave",
"", "",
() => _graphs [_currentGraph = () => _graphs [_currentGraph =
5] () 5] ()
), ),
new ( new (
"Silent _Disco", "Silent _Disco",
"", "",
() => _graphs [_currentGraph = () => _graphs [_currentGraph =
6] () 6] ()
), ),
new ( new (
"_Multi Bar Graph", "_Multi Bar Graph",
"", "",
() => _graphs [_currentGraph = () => _graphs [_currentGraph =
7] () 7] ()
), ),
new ("_Quit", "", () => Quit ()) new ("_Quit", "", () => Quit ())
} }
), ),
new MenuBarItem ( new (
"_View", "_View",
new [] new []
{ {
new ("Zoom _In", "", () => Zoom (0.5f)), new ("Zoom _In", "", () => Zoom (0.5f)),
new ("Zoom _Out", "", () => Zoom (2f)), new ("Zoom _Out", "", () => Zoom (2f)),
new ("MarginLeft++", "", () => Margin (true, true)), new ("MarginLeft++", "", () => Margin (true, true)),
new ("MarginLeft--", "", () => Margin (true, false)), new ("MarginLeft--", "", () => Margin (true, false)),
new ("MarginBottom++", "", () => Margin (false, true)), new ("MarginBottom++", "", () => Margin (false, true)),
new ("MarginBottom--", "", () => Margin (false, false)), new ("MarginBottom--", "", () => Margin (false, false)),
_miShowBorder = new MenuItem ( _miShowBorder = new (
"_Enable Margin, Border, and Padding", "_Enable Margin, Border, and Padding",
"", "",
() => ShowBorder () () => ShowBorder ()
) )
{ {
Checked = true, Checked = true,
CheckType = MenuItemCheckStyle CheckType = MenuItemCheckStyle
.Checked .Checked
}, },
_miDiags = new MenuItem ( _miDiags = new (
"_Diagnostics", "_Diagnostics",
"", "",
() => ToggleDiagnostics () () => ToggleDiagnostics ()
) )
{ {
Checked = View.Diagnostics Checked = View.Diagnostics
== (ViewDiagnosticFlags == (ViewDiagnosticFlags
.Padding .Padding
| ViewDiagnosticFlags | ViewDiagnosticFlags
.Ruler), .Ruler),
CheckType = MenuItemCheckStyle.Checked CheckType = MenuItemCheckStyle.Checked
} }
} }
) )
] ]
}; };
app.Add (menu); app.Add (menu);
_graphView = new GraphView _graphView = new()
{ {
X = 0, X = 0,
Y = 1, Y = 1,
@@ -162,7 +161,7 @@ public class GraphViewExample : Scenario
}; };
frameRight.Add ( frameRight.Add (
_about = new TextView { Width = Dim.Fill (), Height = Dim.Fill () } _about = new() { Width = Dim.Fill (), Height = Dim.Fill () }
); );
app.Add (frameRight); app.Add (frameRight);
@@ -172,15 +171,15 @@ public class GraphViewExample : Scenario
{ {
new (Key.G.WithCtrl, "Next Graph", () => _graphs [_currentGraph++ % _graphs.Length] ()), new (Key.G.WithCtrl, "Next Graph", () => _graphs [_currentGraph++ % _graphs.Length] ()),
new (Key.CursorUp, "Zoom In", () => Zoom (0.5f)), 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); app.Add (statusBar);
var diagShortcut = new Shortcut () var diagShortcut = new Shortcut
{ {
Key = Key.F10, Key = Key.F10,
CommandView = new CheckBox () CommandView = new CheckBox
{ {
Title = "Diagnostics", Title = "Diagnostics",
CanFocus = false CanFocus = false
@@ -195,12 +194,12 @@ public class GraphViewExample : Scenario
View.Diagnostics = _viewDiagnostics; View.Diagnostics = _viewDiagnostics;
app.Dispose (); app.Dispose ();
Application.Shutdown (); Application.Shutdown ();
} }
private void DiagShortcut_Accept (object sender, CancelEventArgs e) private void DiagShortcut_Accept (object sender, CancelEventArgs e)
{ {
ToggleDiagnostics(); ToggleDiagnostics ();
if (sender is Shortcut shortcut && shortcut.CommandView is CheckBox checkBox) if (sender is Shortcut shortcut && shortcut.CommandView is CheckBox checkBox)
{ {
checkBox.Checked = _miDiags.Checked; checkBox.Checked = _miDiags.Checked;
@@ -212,9 +211,9 @@ public class GraphViewExample : Scenario
_miDiags.Checked = !_miDiags.Checked; _miDiags.Checked = !_miDiags.Checked;
View.Diagnostics = _miDiags.Checked == true View.Diagnostics = _miDiags.Checked == true
? ViewDiagnosticFlags.Padding ? ViewDiagnosticFlags.Padding
| ViewDiagnosticFlags.Ruler | ViewDiagnosticFlags.Ruler
: ViewDiagnosticFlags.Off; : ViewDiagnosticFlags.Off;
Application.Refresh (); Application.Refresh ();
} }
@@ -241,7 +240,7 @@ public class GraphViewExample : Scenario
_about.Text = "Housing Expenditures by income thirds 1996-2003"; _about.Text = "Housing Expenditures by income thirds 1996-2003";
Color fore = _graphView.ColorScheme.Normal.Foreground == new Color (ColorName.Black) Color fore = _graphView.ColorScheme.Normal.Foreground == new Color (ColorName.Black)
? new Color (ColorName.White) ? new (ColorName.White)
: _graphView.ColorScheme.Normal.Foreground; : _graphView.ColorScheme.Normal.Foreground;
var black = new Attribute (fore, Color.Black); var black = new Attribute (fore, Color.Black);
var cyan = new Attribute (Color.BrightCyan, 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 ("'02", stiple, 6600, 11000, 16700);
series.AddBars ("'03", stiple, 7000, 12000, 17000); 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.Series.Add (series);
_graphView.SetNeedsDisplay (); _graphView.SetNeedsDisplay ();
@@ -279,20 +278,20 @@ public class GraphViewExample : Scenario
_graphView.AxisY.Minimum = 0; _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 ( legend.AddEntry (
new GraphCellToRender (stiple, series.SubSeries.ElementAt (0).OverrideBarColor), new (stiple, series.SubSeries.ElementAt (0).OverrideBarColor),
"Lower Third" "Lower Third"
); );
legend.AddEntry ( legend.AddEntry (
new GraphCellToRender (stiple, series.SubSeries.ElementAt (1).OverrideBarColor), new (stiple, series.SubSeries.ElementAt (1).OverrideBarColor),
"Middle Third" "Middle Third"
); );
legend.AddEntry ( legend.AddEntry (
new GraphCellToRender (stiple, series.SubSeries.ElementAt (2).OverrideBarColor), new (stiple, series.SubSeries.ElementAt (2).OverrideBarColor),
"Upper Third" "Upper Third"
); );
_graphView.Annotations.Add (legend); _graphView.Annotations.Add (legend);
@@ -324,7 +323,7 @@ public class GraphViewExample : Scenario
for (var i = 0; i < 31; i++) for (var i = 0; i < 31; i++)
{ {
bars.Add ( bars.Add (
new BarSeriesBar (null, stiple, r.Next (0, 100)) new (null, stiple, r.Next (0, 100))
{ {
//ColorGetter = colorDelegate //ColorGetter = colorDelegate
} }
@@ -344,7 +343,7 @@ public class GraphViewExample : Scenario
_graphView.Series.Add (series); _graphView.Series.Add (series);
// How much graph space each cell of the console depicts // 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.Increment = 0; // No graph ticks
_graphView.AxisX.ShowLabelsEvery = 0; // no labels _graphView.AxisX.ShowLabelsEvery = 0; // no labels
@@ -399,7 +398,7 @@ public class GraphViewExample : Scenario
var barSeries = new BarSeries var barSeries = new BarSeries
{ {
Bars = new List<BarSeriesBar> Bars = new()
{ {
new ("Switzerland", softStiple, 83.4f), new ("Switzerland", softStiple, 83.4f),
new ( new (
@@ -476,7 +475,7 @@ public class GraphViewExample : Scenario
barSeries.Orientation = Orientation.Vertical; barSeries.Orientation = Orientation.Vertical;
// How much graph space each cell of the console depicts // 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 // No axis marks since Bar will add it's own categorical marks
_graphView.AxisX.Increment = 0f; _graphView.AxisX.Increment = 0f;
@@ -494,14 +493,14 @@ public class GraphViewExample : Scenario
_graphView.MarginLeft = 6; _graphView.MarginLeft = 6;
// Start the graph at 80 years because that is where most of our data is // 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 else
{ {
barSeries.Orientation = Orientation.Horizontal; barSeries.Orientation = Orientation.Horizontal;
// How much graph space each cell of the console depicts // 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 // No axis marks since Bar will add it's own categorical marks
_graphView.AxisY.Increment = 0f; _graphView.AxisY.Increment = 0f;
@@ -520,7 +519,7 @@ public class GraphViewExample : Scenario
_graphView.MarginLeft = (uint)barSeries.Bars.Max (b => b.Text.Length) + 2; _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 // 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 (); _graphView.SetNeedsDisplay ();
@@ -547,7 +546,7 @@ public class GraphViewExample : Scenario
for (var i = 0; i < 10; i++) 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 }; var points = new ScatterSeries { Points = randomPoints };
@@ -560,14 +559,14 @@ public class GraphViewExample : Scenario
_graphView.Series.Add (points); _graphView.Series.Add (points);
_graphView.Annotations.Add (line); _graphView.Annotations.Add (line);
randomPoints = new List<PointF> (); randomPoints = new ();
for (var i = 0; i < 10; i++) 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 var line2 = new PathAnnotation
{ {
@@ -578,7 +577,7 @@ public class GraphViewExample : Scenario
_graphView.Annotations.Add (line2); _graphView.Annotations.Add (line2);
// How much graph space each cell of the console depicts // 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 // leave space for axis labels
_graphView.MarginBottom = 2; _graphView.MarginBottom = 2;
@@ -599,10 +598,10 @@ public class GraphViewExample : Scenario
new TextAnnotation new TextAnnotation
{ {
Text = "(Max)", Text = "(Max)",
GraphPosition = new PointF ( GraphPosition = new (
max.X + 2 * _graphView.CellSize.X, max.X + 2 * _graphView.CellSize.X,
max.Y max.Y
) )
} }
); );
@@ -622,7 +621,7 @@ public class GraphViewExample : Scenario
_graphView.Series.Add ( _graphView.Series.Add (
new ScatterSeries new ScatterSeries
{ {
Points = new List<PointF> Points = new()
{ {
new (1, 1.007f), new (1, 1.007f),
new (2, 4.002f), new (2, 4.002f),
@@ -744,7 +743,7 @@ public class GraphViewExample : Scenario
); );
// How much graph space each cell of the console depicts // 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 // leave space for axis labels
_graphView.MarginBottom = 2; _graphView.MarginBottom = 2;
@@ -797,10 +796,10 @@ public class GraphViewExample : Scenario
_graphView.Reset (); _graphView.Reset ();
// How much graph space each cell of the console depicts // 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 //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.Text = "Number Of People";
_graphView.AxisX.Increment = 500_000; _graphView.AxisX.Increment = 500_000;
@@ -826,7 +825,7 @@ public class GraphViewExample : Scenario
var malesSeries = new BarSeries var malesSeries = new BarSeries
{ {
Orientation = Orientation.Horizontal, Orientation = Orientation.Horizontal,
Bars = new List<BarSeriesBar> Bars = new()
{ {
new ("0-4", stiple, -2009363), new ("0-4", stiple, -2009363),
new ("5-9", stiple, -2108550), new ("5-9", stiple, -2108550),
@@ -857,7 +856,7 @@ public class GraphViewExample : Scenario
var femalesSeries = new BarSeries var femalesSeries = new BarSeries
{ {
Orientation = Orientation.Horizontal, Orientation = Orientation.Horizontal,
Bars = new List<BarSeriesBar> Bars = new()
{ {
new ("0-4", stiple, 1915127), new ("0-4", stiple, 1915127),
new ("5-9", stiple, 2011016), new ("5-9", stiple, 2011016),
@@ -920,15 +919,15 @@ public class GraphViewExample : Scenario
// Generate line graph with 2,000 points // Generate line graph with 2,000 points
for (float x = -500; x < 500; x += 0.5f) for (float x = -500; x < 500; x += 0.5f)
{ {
points.Points.Add (new PointF (x, (float)Math.Sin (x))); points.Points.Add (new (x, (float)Math.Sin (x)));
line.Points.Add (new PointF (x, (float)Math.Sin (x))); line.Points.Add (new (x, (float)Math.Sin (x)));
} }
_graphView.Series.Add (points); _graphView.Series.Add (points);
_graphView.Annotations.Add (line); _graphView.Annotations.Add (line);
// How much graph space each cell of the console depicts // 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 // leave space for axis labels
_graphView.MarginBottom = 2; _graphView.MarginBottom = 2;
@@ -945,7 +944,7 @@ public class GraphViewExample : Scenario
_graphView.AxisY.Text = "↑Y"; _graphView.AxisY.Text = "↑Y";
_graphView.AxisY.LabelGetter = v => v.Value.ToString ("N2"); _graphView.AxisY.LabelGetter = v => v.Value.ToString ("N2");
_graphView.ScrollOffset = new PointF (-2.5f, -1); _graphView.ScrollOffset = new (-2.5f, -1);
_graphView.SetNeedsDisplay (); _graphView.SetNeedsDisplay ();
} }
@@ -971,10 +970,10 @@ public class GraphViewExample : Scenario
private void Zoom (float factor) private void Zoom (float factor)
{ {
_graphView.CellSize = new PointF ( _graphView.CellSize = new (
_graphView.CellSize.X * factor, _graphView.CellSize.X * factor,
_graphView.CellSize.Y * factor _graphView.CellSize.Y * factor
); );
_graphView.AxisX.Increment *= factor; _graphView.AxisX.Increment *= factor;
_graphView.AxisY.Increment *= factor; _graphView.AxisY.Increment *= factor;
@@ -992,11 +991,11 @@ public class GraphViewExample : Scenario
public DiscoBarSeries () public DiscoBarSeries ()
{ {
_green = new Attribute (Color.BrightGreen, Color.Black); _green = new (Color.BrightGreen, Color.Black);
_brightgreen = new Attribute (Color.Green, Color.Black); _brightgreen = new (Color.Green, Color.Black);
_brightyellow = new Attribute (Color.BrightYellow, Color.Black); _brightyellow = new (Color.BrightYellow, Color.Black);
_red = new Attribute (Color.Red, Color.Black); _red = new (Color.Red, Color.Black);
_brightred = new Attribute (Color.BrightRed, Color.Black); _brightred = new (Color.BrightRed, Color.Black);
} }
protected override void DrawBarLine (GraphView graph, Point start, Point end, BarSeriesBar beingDrawn) protected override void DrawBarLine (GraphView graph, Point start, Point end, BarSeriesBar beingDrawn)

View File

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

View File

@@ -113,142 +113,6 @@ public class ContextMenuTests (ITestOutputHelper output)
top.Dispose (); 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] [Fact]
[AutoInitShutdown] [AutoInitShutdown]
public void Draw_A_ContextMenu_Over_A_Borderless_Top () public void Draw_A_ContextMenu_Over_A_Borderless_Top ()