using System; using System.Collections.Generic; using System.Linq; using Terminal.Gui; namespace UICatalog.Scenarios; [ScenarioMetadata ("Content Scrolling", "Demonstrates using View.Viewport and View.GetContentSize () to scroll content.")] [ScenarioCategory ("Layout")] [ScenarioCategory ("Drawing")] [ScenarioCategory ("Scrolling")] public class ContentScrolling : Scenario { private ViewDiagnosticFlags _diagnosticFlags; public class ScrollingDemoView : FrameView { public ScrollingDemoView () { Width = Dim.Fill (); Height = Dim.Fill (); ColorScheme = Colors.ColorSchemes ["Base"]; Text = "Text (ScrollingDemoView.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; SetContentSize (new (60, 40)); ViewportSettings |= ViewportSettings.ClearContentOnly; ViewportSettings |= ViewportSettings.ClipContentOnly; // Things this view knows how to do AddCommand (Command.ScrollDown, () => ScrollVertical (1)); AddCommand (Command.ScrollUp, () => ScrollVertical (-1)); AddCommand (Command.ScrollRight, () => ScrollHorizontal (1)); AddCommand (Command.ScrollLeft, () => ScrollHorizontal (-1)); // 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); // Add a status label to the border that shows Viewport and ContentSize values. Bit of a hack. // TODO: Move to Padding with controls Border.Add (new Label { X = 20 }); LayoutComplete += VirtualDemoView_LayoutComplete; MouseEvent += VirtualDemoView_MouseEvent; } private void VirtualDemoView_MouseEvent (object sender, MouseEventEventArgs e) { if (e.MouseEvent.Flags == MouseFlags.WheeledDown) { ScrollVertical (1); return; } if (e.MouseEvent.Flags == MouseFlags.WheeledUp) { ScrollVertical (-1); return; } if (e.MouseEvent.Flags == MouseFlags.WheeledRight) { ScrollHorizontal (1); return; } if (e.MouseEvent.Flags == MouseFlags.WheeledLeft) { ScrollHorizontal (-1); } } private void VirtualDemoView_LayoutComplete (object sender, LayoutEventArgs e) { Label status = Border.Subviews.OfType