Table of Contents

Namespace Terminal.Gui.ViewBase

The ViewBase namespace contains the foundational view system and core UI building blocks.

View provides the fundamental view architecture that forms the foundation of all Terminal.Gui user interface elements. This namespace contains the base View class, adornment system, layout primitives, and core view behaviors that enable the rich UI capabilities of Terminal.Gui.

The View system implements the complete view lifecycle, coordinate systems, event handling, focus management, and the innovative adornment system that separates content from visual decoration.

Key Components

  • View - Base class for all UI elements with complete lifecycle management
  • Adornment - Visual decorations (Margin, Border, Padding) outside content area
  • Viewport - Scrollable window into view content with built-in scrolling support
  • ViewArrangement - Flags controlling user interaction (Movable, Resizable, etc.)
  • Pos and Dim - Flexible positioning and sizing system with relative and absolute options

View Architecture

  • Hierarchy: SuperView/SubView relationships with automatic lifecycle management
  • Coordinate Systems: Multiple coordinate spaces (Frame, Viewport, Content, Screen)
  • Layout Engine: Automatic positioning and sizing with constraint-based layout
  • Event System: Comprehensive event handling with cancellation support
  • Focus Management: Built-in keyboard navigation and focus chain management

Example Usage

// Create a view with a Border adornment and Title
var view = new View()
{
    X = Pos.Center(),
    Y = Pos.Center(),
    Width = Dim.Percent(50),
    Height = Dim.Percent(30),
    Title = "My View",
    BorderStyle = LineStyle.Rounded
};

// Enable user arrangement
view.Arrangement = ViewArrangement.Movable | ViewArrangement.Resizable;

// Add to SuperView 
superView.Add(view);

See Also

Classes

AddOrSubtractExtensions

Extension methods for the AddOrSubtract enum type.

Adornment

Adornments are a special form of View that appear outside the Viewport: Margin, Border, and Padding. They are defined using the Thickness class, which specifies the thickness of the sides of a rectangle.

AdvanceFocusEventArgs

The event arguments for AdvanceFocus(NavigationDirection, TabBehavior?) events.

Aligner

Aligns items within a container based on the specified Alignment. Both horizontal and vertical alignments are supported.

AlignmentExtensions

Extension methods for the Alignment enum type.

AlignmentModesExtensions

Extension methods for the AlignmentModes enum type.

Border

The Border for a View. Accessed via Border

BorderSettingsExtensions

Extension methods for the BorderSettings enum type.

Dim

A Dim object describes the dimensions of a View. Dim is the type of the Width and Height properties of View.

Integer values are implicitly convertible to an absolute Dim. These objects are created using the static methods described below. The Dim objects can be combined with the addition and subtraction operators.

DimAbsolute

Represents a dimension that is a fixed size.

DimAuto

Represents a dimension that automatically sizes the view to fit all the view's Content, SubViews, and/or Text.

DimAutoStyleExtensions

Extension methods for the DimAutoStyle enum type.

DimCombine

Represents a dimension that is a combination of two other dimensions.

DimFill

Represents a dimension that fills the dimension, leaving the specified margin.

DimFunc

Represents a function Dim object that computes the dimension by executing the provided function.

DimPercent

Represents a dimension that is a percentage of the width or height of the SuperView.

DimPercentModeExtensions

Extension methods for the DimPercentMode enum type.

DimView

Represents a dimension that tracks the Height or Width of the specified View.

DimensionExtensions

Extension methods for the Dimension enum type.

DrawAdornmentsEventArgs

Provides data for events that allow cancellation of adornment drawing in the Cancellable Work Pattern (CWP).

DrawContext

Tracks the region that has been drawn during Draw(DrawContext?). This is primarily in support of Transparent.

DrawEventArgs

Event args for draw events

HasFocusEventArgs

The event arguments for HasFocus events.

LayoutEventArgs

Event arguments for the SubViewsLaidOut event.

LayoutException

Represents an exception that is thrown when a layout operation fails.

Margin

The Margin for a View. Accessed via Margin

OrientationHelper

Helper class for implementing IOrientation.

Padding

The Padding for a View. Accessed via Padding

Pos

Describes the position of a View which can be an absolute value, a percentage, centered, or relative to the ending dimension. Integer values are implicitly convertible to an absolute Pos. These objects are created using the static methods Percent, AnchorEnd, and Center. The Pos objects can be combined with the addition and subtraction operators.

PosAbsolute

Represents an absolute position in the layout. This is used to specify a fixed position in the layout.

PosAlign

Enables alignment of a set of views.

PosAnchorEnd

Represents a position anchored to the end (right side or bottom).

PosCenter

Represents a position that is centered.

PosCombine

Represents a position that is a combination of two other positions.

PosFunc

Represents a position that is computed by executing a function that returns an integer position.

PosPercent

Represents a position that is a percentage of the width or height of the SuperView.

PosView

Represents a position that is anchored to the side of another view.

SideExtensions

Extension methods for the Side enum type.

SizeChangedEventArgs

Args for events about Size (e.g. Resized)

StackExtensions

Extension of Stack<T> helper to work with specific IEqualityComparer<T>

SuperViewChangedEventArgs

Args for events where the SuperView of a View is changed (e.g. Removed).

View

View is the base class all visible elements. View can render itself and contains zero or more nested views, called SubViews. View provides basic functionality for layout, arrangement, and drawing. In addition, View provides keyboard and mouse event handling.

See the View Deep Dive for more.

ViewDiagnosticFlagsExtensions

Extension methods for the ViewDiagnosticFlags enum type.

ViewEventArgs

Args for events that relate to specific View

Interfaces

IDesignable

Interface declaring common functionality useful for designer implementations.

IOrientation

Implement this interface to provide orientation support.

Enums

AddOrSubtract

Describes whether an operation should add or subtract values.

Alignment

Determines the position of items when arranged in a container.

AlignmentModes

Determines alignment modes for Alignment.

BorderSettings

Determines the settings for Border.

DimAutoStyle

Specifies how Auto(DimAutoStyle, Dim?, Dim?) will compute the dimension.

DimPercentMode

Indicates the mode for a DimPercent object.

Dimension

Indicates the dimension for Dim operations.

MouseState

Used to describe the state of the mouse in relation to a View (MouseState) and to specify visual effects, such as highlighting a button when the mouse is over it or changing the appearance of a view when the mouse is pressed (HighlightStates).

NavigationDirection

Indicates navigation direction.

Orientation

Direction of an element (horizontal or vertical)

ShadowStyle

Defines the style of shadow to be drawn on the right and bottom sides of the View.

Side

Indicates the side for Pos operations.

TabBehavior

Describes how TabStop behaves. A TabStop is a stop-point for keyboard navigation between Views.

ViewArrangement

Describes what user actions are enabled for arranging a View within it's SuperView . See Arrangement.

ViewDiagnosticFlags

Enables diagnostic functions for View.

ViewportSettingsFlags

Settings for how the Viewport behaves.

Delegates

View.CommandImplementation

Function signature commands.