Show / Hide Table of Contents

# Class View

View is the base class for all views on the screen and represents a visible element that can render itself and contains zero or more nested views.

##### Inheritance

System.Object
Responder
View
Button
CheckBox
Label
MenuBar
RadioGroup
ScrollView
TextField
Toplevel

##### Inherited Members

Responder.CanFocus
Responder.MouseEvent(MouseEvent)

###### Namespace: Terminal

###### Assembly: Terminal.dll

##### Syntax

    public class View : Terminal.Responder, System.Collections.IEnumerable

##### Remarks

The View defines the base functionality for user interface elements in Terminal/gui.cs. Views can contain one or more subviews, can respond to user input and render themselves on the screen.

Views are created with a specified rectangle region (the frame) that is relative to the container that they are added into.

Subviews can be added to a View by calling the Add method. The container of a view is the Superview.

Developers can call the SetNeedsDisplay method on the view to flag a region or the entire view as requiring to be redrawn.

Views have a ColorScheme property that defines the default colors that subviews should use for rendering. This ensures that the views fit in the context where they are being used, and allows for themes to be plugged in. For example, the default colors for windows and toplevels uses a blue background, while it uses a white background for dialog boxes and a red background for errors.

If a ColorScheme is not set on a view, the result of the ColorScheme is the value of the SuperView and the value might only be valid once a view has been added to a SuperView, so your subclasses should not rely on ColorScheme being set at construction time.

Using ColorSchemes has the advantage that your application will work both in color as well as black and white displays.

### Constructors

#### View(Rect)

Initializes a new instance of the View class with the specified frame. This is the default constructor.

##### Declaration

    public View (Terminal.Rect frame);

##### Parameters

Type | Name | Description
--- | --- | ---
Rect | frame | The region covered by this view.

### Fields

#### Driver

Points to the current driver in use by the view, it is a convenience property for simplifying the development of new views.

##### Declaration

    public static Terminal.ConsoleDriver Driver;

##### Field Value

Type | Description
--- | ---
ConsoleDriver | To be added.

### Properties

#### Bounds

The bounds represent the View-relative rectangle used for this view. Updates to the Bounds update the Frame, and has the same side effects as updating the frame.

##### Declaration

    public Terminal.Rect Bounds { get; set; }

##### Property Value

Type | Description
--- | ---
Rect | The bounds.

#### ColorScheme

The color scheme for this view, if it is not defined, it returns the parent's color scheme.

##### Declaration

    public Terminal.ColorScheme ColorScheme { get; set; }

##### Property Value

Type | Description
--- | ---
ColorScheme | To be added.

#### Focused

Returns the currently focused view inside this view, or null if nothing is focused.

##### Declaration

    public Terminal.View Focused { get; }

##### Property Value

Type | Description
--- | ---
View | The focused.

#### Frame

Gets or sets the frame for the view.

##### Declaration

    public Terminal.Rect Frame { get; set; }

##### Property Value

Type | Description
--- | ---
Rect | The frame.

##### Remarks

Altering the Frame of a view will trigger the redrawing of the view as well as the redrawing of the affected regions in the superview.

#### HasFocus

Gets or sets a value indicating whether this View has focus.

##### Declaration

    public override bool HasFocus { get; }

##### Property Value

Type | Description
--- | ---
System.Boolean | `true` if has focus; otherwise, `false`.

#### Id

Gets or sets an identifier for the view;

##### Declaration

    public string Id { get; set; }

##### Property Value

Type | Description
--- | ---
System.String | The identifier.

#### MostFocused

Returns the most focused view in the chain of subviews (the leaf view that has the focus).

##### Declaration

    public Terminal.View MostFocused { get; }

##### Property Value

Type | Description
--- | ---
View | The most focused.

#### Subviews

This returns a list of the subviews contained by this view.

##### Declaration

    public System.Collections.Generic.IList<Terminal.View> Subviews { get; }

##### Property Value

Type | Description
--- | ---
System.Collections.Generic.IList<View> | The subviews.

#### SuperView

Returns the container for this view, or null if this view has not been added to a container.

##### Declaration

    public Terminal.View SuperView { get; }

##### Property Value

Type | Description
--- | ---
View | The super view.

#### WantMousePositionReports

Gets or sets a value indicating whether this View want mouse position reports.

##### Declaration

    public virtual bool WantMousePositionReports { get; set; }

##### Property Value

Type | Description
--- | ---
System.Boolean | `true` if want mouse position reports; otherwise, `false`.

### Methods

#### Add(View)

Adds a subview to this view.

##### Declaration

    public virtual void Add (Terminal.View view);

##### Parameters

Type | Name | Description
--- | --- | ---
View | view | To be added.

#### Add(View[])

Adds the specified views to the view.

##### Declaration

    public void Add (Terminal.View[] views);

##### Parameters

Type | Name | Description
--- | --- | ---
View[] | views | Array of one or more views (can be optional parameter).

#### AddCh(Int32, Int32, Int32)

Displays the specified character in the specified column and row.

##### Declaration

    public void AddCh (int col, int row, int ch);

##### Parameters

Type | Name | Description
--- | --- | ---
System.Int32 | col | Col.
System.Int32 | row | Row.
System.Int32 | ch | Ch.

#### ChildNeedsDisplay()

Flags this view for requiring the children views to be repainted.

##### Declaration

    public void ChildNeedsDisplay ();

#### Clear()

Clears the view region with the current color.

##### Declaration

    public void Clear ();

##### Remarks

This clears the entire region used by this view.

#### ClearNeedsDisplay()

Removes the SetNeedsDisplay and the ChildNeedsDisplay setting on this view.

##### Declaration

    protected void ClearNeedsDisplay ();

#### DrawFrame(Rect, Boolean)

Draws a frame in the current view, clipped by the boundary of this view

##### Declaration

    public void DrawFrame (Terminal.Rect rect, bool fill = false);

##### Parameters

Type | Name | Description
--- | --- | ---
Rect | rect | Rectangular region for the frame to be drawn.
System.Boolean | fill | If set to `true` it fill will the contents.

#### DrawHotString(String, Boolean, ColorScheme)

Utility function to draw strings that contains a hotkey using a colorscheme and the "focused" state.

##### Declaration

    public void DrawHotString (string text, bool focused, Terminal.ColorScheme scheme);

##### Parameters

Type | Name | Description
--- | --- | ---
System.String | text | String to display, the underscoore before a letter flags the next letter as the hotkey.
System.Boolean | focused | If set to `true` this uses the focused colors from the color scheme, otherwise the regular ones.
ColorScheme | scheme | The color scheme to use.

#### DrawHotString(String, Attribute, Attribute)

Utility function to draw strings that contain a hotkey

##### Declaration

    public void DrawHotString (string text, Terminal.Attribute hotColor, Terminal.Attribute normalColor);

##### Parameters

Type | Name | Description
--- | --- | ---
System.String | text | String to display, the underscoore before a letter flags the next letter as the hotkey.
Attribute | hotColor | Hot color.
Attribute | normalColor | Normal color.

#### EnsureFocus()

Finds the first view in the hierarchy that wants to get the focus if nothing is currently focused, otherwise, it does nothing.

##### Declaration

    public void EnsureFocus ();

#### FocusFirst()

Focuses the first focusable subview if one exists.

##### Declaration

    public void FocusFirst ();

#### FocusLast()

Focuses the last focusable subview if one exists.

##### Declaration

    public void FocusLast ();

#### FocusNext()

Focuses the next view.

##### Declaration

    public bool FocusNext ();

##### Returns

Type | Description
--- | ---
System.Boolean | `true`, if next was focused, `false` otherwise.

#### FocusPrev()

Focuses the previous view.

##### Declaration

    public bool FocusPrev ();

##### Returns

Type | Description
--- | ---
System.Boolean | `true`, if previous was focused, `false` otherwise.

#### GetEnumerator()

Gets an enumerator that enumerates the subviews in this view.

##### Declaration

    [System.Runtime.CompilerServices.IteratorStateMachine(typeof(Terminal.View/<GetEnumerator>d__23))]
    public System.Collections.IEnumerator GetEnumerator ();

##### Returns

Type | Description
--- | ---
System.Collections.IEnumerator | The enumerator.

#### LayoutSubviews()

This virtual method is invoked when a view starts executing or when the dimensions of the view have changed, for example in response to the container view or terminal resizing.

##### Declaration

    public virtual void LayoutSubviews ();

#### Move(Int32, Int32)

This moves the cursor to the specified column and row in the view.

##### Declaration

    public void Move (int col, int row);

##### Parameters

Type | Name | Description
--- | --- | ---
System.Int32 | col | Col.
System.Int32 | row | Row.

#### PositionCursor()

Positions the cursor in the right position based on the currently focused view in the chain.

##### Declaration

    public virtual void PositionCursor ();

#### ProcessColdKey(KeyEvent)

##### Declaration

    public override bool ProcessColdKey (Terminal.KeyEvent kb);

##### Parameters

Type | Name | Description
--- | --- | ---
KeyEvent | kb | To be added.

##### Returns

Type | Description
--- | ---
System.Boolean | To be added.

#### ProcessHotKey(KeyEvent)

##### Declaration

    public override bool ProcessHotKey (Terminal.KeyEvent kb);

##### Parameters

Type | Name | Description
--- | --- | ---
KeyEvent | kb | To be added.

##### Returns

Type | Description
--- | ---
System.Boolean | To be added.

#### ProcessKey(KeyEvent)

##### Declaration

    public override bool ProcessKey (Terminal.KeyEvent kb);

##### Parameters

Type | Name | Description
--- | --- | ---
KeyEvent | kb | To be added.

##### Returns

Type | Description
--- | ---
System.Boolean | To be added.

#### Redraw(Rect)

Performs a redraw of this view and its subviews, only redraws the views that have been flagged for a re-display.

##### Declaration

    public virtual void Redraw (Terminal.Rect region);

##### Parameters

Type | Name | Description
--- | --- | ---
Rect | region | To be added.

##### Remarks

The region argument is relative to the view itself.

#### Remove(View)

Removes a widget from this container.

##### Declaration

    public virtual void Remove (Terminal.View view);

##### Parameters

Type | Name | Description
--- | --- | ---
View | view | To be added.

#### RemoveAll()

Removes all the widgets from this container.

##### Declaration

    public virtual void RemoveAll ();

#### ScreenToView(Int32, Int32)

Converts a point from screen coordinates into the view coordinate space.

##### Declaration

    public Terminal.Point ScreenToView (int x, int y);

##### Parameters

Type | Name | Description
--- | --- | ---
System.Int32 | x | X screen-coordinate point.
System.Int32 | y | Y screen-coordinate point.

##### Returns

Type | Description
--- | ---
Point | The mapped point.

#### SetFocus(View)

Focuses the specified sub-view.

##### Declaration

    public void SetFocus (Terminal.View view);

##### Parameters

Type | Name | Description
--- | --- | ---
View | view | View.

#### SetNeedsDisplay()

Invoke to flag that this view needs to be redisplayed, by any code that alters the state of the view.

##### Declaration

    public void SetNeedsDisplay ();

#### SetNeedsDisplay(Rect)

Flags the specified rectangle region on this view as needing to be repainted.

##### Declaration

    public void SetNeedsDisplay (Terminal.Rect region);

##### Parameters

Type | Name | Description
--- | --- | ---
Rect | region | The region that must be flagged for repaint.

#### ToString()

Returns a System.String that represents the current View.

##### Declaration

    public override string ToString ();

##### Returns

Type | Description
--- | ---
System.String | A System.String that represents the current View.