|
@@ -1,6 +1,7 @@
|
|
|
using System;
|
|
|
using System.Collections.ObjectModel;
|
|
|
using System.Linq;
|
|
|
+using System.Timers;
|
|
|
using Terminal.Gui;
|
|
|
|
|
|
namespace UICatalog.Scenarios;
|
|
@@ -34,15 +35,16 @@ public class Shortcuts : Scenario
|
|
|
{
|
|
|
X = Pos.AnchorEnd (),
|
|
|
Width = 40,
|
|
|
- Height = Dim.Fill (),
|
|
|
+ Height = Dim.Fill (4),
|
|
|
ColorScheme = Colors.ColorSchemes ["Toplevel"],
|
|
|
Source = new ListWrapper<string> (eventSource)
|
|
|
};
|
|
|
Application.Top.Add (eventLog);
|
|
|
|
|
|
- var shortcut1 = new Shortcut
|
|
|
+ var vShortcut1 = new Shortcut
|
|
|
{
|
|
|
- X = 20,
|
|
|
+ Orientation = Orientation.Vertical,
|
|
|
+ X = 0,
|
|
|
Width = 35,
|
|
|
Title = "A_pp Shortcut",
|
|
|
Key = Key.F1,
|
|
@@ -50,14 +52,15 @@ public class Shortcuts : Scenario
|
|
|
KeyBindingScope = KeyBindingScope.Application,
|
|
|
BorderStyle = LineStyle.Dotted
|
|
|
};
|
|
|
- shortcut1.Border.Thickness = new (1, 1, 1, 1);
|
|
|
- Application.Top.Add (shortcut1);
|
|
|
+ vShortcut1.Border.Thickness = new (1, 1, 1, 1);
|
|
|
+ Application.Top.Add (vShortcut1);
|
|
|
|
|
|
- var shortcut2 = new Shortcut
|
|
|
+ var vShortcut2 = new Shortcut
|
|
|
{
|
|
|
- X = 20,
|
|
|
- Y = Pos.Bottom (shortcut1) - 1,
|
|
|
- Width = Dim.Width (shortcut1),
|
|
|
+ Orientation = Orientation.Vertical,
|
|
|
+ X = 0,
|
|
|
+ Y = Pos.Bottom (vShortcut1) - 1,
|
|
|
+ Width = Dim.Width (vShortcut1),
|
|
|
Key = Key.F2,
|
|
|
Text = "Width is ^",
|
|
|
KeyBindingScope = KeyBindingScope.HotKey,
|
|
@@ -69,71 +72,73 @@ public class Shortcuts : Scenario
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- ((RadioGroup)shortcut2.CommandView).SelectedItemChanged += (o, args) =>
|
|
|
+ ((RadioGroup)vShortcut2.CommandView).SelectedItemChanged += (o, args) =>
|
|
|
{
|
|
|
eventSource.Add ($"SelectedItemChanged: {o.GetType ().Name} - {args.SelectedItem}");
|
|
|
eventLog.MoveDown ();
|
|
|
};
|
|
|
|
|
|
- shortcut2.Accept += (o, args) =>
|
|
|
+ vShortcut2.Accept += (o, args) =>
|
|
|
{
|
|
|
// Cycle to next item. If at end, set 0
|
|
|
- if (((RadioGroup)shortcut2.CommandView).SelectedItem < ((RadioGroup)shortcut2.CommandView).RadioLabels.Length - 1)
|
|
|
+ if (((RadioGroup)vShortcut2.CommandView).SelectedItem < ((RadioGroup)vShortcut2.CommandView).RadioLabels.Length - 1)
|
|
|
{
|
|
|
- ((RadioGroup)shortcut2.CommandView).SelectedItem++;
|
|
|
+ ((RadioGroup)vShortcut2.CommandView).SelectedItem++;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- ((RadioGroup)shortcut2.CommandView).SelectedItem = 0;
|
|
|
+ ((RadioGroup)vShortcut2.CommandView).SelectedItem = 0;
|
|
|
}
|
|
|
};
|
|
|
- shortcut2.Border.Thickness = new (1, 1, 1, 1);
|
|
|
- Application.Top.Add (shortcut2);
|
|
|
+ vShortcut2.Border.Thickness = new (1, 1, 1, 1);
|
|
|
+ Application.Top.Add (vShortcut2);
|
|
|
|
|
|
- var shortcut3 = new Shortcut
|
|
|
+ var vShortcut3 = new Shortcut
|
|
|
{
|
|
|
- X = 20,
|
|
|
- Y = Pos.Bottom (shortcut2),
|
|
|
+ Orientation = Orientation.Vertical,
|
|
|
+ X = 0,
|
|
|
+ Y = Pos.Bottom (vShortcut2),
|
|
|
CommandView = new CheckBox { Text = "_Align" },
|
|
|
Key = Key.F3,
|
|
|
HelpText = "Width is Fill",
|
|
|
Width = Dim.Fill () - Dim.Width (eventLog),
|
|
|
KeyBindingScope = KeyBindingScope.HotKey,
|
|
|
- BorderStyle = LineStyle.Dotted
|
|
|
+ BorderStyle = LineStyle.Rounded
|
|
|
};
|
|
|
- shortcut3.CommandView.CanFocus = true;
|
|
|
- shortcut3.Border.Thickness = new (1, 1, 1, 0);
|
|
|
+ vShortcut3.Border.Thickness = new (1, 1, 1, 0);
|
|
|
|
|
|
- ((CheckBox)shortcut3.CommandView).Toggled += (s, e) =>
|
|
|
+ ((CheckBox)vShortcut3.CommandView).Toggled += (s, e) =>
|
|
|
{
|
|
|
- if (shortcut3.CommandView is CheckBox cb)
|
|
|
+ if (vShortcut3.CommandView is CheckBox cb)
|
|
|
{
|
|
|
eventSource.Add ($"Toggled: {cb.Text}");
|
|
|
eventLog.MoveDown ();
|
|
|
|
|
|
var max = 0;
|
|
|
+ var toAlign = Application.Top.Subviews.Where (v => v is Shortcut s && s.Orientation == Orientation.Vertical && s.BorderStyle == LineStyle.Rounded);
|
|
|
|
|
|
if (e.NewValue == true)
|
|
|
{
|
|
|
- foreach (Shortcut peer in Application.Top.Subviews.Where (v => v is Shortcut)!)
|
|
|
+ foreach (Shortcut peer in toAlign)
|
|
|
{
|
|
|
max = Math.Max (max, peer.KeyView.Text.GetColumns ());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- foreach (Shortcut peer in Application.Top.Subviews.Where (v => v is Shortcut)!)
|
|
|
+ foreach (Shortcut peer in toAlign)
|
|
|
{
|
|
|
peer.MinimumKeyViewSize = max;
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
- Application.Top.Add (shortcut3);
|
|
|
+ Application.Top.Add (vShortcut3);
|
|
|
|
|
|
- var shortcut4 = new Shortcut
|
|
|
+ var vShortcut4 = new Shortcut
|
|
|
{
|
|
|
- X = 20,
|
|
|
- Y = Pos.Bottom (shortcut3),
|
|
|
- Width = Dim.Width (shortcut3),
|
|
|
+ Orientation = Orientation.Vertical,
|
|
|
+ X = 0,
|
|
|
+ Y = Pos.Bottom (vShortcut3),
|
|
|
+ Width = Dim.Width (vShortcut3),
|
|
|
CommandView = new Button
|
|
|
{
|
|
|
Title = "B_utton",
|
|
@@ -141,41 +146,56 @@ public class Shortcuts : Scenario
|
|
|
HelpText = "Width is Fill",
|
|
|
Key = Key.K,
|
|
|
KeyBindingScope = KeyBindingScope.HotKey,
|
|
|
- BorderStyle = LineStyle.Dotted
|
|
|
+ BorderStyle = LineStyle.Rounded
|
|
|
};
|
|
|
- Button button = (Button)shortcut4.CommandView;
|
|
|
- shortcut4.CommandView.Accept += Button_Clicked;
|
|
|
- shortcut4.CommandView.CanFocus = true;
|
|
|
- shortcut4.Border.Thickness = new (1, 0, 1,0);
|
|
|
+ Button button = (Button)vShortcut4.CommandView;
|
|
|
+ vShortcut4.CommandView.Accept += Button_Clicked;
|
|
|
+ vShortcut4.Border.Thickness = new (1, 0, 1, 0);
|
|
|
|
|
|
- Application.Top.Add (shortcut4);
|
|
|
+ Application.Top.Add (vShortcut4);
|
|
|
|
|
|
- var shortcut5 = new Shortcut
|
|
|
+ var vShortcut5 = new Shortcut
|
|
|
{
|
|
|
- X = 20,
|
|
|
- Y = Pos.Bottom (shortcut4) ,
|
|
|
- Width = Dim.Width (shortcut4),
|
|
|
+ Orientation = Orientation.Vertical,
|
|
|
+ X = 0,
|
|
|
+ Y = Pos.Bottom (vShortcut4),
|
|
|
+ Width = Dim.Width (vShortcut4),
|
|
|
|
|
|
- Title = "Fi_ve",
|
|
|
Key = Key.F5.WithCtrl.WithAlt.WithShift,
|
|
|
- HelpText = "Width is Fill",
|
|
|
+ HelpText = "CommandView.CanFocus",
|
|
|
KeyBindingScope = KeyBindingScope.HotKey,
|
|
|
- BorderStyle = LineStyle.Dotted
|
|
|
+ BorderStyle = LineStyle.Rounded,
|
|
|
+ CommandView = new CheckBox { Text = "_CanFocus" },
|
|
|
};
|
|
|
- shortcut5.Border.Thickness = new (1, 0, 1, 1);
|
|
|
+ vShortcut5.Border.Thickness = new (1, 0, 1, 1);
|
|
|
|
|
|
- Application.Top.Add (shortcut5);
|
|
|
+ ((CheckBox)vShortcut5.CommandView).Toggled += (s, e) =>
|
|
|
+ {
|
|
|
+ if (vShortcut5.CommandView is CheckBox cb)
|
|
|
+ {
|
|
|
+ eventSource.Add ($"Toggled: {cb.Text}");
|
|
|
+ eventLog.MoveDown ();
|
|
|
+
|
|
|
+ foreach (Shortcut peer in Application.Top.Subviews.Where (v => v is Shortcut)!)
|
|
|
+ {
|
|
|
+ peer.CanFocus = e.NewValue == true;
|
|
|
+ peer.CommandView.CanFocus = e.NewValue == true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+ Application.Top.Add (vShortcut5);
|
|
|
|
|
|
- var shortcutSlider = new Shortcut
|
|
|
+ var vShortcutSlider = new Shortcut
|
|
|
{
|
|
|
- X = 20,
|
|
|
- Y = Pos.Bottom (shortcut5) - 1,
|
|
|
+ Orientation = Orientation.Vertical,
|
|
|
+ X = 0,
|
|
|
+ Y = Pos.Bottom (vShortcut5) - 1,
|
|
|
Key = Key.F5,
|
|
|
HelpText = "Width is Fill",
|
|
|
- Width = Dim.Width (shortcut5),
|
|
|
+ Width = Dim.Width (vShortcut5),
|
|
|
|
|
|
KeyBindingScope = KeyBindingScope.HotKey,
|
|
|
- BorderStyle = LineStyle.Dotted,
|
|
|
+ BorderStyle = LineStyle.Rounded,
|
|
|
CommandView = new Slider<string>
|
|
|
{
|
|
|
Orientation = Orientation.Vertical,
|
|
@@ -183,31 +203,151 @@ public class Shortcuts : Scenario
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- ((Slider<string>)shortcutSlider.CommandView).Options = new () { new () { Legend = "A" }, new () { Legend = "B" }, new () { Legend = "C" } };
|
|
|
- ((Slider<string>)shortcutSlider.CommandView).SetOption (0);
|
|
|
- shortcutSlider.Border.Thickness = new (1, 1, 1, 1);
|
|
|
+ ((Slider<string>)vShortcutSlider.CommandView).Options = new () { new () { Legend = "A" }, new () { Legend = "B" }, new () { Legend = "C" } };
|
|
|
+ ((Slider<string>)vShortcutSlider.CommandView).SetOption (0);
|
|
|
+ vShortcutSlider.Border.Thickness = new (1, 1, 1, 1);
|
|
|
|
|
|
- ((Slider<string>)shortcutSlider.CommandView).OptionsChanged += (o, args) =>
|
|
|
+ ((Slider<string>)vShortcutSlider.CommandView).OptionsChanged += (o, args) =>
|
|
|
{
|
|
|
eventSource.Add ($"OptionsChanged: {o.GetType ().Name} - {args.Options}");
|
|
|
eventLog.MoveDown ();
|
|
|
};
|
|
|
|
|
|
- Application.Top.Add (shortcutSlider);
|
|
|
+ Application.Top.Add (vShortcutSlider);
|
|
|
|
|
|
- var shortcut6 = new Shortcut
|
|
|
+ var vShortcut6 = new Shortcut
|
|
|
{
|
|
|
- X = 20,
|
|
|
- Y = Pos.Bottom (shortcutSlider) - 1,
|
|
|
- Width = Dim.Width (shortcutSlider),
|
|
|
+ Orientation = Orientation.Vertical,
|
|
|
+ X = 0,
|
|
|
+ Y = Pos.Bottom (vShortcutSlider) - 1,
|
|
|
+ Width = Dim.Width (vShortcutSlider),
|
|
|
|
|
|
Title = "_No Key",
|
|
|
HelpText = "Keyless",
|
|
|
- BorderStyle = LineStyle.Dotted
|
|
|
+ BorderStyle = LineStyle.Rounded
|
|
|
+ };
|
|
|
+ vShortcut6.Border.Thickness = new (1, 1, 1, 1);
|
|
|
+
|
|
|
+ Application.Top.Add (vShortcut6);
|
|
|
+
|
|
|
+ ((CheckBox)vShortcut3.CommandView).OnToggled();
|
|
|
+
|
|
|
+ // Horizontal
|
|
|
+ var hShortcut1 = new Shortcut
|
|
|
+ {
|
|
|
+ X = Pos.Align (Alignment.Start, AlignmentModes.IgnoreFirstOrLast, 1),
|
|
|
+ Y = Pos.Bottom (eventLog) + 1,
|
|
|
+ Key = Key.F7,
|
|
|
+ HelpText = "Horizontal",
|
|
|
+ BorderStyle = LineStyle.Dashed,
|
|
|
+ CanFocus = false
|
|
|
+ };
|
|
|
+ hShortcut1.Border.Thickness = new (0, 0, 1, 0);
|
|
|
+
|
|
|
+ hShortcut1.CommandView = new ProgressBar
|
|
|
+ {
|
|
|
+ Text = "Progress",
|
|
|
+ Title = "P",
|
|
|
+ Fraction = 0.5f,
|
|
|
+ Width = 10,
|
|
|
+ Height = 1,
|
|
|
+ ProgressBarStyle = ProgressBarStyle.Continuous
|
|
|
+ };
|
|
|
+ hShortcut1.CommandView.Width = 10;
|
|
|
+ hShortcut1.CommandView.Height = 1;
|
|
|
+ hShortcut1.CommandView.CanFocus = false;
|
|
|
+ Timer timer = new (10)
|
|
|
+ {
|
|
|
+ AutoReset = true,
|
|
|
+ };
|
|
|
+ timer.Elapsed += (o, args) =>
|
|
|
+ {
|
|
|
+ if (hShortcut1.CommandView is ProgressBar pb)
|
|
|
+ {
|
|
|
+ if (pb.Fraction == 1.0)
|
|
|
+ {
|
|
|
+ pb.Fraction = 0;
|
|
|
+ }
|
|
|
+ pb.Fraction += 0.01f;
|
|
|
+
|
|
|
+ Application.Wakeup ();
|
|
|
+
|
|
|
+ pb.SetNeedsDisplay ();
|
|
|
+ }
|
|
|
+ };
|
|
|
+ timer.Start ();
|
|
|
+
|
|
|
+ Application.Top.Add (hShortcut1);
|
|
|
+
|
|
|
+ var textField = new TextField ()
|
|
|
+ {
|
|
|
+ Text = "Edit me",
|
|
|
+ Width = 10,
|
|
|
+ Height = 1,
|
|
|
+ CanFocus = true
|
|
|
+ };
|
|
|
+
|
|
|
+ var hShortcut2 = new Shortcut
|
|
|
+ {
|
|
|
+ X = Pos.Align (Alignment.Start, AlignmentModes.IgnoreFirstOrLast, 1),
|
|
|
+ Y = Pos.Top (hShortcut1),
|
|
|
+ Key = Key.F8,
|
|
|
+ HelpText = "Edit",
|
|
|
+ CanFocus = true,
|
|
|
+ BorderStyle = LineStyle.Dashed,
|
|
|
+ CommandView = textField,
|
|
|
+ };
|
|
|
+ hShortcut2.Border.Thickness = new (0, 0, 1, 0);
|
|
|
+
|
|
|
+ Application.Top.Add (hShortcut2);
|
|
|
+
|
|
|
+ var hShortcutBG = new Shortcut
|
|
|
+ {
|
|
|
+ X = Pos.Align (Alignment.Start, AlignmentModes.IgnoreFirstOrLast, 1)-1,
|
|
|
+ Y = Pos.Top (hShortcut2),
|
|
|
+ Key = Key.F9,
|
|
|
+ HelpText = "BG Color",
|
|
|
+ BorderStyle = LineStyle.Dashed,
|
|
|
+ CanFocus = false
|
|
|
+ };
|
|
|
+
|
|
|
+ var bgColor = new ColorPicker ()
|
|
|
+ {
|
|
|
+ CanFocus = false,
|
|
|
+ BoxHeight = 1,
|
|
|
+ BoxWidth = 1,
|
|
|
};
|
|
|
- shortcut6.Border.Thickness = new (1, 1, 1, 1);
|
|
|
+ bgColor.ColorChanged += (o, args) =>
|
|
|
+ {
|
|
|
+ Application.Top.ColorScheme = new ColorScheme (Application.Top.ColorScheme)
|
|
|
+ {
|
|
|
+ Normal = new Attribute (Application.Top.ColorScheme.Normal.Foreground, args.Color),
|
|
|
+ };
|
|
|
+ };
|
|
|
+ hShortcutBG.CommandView = bgColor;
|
|
|
+ hShortcutBG.Border.Thickness = new (1, 0, 1, 0);
|
|
|
+
|
|
|
+ Application.Top.Add (hShortcutBG);
|
|
|
+
|
|
|
+ var hShortcut3 = new Shortcut
|
|
|
+ {
|
|
|
+ X = Pos.Align (Alignment.Start, AlignmentModes.IgnoreFirstOrLast, 1),
|
|
|
+ Y = Pos.Top (hShortcut2),
|
|
|
+ Key = Key.Esc,
|
|
|
+ KeyBindingScope = KeyBindingScope.Application,
|
|
|
+ Title = "Quit",
|
|
|
+ HelpText = "App Scope",
|
|
|
+ BorderStyle = LineStyle.Dashed,
|
|
|
+ CanFocus = false
|
|
|
+ };
|
|
|
+ hShortcut3.Border.Thickness = new (0);
|
|
|
+ hShortcut3.Accept += (o, args) =>
|
|
|
+ {
|
|
|
+ Application.RequestStop ();
|
|
|
+ };
|
|
|
+
|
|
|
+ Application.Top.Add (hShortcut3);
|
|
|
|
|
|
- Application.Top.Add (shortcut6);
|
|
|
|
|
|
foreach (View sh in Application.Top.Subviews.Where (v => v is Shortcut)!)
|
|
|
{
|