From 8df0ea44dc4cf4fb032f45a629604e9ec2a347e4 Mon Sep 17 00:00:00 2001 From: Tig Date: Fri, 12 Apr 2024 14:34:51 -0600 Subject: [PATCH] Scenario clean up --- Terminal.Gui/Application.cs | 1 - UICatalog/Scenarios/CharacterMap.cs | 123 ++++++++---------- UICatalog/Scenarios/Clipping.cs | 2 + UICatalog/Scenarios/Coordinates.cs | 50 ------- UICatalog/Scenarios/ListColumns.cs | 2 + UICatalog/Scenarios/Scrolling.cs | 1 + ...lContentScrolling.cs => VirtualContent.cs} | 98 ++++++-------- 7 files changed, 103 insertions(+), 174 deletions(-) delete mode 100644 UICatalog/Scenarios/Coordinates.cs rename UICatalog/Scenarios/{VirtualContentScrolling.cs => VirtualContent.cs} (77%) diff --git a/Terminal.Gui/Application.cs b/Terminal.Gui/Application.cs index 58dca8940..1cb3ee4e3 100644 --- a/Terminal.Gui/Application.cs +++ b/Terminal.Gui/Application.cs @@ -1457,7 +1457,6 @@ public static partial class Application return; } - // TODO: In PR #3273, FindDeepestView will return adornments. Update logic below to fix adornment mouse handling var view = View.FindDeepestView (Current, mouseEvent.X, mouseEvent.Y); if (view is { }) diff --git a/UICatalog/Scenarios/CharacterMap.cs b/UICatalog/Scenarios/CharacterMap.cs index 1b5d2cb21..7b3fbe1cc 100644 --- a/UICatalog/Scenarios/CharacterMap.cs +++ b/UICatalog/Scenarios/CharacterMap.cs @@ -19,12 +19,15 @@ namespace UICatalog.Scenarios; /// /// This Scenario demonstrates building a custom control (a class deriving from View) that: - Provides a /// "Character Map" application (like Windows' charmap.exe). - Helps test unicode character rendering in Terminal.Gui - -/// Illustrates how to use ScrollView to do infinite scrolling +/// Illustrates how to do infinite scrolling /// -[ScenarioMetadata ("Character Map", "Unicode viewer demonstrating the ScrollView control.")] +[ScenarioMetadata ("Character Map", "Unicode viewer demonstrating infinite content, scrolling, and Unicode.")] [ScenarioCategory ("Text and Formatting")] +[ScenarioCategory ("Drawing")] [ScenarioCategory ("Controls")] -[ScenarioCategory ("ScrollView")] +[ScenarioCategory ("Layout")] +[ScenarioCategory ("Scrolling")] + public class CharacterMap : Scenario { public Label _errorLabel; @@ -36,7 +39,7 @@ public class CharacterMap : Scenario { Application.Init (); - var top = new Window () + var top = new Window { BorderStyle = LineStyle.None }; @@ -105,26 +108,26 @@ public class CharacterMap : Scenario // if user clicks the mouse in TableView _categoryList.MouseClick += (s, e) => - { - _categoryList.ScreenToCell (e.MouseEvent.X, e.MouseEvent.Y, out int? clickedCol); + { + _categoryList.ScreenToCell (e.MouseEvent.X, e.MouseEvent.Y, out int? clickedCol); - if (clickedCol != null && e.MouseEvent.Flags.HasFlag (MouseFlags.Button1Clicked)) - { - EnumerableTableSource table = (EnumerableTableSource)_categoryList.Table; - string prevSelection = table.Data.ElementAt (_categoryList.SelectedRow).Category; - isDescending = !isDescending; + if (clickedCol != null && e.MouseEvent.Flags.HasFlag (MouseFlags.Button1Clicked)) + { + EnumerableTableSource table = (EnumerableTableSource)_categoryList.Table; + string prevSelection = table.Data.ElementAt (_categoryList.SelectedRow).Category; + isDescending = !isDescending; - _categoryList.Table = CreateCategoryTable (clickedCol.Value, isDescending); + _categoryList.Table = CreateCategoryTable (clickedCol.Value, isDescending); - table = (EnumerableTableSource)_categoryList.Table; + table = (EnumerableTableSource)_categoryList.Table; - _categoryList.SelectedRow = table.Data - .Select ((item, index) => new { item, index }) - .FirstOrDefault (x => x.item.Category == prevSelection) - ?.index - ?? -1; - } - }; + _categoryList.SelectedRow = table.Data + .Select ((item, index) => new { item, index }) + .FirstOrDefault (x => x.item.Category == prevSelection) + ?.index + ?? -1; + } + }; int longestName = UnicodeRange.Ranges.Max (r => r.Category.GetColumns ()); @@ -138,14 +141,13 @@ public class CharacterMap : Scenario _categoryList.Width = _categoryList.Style.ColumnStyles.Sum (c => c.Value.MinWidth) + 4; _categoryList.SelectedCellChanged += (s, args) => - { - EnumerableTableSource table = (EnumerableTableSource)_categoryList.Table; - _charMap.StartCodePoint = table.Data.ToArray () [args.NewRow].Start; - }; + { + EnumerableTableSource table = (EnumerableTableSource)_categoryList.Table; + _charMap.StartCodePoint = table.Data.ToArray () [args.NewRow].Start; + }; top.Add (_categoryList); - // TODO: Replace this with Dim.Auto when that's ready _categoryList.Initialized += _categoryList_Initialized; @@ -466,8 +468,9 @@ internal class CharMap : View MouseEvent += Handle_MouseEvent; // Prototype scrollbars - Padding.Thickness = new Thickness (0, 0, 1, 1); - var up = new Button () + Padding.Thickness = new (0, 0, 1, 1); + + var up = new Button { AutoSize = false, X = Pos.AnchorEnd (1), @@ -478,15 +481,11 @@ internal class CharMap : View NoDecorations = true, Title = CM.Glyphs.UpArrow.ToString (), WantContinuousButtonPressed = true, - CanFocus = false, - - }; - up.Accept += (sender, args) => - { - args.Cancel = ScrollVertical (-1) == true; + CanFocus = false }; + up.Accept += (sender, args) => { args.Cancel = ScrollVertical (-1) == true; }; - var down = new Button () + var down = new Button { AutoSize = false, X = Pos.AnchorEnd (1), @@ -497,15 +496,11 @@ internal class CharMap : View NoDecorations = true, Title = CM.Glyphs.DownArrow.ToString (), WantContinuousButtonPressed = true, - CanFocus = false, - - }; - down.Accept += (sender, args) => - { - ScrollVertical (1); + CanFocus = false }; + down.Accept += (sender, args) => { ScrollVertical (1); }; - var left = new Button () + var left = new Button { AutoSize = false, X = 0, @@ -516,15 +511,11 @@ internal class CharMap : View NoDecorations = true, Title = CM.Glyphs.LeftArrow.ToString (), WantContinuousButtonPressed = true, - CanFocus = false, - - }; - left.Accept += (sender, args) => - { - ScrollHorizontal (-1); + CanFocus = false }; + left.Accept += (sender, args) => { ScrollHorizontal (-1); }; - var right = new Button () + var right = new Button { AutoSize = false, X = Pos.AnchorEnd (2), @@ -535,14 +526,9 @@ internal class CharMap : View NoDecorations = true, Title = CM.Glyphs.RightArrow.ToString (), WantContinuousButtonPressed = true, - CanFocus = false, - + CanFocus = false }; - right.Accept += (sender, args) => - { - ScrollHorizontal (1); - }; - + right.Accept += (sender, args) => { ScrollHorizontal (1); }; Padding.Add (up, down, left, right); } @@ -553,6 +539,7 @@ internal class CharMap : View { ScrollVertical (1); e.Handled = true; + return; } @@ -576,7 +563,6 @@ internal class CharMap : View { ScrollHorizontal (-1); e.Handled = true; - } } @@ -609,6 +595,7 @@ internal class CharMap : View { return; } + _selected = value; if (IsInitialized) @@ -640,6 +627,7 @@ internal class CharMap : View Viewport = Viewport with { X = col - width }; } } + SetNeedsDisplay (); SelectedCodePointChanged?.Invoke (this, new (SelectedCodePoint, null)); } @@ -882,7 +870,6 @@ internal class CharMap : View return; } - args.Handled = true; if (me.Y == 0) @@ -971,7 +958,7 @@ internal class CharMap : View { var client = new UcdApiClient (); var decResponse = string.Empty; - string getCodePointError = string.Empty; + var getCodePointError = string.Empty; var waitIndicator = new Dialog { @@ -1037,7 +1024,7 @@ internal class CharMap : View document.RootElement, new JsonSerializerOptions - { WriteIndented = true } + { WriteIndented = true } ); } @@ -1050,16 +1037,16 @@ internal class CharMap : View var dlg = new Dialog { Title = title, Buttons = [copyGlyph, copyCP, cancel] }; copyGlyph.Accept += (s, a) => - { - CopyGlyph (); - dlg.RequestStop (); - }; + { + CopyGlyph (); + dlg.RequestStop (); + }; copyCP.Accept += (s, a) => - { - CopyCodePoint (); - dlg.RequestStop (); - }; + { + CopyCodePoint (); + dlg.RequestStop (); + }; cancel.Accept += (s, a) => dlg.RequestStop (); var rune = (Rune)SelectedCodePoint; @@ -1258,4 +1245,4 @@ internal class UnicodeRange return ranges.Concat (nonBmpRanges).OrderBy (r => r.Category).ToList (); } -} \ No newline at end of file +} diff --git a/UICatalog/Scenarios/Clipping.cs b/UICatalog/Scenarios/Clipping.cs index e0a1fefc4..0aba6ece9 100644 --- a/UICatalog/Scenarios/Clipping.cs +++ b/UICatalog/Scenarios/Clipping.cs @@ -4,6 +4,8 @@ namespace UICatalog.Scenarios; [ScenarioMetadata ("Clipping", "Used to test that things clip correctly")] [ScenarioCategory ("Tests")] +[ScenarioCategory ("Drawing")] +[ScenarioCategory ("Scrolling")] public class Clipping : Scenario { public override void Init () diff --git a/UICatalog/Scenarios/Coordinates.cs b/UICatalog/Scenarios/Coordinates.cs deleted file mode 100644 index 48a85eaf6..000000000 --- a/UICatalog/Scenarios/Coordinates.cs +++ /dev/null @@ -1,50 +0,0 @@ -using Terminal.Gui; - -namespace UICatalog.Scenarios; - -[ScenarioMetadata ("Coordinates", "Demonstrates Screen, Frame, Content, and Viewport coordinates.")] -[ScenarioCategory ("Layout")] -public sealed class Coordinates : Scenario -{ - public override void Main () - { - // Init - Application.Init (); - - // Setup - Create a top-level application window and configure it. - Window app = new () - { - Title = $"Application/Screen", - BorderStyle = LineStyle.HeavyDotted - }; - - View frame = new () - { - Title = "", - Text = "Content - Location (0 0), Size: (54, 14)", - X = 3, - Y = 3, - Width = 60, - Height = 20, - ColorScheme = new ColorScheme (new Attribute (Color.Black, Color.White)) - }; - frame.Margin.Thickness = new (1); - frame.Margin.ColorScheme = new ColorScheme (new Attribute (Color.Black, Color.BrightRed)); - frame.Margin.Add (new Label () { Title = "Margin - Frame-Relative Location (0,0)" }); - frame.Border.LineStyle = LineStyle.None; - frame.Border.Thickness = new (1); - frame.Border.ColorScheme = new ColorScheme (new Attribute (Color.Black, Color.BrightGreen)); - frame.Border.Add (new Label () { Title = "Border - Frame-Relative Location (1,1)" }); - frame.Padding.Thickness = new (1); - frame.Padding.ColorScheme = new ColorScheme (new Attribute (Color.Black, Color.BrightYellow)); - frame.Padding.Add (new Label () { Title = "Padding - Frame-Relative Location (2,2)" }); - - app.Add (frame); - // Run - Start the application. - Application.Run (app); - app.Dispose (); - - // Shutdown - Calling Application.Shutdown is required. - Application.Shutdown (); - } -} diff --git a/UICatalog/Scenarios/ListColumns.cs b/UICatalog/Scenarios/ListColumns.cs index 1dbe19a1d..0f92e1aad 100644 --- a/UICatalog/Scenarios/ListColumns.cs +++ b/UICatalog/Scenarios/ListColumns.cs @@ -12,6 +12,8 @@ namespace UICatalog.Scenarios; [ScenarioCategory ("Dialogs")] [ScenarioCategory ("Text and Formatting")] [ScenarioCategory ("Top Level Windows")] +[ScenarioCategory ("Scrolling")] + public class ListColumns : Scenario { private ColorScheme _alternatingColorScheme; diff --git a/UICatalog/Scenarios/Scrolling.cs b/UICatalog/Scenarios/Scrolling.cs index a85651e0c..9e7215ad7 100644 --- a/UICatalog/Scenarios/Scrolling.cs +++ b/UICatalog/Scenarios/Scrolling.cs @@ -7,6 +7,7 @@ namespace UICatalog.Scenarios; [ScenarioMetadata ("Scrolling", "Demonstrates ScrollView etc...")] [ScenarioCategory ("Controls")] [ScenarioCategory ("ScrollView")] +[ScenarioCategory ("Scrolling")] [ScenarioCategory ("Tests")] public class Scrolling : Scenario { diff --git a/UICatalog/Scenarios/VirtualContentScrolling.cs b/UICatalog/Scenarios/VirtualContent.cs similarity index 77% rename from UICatalog/Scenarios/VirtualContentScrolling.cs rename to UICatalog/Scenarios/VirtualContent.cs index 6dc6c9ccc..434b5252b 100644 --- a/UICatalog/Scenarios/VirtualContentScrolling.cs +++ b/UICatalog/Scenarios/VirtualContent.cs @@ -1,16 +1,16 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; +using System.ComponentModel; using System.Linq; using Terminal.Gui; namespace UICatalog.Scenarios; -[ScenarioMetadata ("_Virtual Content Scrolling Demo", "Demonstrates scrolling built-into View")] +[ScenarioMetadata ("Virtual Content", "Demonstrates using Viewport to enable scrolling content.")] [ScenarioCategory ("Layout")] -public class VirtualScrolling : Scenario +[ScenarioCategory ("Drawing")] +public class VirtualContent : Scenario { private ViewDiagnosticFlags _diagnosticFlags; + public class VirtualDemoView : FrameView { public VirtualDemoView () @@ -18,13 +18,12 @@ public class VirtualScrolling : Scenario Width = Dim.Fill (); Height = Dim.Fill (); ColorScheme = Colors.ColorSchemes ["Base"]; - Text = "Virtual Demo View Text. This is long text.\nThe second line.\n3\n4\n5th line\nLine 6. This is a longer line that should wrap automatically."; + Text = "Virtual Content Text. This is long text.\nThe second line.\n3\n4\n5th line\nLine 6. This is a longer line that should wrap automatically."; CanFocus = true; BorderStyle = LineStyle.Rounded; Arrangement = ViewArrangement.Fixed; - // TODO: Add a way to set the scroll settings in the Scenario - ContentSize = new Size (60, 40); + ContentSize = new (60, 40); ViewportSettings |= ViewportSettings.ClearVisibleContentOnly; // Things this view knows how to do @@ -34,23 +33,13 @@ public class VirtualScrolling : Scenario AddCommand (Command.ScrollRight, () => ScrollHorizontal (1)); AddCommand (Command.ScrollLeft, () => ScrollHorizontal (-1)); - //AddCommand (Command.PageUp, () => PageUp ()); - //AddCommand (Command.PageDown, () => PageDown ()); - //AddCommand (Command.TopHome, () => Home ()); - //AddCommand (Command.BottomEnd, () => End ()); - // Default keybindings for all ListViews KeyBindings.Add (Key.CursorUp, Command.ScrollUp); KeyBindings.Add (Key.CursorDown, Command.ScrollDown); KeyBindings.Add (Key.CursorLeft, Command.ScrollLeft); KeyBindings.Add (Key.CursorRight, Command.ScrollRight); - //KeyBindings.Add (Key.PageUp, Command.PageUp); - //KeyBindings.Add (Key.PageDown, Command.PageDown); - //KeyBindings.Add (Key.Home, Command.TopHome); - //KeyBindings.Add (Key.End, Command.BottomEnd); - - Border.Add (new Label () { X = 23 }); + Border.Add (new Label { X = 23 }); LayoutComplete += VirtualDemoView_LayoutComplete; MouseEvent += VirtualDemoView_MouseEvent; @@ -61,8 +50,10 @@ public class VirtualScrolling : Scenario if (e.MouseEvent.Flags == MouseFlags.WheeledDown) { ScrollVertical (1); + return; } + if (e.MouseEvent.Flags == MouseFlags.WheeledUp) { ScrollVertical (-1); @@ -73,20 +64,19 @@ public class VirtualScrolling : Scenario if (e.MouseEvent.Flags == MouseFlags.WheeledRight) { ScrollHorizontal (1); + return; } + if (e.MouseEvent.Flags == MouseFlags.WheeledLeft) { ScrollHorizontal (-1); - - return; } - } private void VirtualDemoView_LayoutComplete (object sender, LayoutEventArgs e) { - var status = Border.Subviews.OfType