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
View
Implements
System.Collections.IEnumerable
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
Assembly: Terminal.Gui.dll
Syntax
public class View : Responder, IEnumerable
Constructors
View()
Initializes a new instance of the
View class and sets the
view up for Computed layout, which will use the values in X, Y, Width and Height to
compute the View's Frame.
Declaration
View(Rect)
Initializes a new instance of the
View class with the absolute
dimensions specified in the frame. If you want to have Views that can be positioned with
Pos and Dim properties on X, Y, Width and Height, use the empty constructor.
Declaration
Parameters
Type |
Name |
Description |
Rect |
frame |
The region covered by this view. |
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 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 ColorScheme ColorScheme { get; set; }
Property Value
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 ConsoleDriver Driver { get; }
Property Value
Focused
Returns the currently focused view inside this view, or null if nothing is focused.
Declaration
public View Focused { get; }
Property Value
Type |
Description |
View |
The focused. |
Frame
Gets or sets the frame for the view.
Declaration
public virtual Rect Frame { get; set; }
Property Value
Type |
Description |
Rect |
The frame. |
HasFocus
Declaration
public override bool HasFocus { get; }
Property Value
Type |
Description |
System.Boolean |
|
Overrides
Height
Gets or sets the height for the view. This is only used when the LayoutStyle is Computed, if the
LayoutStyle is set to Absolute, this value is ignored.
Declaration
public Dim Height { get; set; }
Property Value
Type |
Description |
Dim |
The height. |
Id
Gets or sets an identifier for the view;
Declaration
public ustring Id { get; set; }
Property Value
Type |
Description |
NStack.ustring |
The identifier. |
IsCurrentTop
Returns a value indicating if this View is currently on Top (Active)
Declaration
public bool IsCurrentTop { get; }
Property Value
Type |
Description |
System.Boolean |
|
LayoutStyle
Controls how the view's Frame is computed during the LayoutSubviews method, if Absolute, then
LayoutSubviews does not change the Frame properties, otherwise the Frame is updated from the
values in X, Y, Width and Height properties.
Declaration
public LayoutStyle LayoutStyle { get; set; }
Property Value
MostFocused
Returns the most focused view in the chain of subviews (the leaf view that has the focus).
Declaration
public 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 IList<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 View SuperView { get; }
Property Value
Type |
Description |
View |
The super view. |
Gets or sets a value indicating whether this
View want continuous button pressed event.
Declaration
public virtual bool WantContinuousButtonPressed { get; set; }
Property Value
Type |
Description |
System.Boolean |
|
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 . |
Width
Gets or sets the width for the view. This is only used when the LayoutStyle is Computed, if the
LayoutStyle is set to Absolute, this value is ignored.
Declaration
public Dim Width { get; set; }
Property Value
Type |
Description |
Dim |
The width. |
X
Gets or sets the X position for the view (the column). This is only used when the LayoutStyle is Computed, if the
LayoutStyle is set to Absolute, this value is ignored.
Declaration
public Pos X { get; set; }
Property Value
Type |
Description |
Pos |
The X Position. |
Y
Gets or sets the Y position for the view (line). This is only used when the LayoutStyle is Computed, if the
LayoutStyle is set to Absolute, this value is ignored.
Declaration
public Pos Y { get; set; }
Property Value
Type |
Description |
Pos |
The y position (line). |
Methods
Add(View)
Adds a subview to this view.
Declaration
public virtual void Add(View view)
Parameters
Type |
Name |
Description |
View |
view |
|
Add(View[])
Adds the specified views to the view.
Declaration
public void Add(params View[] views)
Parameters
Type |
Name |
Description |
View[] |
views |
Array of one or more views (can be optional parameter). |
AddRune(Int32, Int32, Rune)
Displays the specified character in the specified column and row.
Declaration
public void AddRune(int col, int row, Rune ch)
Parameters
Type |
Name |
Description |
System.Int32 |
col |
Col. |
System.Int32 |
row |
Row. |
System.Rune |
ch |
Ch. |
BringSubviewForward(View)
Moves the subview backwards in the hierarchy, only one step
Declaration
public void BringSubviewForward(View subview)
Parameters
Type |
Name |
Description |
View |
subview |
The subview to send backwards |
BringSubviewToFront(View)
Brings the specified subview to the front so it is drawn on top of any other views.
Declaration
public void BringSubviewToFront(View subview)
Parameters
Type |
Name |
Description |
View |
subview |
The subview to send to the front |
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
Clear(Rect)
Clears the specified rectangular region with the current color
Declaration
public void Clear(Rect r)
Parameters
Type |
Name |
Description |
Rect |
r |
|
ClearNeedsDisplay()
Removes the SetNeedsDisplay and the ChildNeedsDisplay setting on this view.
Declaration
protected void ClearNeedsDisplay()
ClipToBounds()
Sets the Console driver's clip region to the current View's Bounds.
Declaration
public Rect ClipToBounds()
Returns
Type |
Description |
Rect |
The existing driver's Clip region, which can be then set by setting the Driver.Clip property. |
DrawFrame(Rect, Int32, Boolean)
Draws a frame in the current view, clipped by the boundary of this view
Declaration
public void DrawFrame(Rect rect, int padding = 0, bool fill = false)
Parameters
Type |
Name |
Description |
Rect |
rect |
Rectangular region for the frame to be drawn. |
System.Int32 |
padding |
The padding to add to the drawn frame. |
System.Boolean |
fill |
If set to true it fill will the contents. |
DrawHotString(ustring, Boolean, ColorScheme)
Utility function to draw strings that contains a hotkey using a colorscheme and the "focused" state.
Declaration
public void DrawHotString(ustring text, bool focused, ColorScheme scheme)
Parameters
Type |
Name |
Description |
NStack.ustring |
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(ustring, Attribute, Attribute)
Utility function to draw strings that contain a hotkey
Declaration
public void DrawHotString(ustring text, Attribute hotColor, Attribute normalColor)
Parameters
Type |
Name |
Description |
NStack.ustring |
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
FocusLast()
Focuses the last focusable subview if one exists.
Declaration
FocusNext()
Focuses the next view.
Declaration
Returns
Type |
Description |
System.Boolean |
true , if next was focused, false otherwise. |
FocusPrev()
Focuses the previous view.
Declaration
Returns
Type |
Description |
System.Boolean |
true , if previous was focused, false otherwise. |
GetEnumerator()
Gets an enumerator that enumerates the subviews in this view.
Declaration
public 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. |
OnEnter()
Declaration
public override bool OnEnter()
Returns
Type |
Description |
System.Boolean |
|
Overrides
OnKeyDown(KeyEvent)
Declaration
public override bool OnKeyDown(KeyEvent keyEvent)
Parameters
Type |
Name |
Description |
KeyEvent |
keyEvent |
Contains the details about the key that produced the event. |
Returns
Type |
Description |
System.Boolean |
|
Overrides
OnKeyUp(KeyEvent)
Declaration
public override bool OnKeyUp(KeyEvent keyEvent)
Parameters
Type |
Name |
Description |
KeyEvent |
keyEvent |
Contains the details about the key that produced the event. |
Returns
Type |
Description |
System.Boolean |
|
Overrides
OnLeave()
Declaration
public override bool OnLeave()
Returns
Type |
Description |
System.Boolean |
|
Overrides
OnMouseEnter(MouseEvent)
Declaration
public override bool OnMouseEnter(MouseEvent mouseEvent)
Parameters
Returns
Type |
Description |
System.Boolean |
|
Overrides
OnMouseLeave(MouseEvent)
Declaration
public override bool OnMouseLeave(MouseEvent mouseEvent)
Parameters
Returns
Type |
Description |
System.Boolean |
|
Overrides
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(KeyEvent keyEvent)
Parameters
Returns
Type |
Description |
System.Boolean |
|
Overrides
ProcessHotKey(KeyEvent)
Declaration
public override bool ProcessHotKey(KeyEvent keyEvent)
Parameters
Returns
Type |
Description |
System.Boolean |
|
Overrides
ProcessKey(KeyEvent)
Declaration
public override bool ProcessKey(KeyEvent keyEvent)
Parameters
Returns
Type |
Description |
System.Boolean |
|
Overrides
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(Rect region)
Parameters
Type |
Name |
Description |
Rect |
region |
The region to redraw, this is relative to the view itself. |
Remove(View)
Removes a widget from this container.
Declaration
public virtual void Remove(View view)
Parameters
Type |
Name |
Description |
View |
view |
|
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 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. |
SendSubviewBackwards(View)
Moves the subview backwards in the hierarchy, only one step
Declaration
public void SendSubviewBackwards(View subview)
Parameters
Type |
Name |
Description |
View |
subview |
The subview to send backwards |
SendSubviewToBack(View)
Sends the specified subview to the front so it is the first view drawn
Declaration
public void SendSubviewToBack(View subview)
Parameters
Type |
Name |
Description |
View |
subview |
The subview to send to the front |
SetClip(Rect)
Sets the clipping region to the specified region, the region is view-relative
Declaration
public Rect SetClip(Rect rect)
Parameters
Type |
Name |
Description |
Rect |
rect |
Rectangle region to clip into, the region is view-relative. |
Returns
Type |
Description |
Rect |
The previous clip region. |
SetFocus(View)
Focuses the specified sub-view.
Declaration
public void SetFocus(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(Rect region)
Parameters
Type |
Name |
Description |
Rect |
region |
The region that must be flagged for repaint. |
ToString()
Declaration
public override string ToString()
Returns
Type |
Description |
System.String |
|
Overrides
System.Object.ToString()
Events
Enter
Event fired when the view get focus.
Declaration
public event EventHandler Enter
Event Type
Type |
Description |
System.EventHandler |
|
KeyDown
Invoked when a key is pressed
Declaration
public event EventHandler<View.KeyEventEventArgs> KeyDown
Event Type
KeyPress
Invoked when a character key is pressed and occurs after the key up event.
Declaration
public event EventHandler<View.KeyEventEventArgs> KeyPress
Event Type
KeyUp
Invoked when a key is released
Declaration
public event EventHandler<View.KeyEventEventArgs> KeyUp
Event Type
Leave
Event fired when the view lost focus.
Declaration
public event EventHandler Leave
Event Type
Type |
Description |
System.EventHandler |
|
MouseEnter
Event fired when the view receives the mouse event for the first time.
Declaration
public event EventHandler<MouseEvent> MouseEnter
Event Type
MouseLeave
Event fired when the view loses mouse event for the last time.
Declaration
public event EventHandler<MouseEvent> MouseLeave
Event Type
Implements
System.Collections.IEnumerable