From 844c0f7038a13e8ed687f6d1fcd494393e113ed9 Mon Sep 17 00:00:00 2001 From: Charlie Kindel Date: Sun, 31 May 2020 09:05:10 -0600 Subject: [PATCH 1/3] enhanced Scrolling demos --- Example/demo.cs | 2 +- UICatalog/Scenarios/Scrolling.cs | 120 ++++++++++++++++++++++++++++++- 2 files changed, 119 insertions(+), 3 deletions(-) diff --git a/Example/demo.cs b/Example/demo.cs index edae3a77b..280f460cc 100644 --- a/Example/demo.cs +++ b/Example/demo.cs @@ -508,7 +508,7 @@ static class Demo { //Application.UseSystemConsole = true; - Application.Init (); + Application.Init(); var top = Application.Top; diff --git a/UICatalog/Scenarios/Scrolling.cs b/UICatalog/Scenarios/Scrolling.cs index 78e554d0e..afb2fc582 100644 --- a/UICatalog/Scenarios/Scrolling.cs +++ b/UICatalog/Scenarios/Scrolling.cs @@ -7,6 +7,80 @@ namespace UICatalog { [ScenarioCategory ("Bug Repro")] class Scrolling : Scenario { + + //class Box10x : View, IScrollView { + class Box10x : View { + int w = 40; + int h = 50; + + public bool WantCursorPosition { get; set; } = false; + + public Box10x (int x, int y) : base (new Rect (x, y, 20, 10)) + { + } + + public Size GetContentSize () + { + return new Size (w, h); + } + + public void SetCursorPosition (Point pos) + { + throw new NotImplementedException (); + } + + public override void Redraw (Rect bounds) + { + //Point pos = new Point (region.X, region.Y); + Driver.SetAttribute (ColorScheme.Focus); + + for (int y = 0; y < h; y++) { + Move (0, y); + Driver.AddStr (y.ToString ()); + for (int x = 0; x < w - y.ToString ().Length; x++) { + //Driver.AddRune ((Rune)('0' + (x + y) % 10)); + if (y.ToString ().Length < w) + Driver.AddStr (" "); + } + } + //Move (pos.X, pos.Y); + } + } + + class Filler : View { + public Filler (Rect rect) : base (rect) + { + } + + public override void Redraw (Rect bounds) + { + Driver.SetAttribute (ColorScheme.Focus); + var f = Frame; + + for (int y = 0; y < f.Width; y++) { + Move (0, y); + for (int x = 0; x < f.Height; x++) { + Rune r; + switch (x % 3) { + case 0: + Driver.AddRune (y.ToString ().ToCharArray (0, 1) [0]); + if (y > 9) + Driver.AddRune (y.ToString ().ToCharArray (1, 1) [0]); + r = '.'; + break; + case 1: + r = 'o'; + break; + default: + r = 'O'; + break; + } + Driver.AddRune (r); + } + } + } + } + public override void Setup () { Win.X = 1; @@ -14,7 +88,8 @@ namespace UICatalog { Win.Width = Dim.Fill () - 4; Win.Height = Dim.Fill () - 2; var label = new Label ("ScrollView (new Rect (2, 2, 50, 20)) with a 200, 100 ContentSize...") { - X = 0, Y = 0, + X = 0, + Y = 0, ColorScheme = Colors.Dialog }; Win.Add (label); @@ -60,7 +135,11 @@ namespace UICatalog { scrollView.Add (new Button ("A very long button. Should be wide enough to demo clipping!") { X = 3, Y = 4, +<<<<<<< Updated upstream Width = 50, +======= + Width = Dim.Fill (6), +>>>>>>> Stashed changes Clicked = () => MessageBox.Query (20, 7, "MessageBox", "Neat?", "Yes", "No") }); @@ -101,7 +180,44 @@ namespace UICatalog { }; scrollView.Add (anchorButton); - Win.Add (scrollView); + var scrollView2 = new ScrollView (new Rect (55, 2, 20, 8)) { + ContentSize = new Size (20, 50), + //ContentOffset = new Point (0, 0), + ShowVerticalScrollIndicator = true, + ShowHorizontalScrollIndicator = true + }; + scrollView2.Add (new Filler(new Rect (0, 0, 60, 40))); + + // This is just to debug the visuals of the scrollview when small + var scrollView3 = new ScrollView (new Rect (55, 15, 3, 3)) { + ContentSize = new Size (100, 100), + ShowVerticalScrollIndicator = true, + ShowHorizontalScrollIndicator = true + }; + scrollView3.Add (new Box10x (0, 0)); + + int count = 0; + var mousePos = new Label ("Mouse: "); + mousePos.X = Pos.Center (); + mousePos.Y = Pos.AnchorEnd (1); + mousePos.Width = 50; + Application.RootMouseEvent += delegate (MouseEvent me) { + mousePos.TextColor = Colors.TopLevel.Normal; + mousePos.Text = $"Mouse: ({me.X},{me.Y}) - {me.Flags} {count++}"; + }; + + var progress = new ProgressBar (); + progress.X = 5; + progress.Y = Pos.AnchorEnd (3); + progress.Width = 50; + bool timer (MainLoop caller) + { + progress.Pulse (); + return true; + } + Application.MainLoop.AddTimeout (TimeSpan.FromMilliseconds (300), timer); + + Win.Add (scrollView, scrollView2, scrollView3, mousePos, progress); } } } \ No newline at end of file From 2e79a2058197688f92136a24d12c1c2a4579226e Mon Sep 17 00:00:00 2001 From: Charlie Kindel Date: Sun, 31 May 2020 09:11:01 -0600 Subject: [PATCH 2/3] fixed merge conflict --- UICatalog/Scenarios/Scrolling.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/UICatalog/Scenarios/Scrolling.cs b/UICatalog/Scenarios/Scrolling.cs index afb2fc582..27317d025 100644 --- a/UICatalog/Scenarios/Scrolling.cs +++ b/UICatalog/Scenarios/Scrolling.cs @@ -135,11 +135,7 @@ namespace UICatalog { scrollView.Add (new Button ("A very long button. Should be wide enough to demo clipping!") { X = 3, Y = 4, -<<<<<<< Updated upstream - Width = 50, -======= Width = Dim.Fill (6), ->>>>>>> Stashed changes Clicked = () => MessageBox.Query (20, 7, "MessageBox", "Neat?", "Yes", "No") }); From 222a71d9eac8d9ba7a36061dfc37c91344e31680 Mon Sep 17 00:00:00 2001 From: Charlie Kindel Date: Sun, 31 May 2020 09:14:32 -0600 Subject: [PATCH 3/3] removed extraneous changes --- Terminal.Gui/Core/View.cs | 3 +-- Terminal.Gui/Views/ScrollView.cs | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Terminal.Gui/Core/View.cs b/Terminal.Gui/Core/View.cs index a3f2650d8..b426a9a06 100644 --- a/Terminal.Gui/Core/View.cs +++ b/Terminal.Gui/Core/View.cs @@ -891,8 +891,7 @@ namespace Terminal.Gui { Application.CurrentView = view; // Ensure we don't make the Driver's clip rect any bigger - if (SuperView != null && SuperView.Bounds.Contains (RectToScreen (Frame))) { - //if (Driver.Clip.IsEmpty || Driver.Clip.Contains(RectToScreen (view.Frame))) { + if (Driver.Clip.IsEmpty || Driver.Clip.Contains(RectToScreen (view.Frame))) { var savedClip = view.ClipToBounds (); view.Redraw (view.Bounds); Driver.Clip = savedClip; diff --git a/Terminal.Gui/Views/ScrollView.cs b/Terminal.Gui/Views/ScrollView.cs index e8edd6e2d..89b7d1f06 100644 --- a/Terminal.Gui/Views/ScrollView.cs +++ b/Terminal.Gui/Views/ScrollView.cs @@ -405,9 +405,9 @@ namespace Terminal.Gui { Clear (); if (Driver.Clip.IsEmpty || Driver.Clip.Contains (RectToScreen (Frame))) { - var savedClip = ClipToBounds (); - contentView.Redraw (contentView.Frame); - Driver.Clip = savedClip; + var savedClip = ClipToBounds (); + contentView.Redraw (contentView.Frame); + Driver.Clip = savedClip; } else { contentView.Redraw (contentView.Bounds); }