using System; namespace Terminal.Gui { /// /// /// /// /// /// The subviews that are added to this scrollview are offset by the /// ContentOffset property. The view itself is a window into the /// space represented by the ContentSize. /// /// /// /// /// public class ScrollView : View { View contentView; public ScrollView (Rect frame) : base (frame) { contentView = new View (frame); base.Add (contentView); } Size contentSize; Point contentOffset; bool showHorizontalScrollIndicator; bool showVerticalScrollIndicator; /// /// Represents the contents of the data shown inside the scrolview /// /// The size of the content. public Size ContentSize { get { return contentSize; } set { contentSize = value; contentView.Frame = new Rect (contentOffset, value); } } /// /// Represents the top left corner coordinate that is displayed by the scrollview /// /// The content offset. public Point ContentOffset { get { return contentOffset; } set { contentOffset = new Point (-value.X, -value.Y); contentView.Frame = new Rect (contentOffset, contentSize); } } /// /// Adds the view to the scrollview. /// /// The view to add to the scrollview. public override void Add (View view) { contentView.Add (view); } /// /// Gets or sets the visibility for the horizontal scroll indicator. /// /// true if show vertical scroll indicator; otherwise, false. public bool ShowHorizontalScrollIndicator { get => showHorizontalScrollIndicator; set { showHorizontalScrollIndicator = value; SetNeedsDisplay (); } } /// /// /// Gets or sets the visibility for the vertical scroll indicator. /// /// true if show vertical scroll indicator; otherwise, false. public bool ShowVerticalScrollIndicator { get => showVerticalScrollIndicator; set { showVerticalScrollIndicator = value; SetNeedsDisplay (); } } /// /// This event is raised when the contents have scrolled /// public event Action Scrolled; public override void Redraw(Rect region) { var oldClip = ClipToBounds (); base.Redraw(region); Driver.SetAttribute (ColorScheme.Normal); DrawFrame (Bounds); Driver.Clip = oldClip; } } }