scrolling.md 5.9 KB

Scrolling

Terminal.Gui provides a rich system for how View users can scroll content with the keyboard and/or mouse.

Lexicon & Taxonomy

See View Deep Dive for broader definitions.

  • Scroll (Verb) - The act of causing content to move either horizontally or vertically within the View.Viewport. Also referred to as "Content Scrolling".
  • Scroll (Noun) - Indicates the size of scrollable content and provides a visible element, referred to as the "ScrollSlider" that that is sized to show the proportion of the scrollable content to the size of the View.Viewport and can be dragged with the mouse. A Scroll can be oriented either vertically or horizontally and is used within a ScrollBar.
  • ScrollSlider - The visual indicator that shows the proportion of the scrollable content to the size of the View.Viewport and allows the user to use the mouse to scroll. The Scroll Slider is not exposed publicly.
  • ScrollBar - Provides a visual indicator that content can be scrolled. ScrollBars consist of two buttons, one each for scrolling forward or backwards, a Scroll that can be clicked to scroll large amounts, and a ScrollSlider that can be dragged to scroll continuously. ScrollBars can be oriented either horizontally or vertically and support the user dragging and clicking with the mouse to scroll.

Overview

The ability to scroll content is built into View. The View.Viewport represents the scrollable "viewport" into the View's Content Area (which is defined by the return value of View.GetContentSize()).

By default, View, includes no bindings for the typical directional keyboard and mouse input and cause the Content Area.

Terminal.Gui also provides the ability show a visual scroll bar that responds to mouse input. This ability is not enabled by default given how precious TUI screen real estate is.

Scrolling with the mouse and keyboard are enabled by:

1) Making the View.Viewport size smaller than the size returned by View.GetContentSize(). 2) Creating key bindings for the appropriate directional keys (e.g. Key.CursorDown), and calling View.ScrollHorizontal()/ScrollVertical() as needed. 3) Subscribing to View.MouseEvent and calling calling View.ScrollHorizontal()/ScrollVertical() as needed. 4) Enabling the ScrollBars built into View (View.HorizontalScrollBar/VerticalScrollBar) by setting the flag ViewportSettings.EnableScrollBars on View.ViewportSettings.

Viewport Settings

Use View.ViewportSettings to adjust the behavior of scrolling.

  • AllowNegativeX/Y - If set, Viewport.Size can be set to negative coordinates enabling scrolling beyond the top-left of the content area.

  • AllowX/YGreaterThanContentWidth - If set, Viewport.Size can be set values greater than GetContentSize() enabling scrolling beyond the bottom-right of the Content Area. When not set, Viewport.X/Y are constrained to the dimension of the content area - 1. This means the last column of the content will remain visible even if there is an attempt to scroll the Viewport past the last column. The practical effect of this is that the last column/row of the content will always be visible.

  • ClipContentOnly - By default, clipping is applied to Viewport. Setting this flag will cause clipping to be applied to the visible content area.

  • ClearContentOnly - If set View.Clear() will clear only the portion of the content area that is visible within the Viewport. This is useful for views that have a content area larger than the Viewport and want the area outside the content to be visually distinct.

  • EnableHorizontal/VerticalScrollBar - If set, the scroll bar will be enabled and automatically made visible when the corresponding dimension of View.Viewport is smaller than the dimension of View.GetContentSize().

ScrollBar

Provides a visual indicator that content can be scrolled. ScrollBars consist of two buttons, one each for scrolling forward or backwards, a Scroll that can be clicked to scroll large amounts, and a ScrollSlider that can be dragged to scroll continuously. ScrollBars can be oriented either horizontally or vertically and support the user dragging and clicking with the mouse to scroll.

While the Scroll ScrollBar Views can be used in a standalone manner to provide proportional scrolling, they are typically enabled automatically via the View.HorizontalScrollBar and View.VerticalScrollBar properties.