From 157f1db28831e8d3d23d10d6594e4fb41e284563 Mon Sep 17 00:00:00 2001 From: Tig Date: Mon, 27 May 2024 22:26:45 -0600 Subject: [PATCH] Temporarily added SetContentSize to ScrollView and fixed other scenarios --- Terminal.Gui/Views/ScrollView.cs | 7 +++++++ UICatalog/Scenarios/ASCIICustomButton.cs | 2 +- UICatalog/Scenarios/Clipping.cs | 2 +- UICatalog/Scenarios/ContentScrolling.cs | 17 ++++++++++++----- UICatalog/Scenarios/Scrolling.cs | 2 +- 5 files changed, 22 insertions(+), 8 deletions(-) diff --git a/Terminal.Gui/Views/ScrollView.cs b/Terminal.Gui/Views/ScrollView.cs index d62729223..a884be638 100644 --- a/Terminal.Gui/Views/ScrollView.cs +++ b/Terminal.Gui/Views/ScrollView.cs @@ -136,6 +136,13 @@ public class ScrollView : View ContentSizeChanged += ScrollViewContentSizeChanged; } + [ObsoleteAttribute ("This method is obsolete and will be removed in v2.", false)] + public void SetContentSize (Size contentSize) + { + ContentSize = contentSize; + } + + private void ScrollViewContentSizeChanged (object sender, SizeChangedEventArgs e) { if (e.Size is null) diff --git a/UICatalog/Scenarios/ASCIICustomButton.cs b/UICatalog/Scenarios/ASCIICustomButton.cs index 8b9833173..e1ecff50f 100644 --- a/UICatalog/Scenarios/ASCIICustomButton.cs +++ b/UICatalog/Scenarios/ASCIICustomButton.cs @@ -236,7 +236,7 @@ public class ASCIICustomButtonTest : Scenario } // BUGBUG: set_ContentSize is supposed to be `protected`. - _scrollView.ContentSize = new (25, pages * BUTTONS_ON_PAGE * BUTTON_HEIGHT); + _scrollView.SetContentSize (new (25, pages * BUTTONS_ON_PAGE * BUTTON_HEIGHT)); if (_smallerWindow) { diff --git a/UICatalog/Scenarios/Clipping.cs b/UICatalog/Scenarios/Clipping.cs index 6fc3782f1..2e30253ab 100644 --- a/UICatalog/Scenarios/Clipping.cs +++ b/UICatalog/Scenarios/Clipping.cs @@ -30,7 +30,7 @@ public class Clipping : Scenario var scrollView = new ScrollView { X = 3, Y = 3, Width = 50, Height = 20 }; scrollView.ColorScheme = Colors.ColorSchemes ["Menu"]; // BUGBUG: set_ContentSize is supposed to be `protected`. - scrollView.ContentSize = new (200, 100); + scrollView.SetContentSize (new (200, 100)); //ContentOffset = Point.Empty, scrollView.AutoHideScrollBars = true; diff --git a/UICatalog/Scenarios/ContentScrolling.cs b/UICatalog/Scenarios/ContentScrolling.cs index cf4b721cd..c08870f25 100644 --- a/UICatalog/Scenarios/ContentScrolling.cs +++ b/UICatalog/Scenarios/ContentScrolling.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using Terminal.Gui; @@ -51,6 +52,12 @@ public class ContentScrolling : Scenario MouseEvent += VirtualDemoView_MouseEvent; } + [ObsoleteAttribute ("This method is obsolete and will be removed in v2.", false)] + public void SetContentSize (Size contentSize) + { + ContentSize = contentSize; + } + private void VirtualDemoView_MouseEvent (object sender, MouseEventEventArgs e) { if (e.MouseEvent.Flags == MouseFlags.WheeledDown) @@ -245,7 +252,7 @@ public class ContentScrolling : Scenario return; } // BUGBUG: set_ContentSize is supposed to be `protected`. - view.ContentSize = view.ContentSize with { Width = e.NewValue }; + view.SetContentSize (view.ContentSize with { Width = e.NewValue }); } var labelComma = new Label @@ -273,7 +280,7 @@ public class ContentScrolling : Scenario return; } // BUGBUG: set_ContentSize is supposed to be `protected`. - view.ContentSize = view.ContentSize with { Height = e.NewValue }; + view.SetContentSize (view.ContentSize with { Height = e.NewValue }); } var cbClearOnlyVisible = new CheckBox @@ -355,8 +362,8 @@ public class ContentScrolling : Scenario { X = Pos.Center (), Y = Pos.Bottom (textView) + 1, - Width = Dim.Auto(DimAutoStyle.Content, maximumContentDim: Dim.Func (() => view.ContentSize.Width)), - Height = Dim.Auto (DimAutoStyle.Content, maximumContentDim: Dim.Percent(20)), + Width = Dim.Auto (DimAutoStyle.Content, maximumContentDim: Dim.Func (() => view.ContentSize.Width)), + Height = Dim.Auto (DimAutoStyle.Content, maximumContentDim: Dim.Percent (20)), }; charMap.Accept += (s, e) => diff --git a/UICatalog/Scenarios/Scrolling.cs b/UICatalog/Scenarios/Scrolling.cs index 5ab9461ca..50434772f 100644 --- a/UICatalog/Scenarios/Scrolling.cs +++ b/UICatalog/Scenarios/Scrolling.cs @@ -45,7 +45,7 @@ public class Scrolling : Scenario ShowHorizontalScrollIndicator = true }; // BUGBUG: set_ContentSize is supposed to be `protected`. - scrollView.ContentSize = new (120, 40); + scrollView.SetContentSize (new (120, 40)); scrollView.Padding.Thickness = new (1); label.Text = $"{scrollView}\nContentSize: {scrollView.ContentSize}\nContentOffset: {scrollView.ContentOffset}";