using System; using System.Collections.Generic; using System.Linq; namespace UICatalog.Scenarios; [ScenarioMetadata ("ViewportSettings", "Demonstrates manipulating Viewport, ViewportSettings, and ContentSize to scroll content.")] [ScenarioCategory ("Layout")] [ScenarioCategory ("Drawing")] [ScenarioCategory ("Scrolling")] [ScenarioCategory ("Adornments")] public class ViewportSettings : Scenario { public class ViewportSettingsDemoView : FrameView { public ViewportSettingsDemoView () { Id = "ViewportSettingsDemoView"; Width = Dim.Fill (); Height = Dim.Fill (); SchemeName = "base"; base.Text = "Text (ViewportSettingsDemoView.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.Resizable; SetContentSize (new (60, 40)); ViewportSettings |= Terminal.Gui.ViewBase.ViewportSettingsFlags.ClearContentOnly; ViewportSettings |= Terminal.Gui.ViewBase.ViewportSettingsFlags.ClipContentOnly; VerticalScrollBar.Visible = true; // 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 }); ViewportChanged += VirtualDemoView_LayoutComplete; MouseEvent += VirtualDemoView_MouseEvent; } private void VirtualDemoView_MouseEvent (object sender, MouseEventArgs e) { if (e.Flags == MouseFlags.WheeledDown) { ScrollVertical (1); return; } if (e.Flags == MouseFlags.WheeledUp) { ScrollVertical (-1); return; } if (e.Flags == MouseFlags.WheeledRight) { ScrollHorizontal (1); return; } if (e.Flags == MouseFlags.WheeledLeft) { ScrollHorizontal (-1); } } private void VirtualDemoView_LayoutComplete (object sender, DrawEventArgs drawEventArgs) { Label frameLabel = Padding?.SubViews.OfType