| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- #nullable enable
- using System.Diagnostics;
- namespace UICatalog.Scenarios;
- [ScenarioMetadata ("Scrolling", "Content scrolling, IScrollBars, etc...")]
- [ScenarioCategory ("Controls")]
- [ScenarioCategory ("Scrolling")]
- [ScenarioCategory ("Tests")]
- public class Scrolling : Scenario
- {
- private object? _progressTimer = null;
- public override void Main ()
- {
- Application.Init ();
- var win = new Window
- {
- Title = GetQuitKeyAndName ()
- };
- var label = new Label { X = 0, Y = 0 };
- win.Add (label);
- var demoView = new AllViewsView
- {
- Id = "demoView",
- X = 2,
- Y = Pos.Bottom (label) + 1,
- Width = Dim.Fill (4),
- Height = Dim.Fill (4)
- };
- label.Text =
- $"{demoView}\nContentSize: {demoView.GetContentSize ()}\nViewport.Location: {demoView.Viewport.Location}";
- demoView.ViewportChanged += (_, _) =>
- {
- label.Text =
- $"{demoView}\nContentSize: {demoView.GetContentSize ()}\nViewport.Location: {demoView.Viewport.Location}";
- };
- win.Add (demoView);
- var hCheckBox = new CheckBox
- {
- X = Pos.X (demoView),
- Y = Pos.Bottom (demoView),
- Text = "_HorizontalScrollBar.Visible",
- CheckedState = demoView.HorizontalScrollBar.Visible ? CheckState.Checked : CheckState.UnChecked
- };
- win.Add (hCheckBox);
- hCheckBox.CheckedStateChanged += (sender, args) => { demoView.HorizontalScrollBar.Visible = args.Value == CheckState.Checked; };
- var vCheckBox = new CheckBox
- {
- X = Pos.Right (hCheckBox) + 3,
- Y = Pos.Bottom (demoView),
- Text = "_VerticalScrollBar.Visible",
- CheckedState = demoView.VerticalScrollBar.Visible ? CheckState.Checked : CheckState.UnChecked
- };
- win.Add (vCheckBox);
- vCheckBox.CheckedStateChanged += (sender, args) => { demoView.VerticalScrollBar.Visible = args.Value == CheckState.Checked; };
- var ahCheckBox = new CheckBox
- {
- X = Pos.Left (demoView),
- Y = Pos.Bottom (hCheckBox),
- Text = "_AutoShow (both)",
- CheckedState = demoView.HorizontalScrollBar.AutoShow ? CheckState.Checked : CheckState.UnChecked
- };
- ahCheckBox.CheckedStateChanging += (s, e) =>
- {
- demoView.HorizontalScrollBar.AutoShow = e.Result == CheckState.Checked;
- demoView.VerticalScrollBar.AutoShow = e.Result == CheckState.Checked;
- };
- win.Add (ahCheckBox);
- demoView.VerticalScrollBar.VisibleChanging += (sender, args) => { vCheckBox.CheckedState = args.NewValue ? CheckState.Checked : CheckState.UnChecked; };
- demoView.HorizontalScrollBar.VisibleChanging += (sender, args) =>
- {
- hCheckBox.CheckedState = args.NewValue ? CheckState.Checked : CheckState.UnChecked;
- };
- // Add a progress bar to cause constant redraws
- var progress = new ProgressBar
- {
- X = Pos.Center (), Y = Pos.AnchorEnd (), Width = Dim.Fill ()
- };
- win.Add (progress);
- win.Initialized += WinOnInitialized;
- win.IsRunningChanged += WinIsRunningChanged;
- Application.Run (win);
- win.IsRunningChanged -= WinIsRunningChanged;
- win.Dispose ();
- Application.Shutdown ();
- return;
- void WinOnInitialized (object? sender, EventArgs e)
- {
- bool TimerFn ()
- {
- progress.Pulse ();
- return _progressTimer is { };
- }
- _progressTimer = Application.AddTimeout (TimeSpan.FromMilliseconds (200), TimerFn);
- }
- void WinIsRunningChanged (object? sender, EventArgs<bool> args)
- {
- if (!args.Value && _progressTimer is { })
- {
- Application.RemoveTimeout (_progressTimer);
- _progressTimer = null;
- }
- }
- }
- }
|