Show / Hide Table of Contents

Class Viewport<T>

Implements IGridView<T> to expose a "viewport", or sub-area, of another grid view. Its indexers perform relative to absolute coordinate translations based on the viewport size/location, and return the proper value of type T from the underlying view.

Inheritance
Object
GridViewBase<T>
Viewport<T>
SettableViewport<T>
Implements
IGridView<T>
Inherited Members
GridViewBase<T>.Count
GridViewBase<T>.Item[Int32, Int32]
GridViewBase<T>.Item[Int32]
Namespace: SadRogue.Primitives.GridViews
Assembly: TheSadRogue.Primitives.dll
Syntax
public class Viewport<T> : GridViewBase<T>, IGridView<T>
Type Parameters
Name Description
T

The type being exposed by the Viewport.

Remarks

This implementation restricts the subsection of the view that is presented in such a way that no part of the viewport can be outside the boundary of its parent grid view. The viewport cannot be bigger than the underlying grid view, and the viewport's position is "locked" to the edge so that it cannot be set in such a way that a portion of the viewport lies outside the bounds of the parent view. If you would rather allow this and return a default value for locations outside the parent grid view, see UnboundedViewport<T>.

Constructors

Viewport(IGridView<T>)

Constructor. Takes the map view to represent. The viewport will represent the entire given map view.

Declaration
public Viewport(IGridView<T> gridView)
Parameters
Type Name Description
IGridView<T> gridView

The map view to represent.

Viewport(IGridView<T>, Rectangle)

Constructor. Takes the parent grid view, and the initial subsection of that grid view to represent.

Declaration
public Viewport(IGridView<T> gridView, Rectangle viewArea)
Parameters
Type Name Description
IGridView<T> gridView

The grid view being represented.

Rectangle viewArea

The initial subsection of that grid view to represent.

Properties

GridView

The grid view that this Viewport is exposing values from.

Declaration
public IGridView<T> GridView { get; }
Property Value
Type Description
IGridView<T>

Height

The height of the area being represented.

Declaration
public override int Height { get; }
Property Value
Type Description
Int32
Overrides
SadRogue.Primitives.GridViews.GridViewBase<T>.Height

Item[Point]

Given a position in relative coordinates, returns the "value" associated with that location in absolute coordinates.

Declaration
public override T this[Point relativePosition] { get; }
Parameters
Type Name Description
Point relativePosition

Viewport-relative position of the location to retrieve the value for.

Property Value
Type Description
T

The "value" associated with the absolute location represented on the underlying grid view.

Overrides
SadRogue.Primitives.GridViews.GridViewBase<T>.Item[SadRogue.Primitives.Point]

ViewArea

The area of GridView that this Viewport is exposing. Use SetViewArea(Rectangle) to set the viewing area.

Declaration
public ref readonly Rectangle ViewArea { get; }
Property Value
Type Description
Rectangle

Width

The width of the area being represented.

Declaration
public override int Width { get; }
Property Value
Type Description
Int32
Overrides
SadRogue.Primitives.GridViews.GridViewBase<T>.Width

Methods

SetViewArea(Rectangle)

Sets the viewing area for the viewport to the value given. The viewport will automatically be bounded as needed to ensure that it remains within the bounds of the underlying IGridView.

Declaration
public void SetViewArea(Rectangle viewArea)
Parameters
Type Name Description
Rectangle viewArea

The new view area.

ToString()

Returns a string representation of the grid values inside the viewport.

Declaration
public override string ToString()
Returns
Type Description
String

A string representation of the values inside the viewport.

ToString(Func<T, String>)

Returns a string representation of the grid values inside the viewport, using elementStringifier to determine what string represents each value.

Declaration
public string ToString(Func<T, string> elementStringifier)
Parameters
Type Name Description
Func<T, String> elementStringifier

Function determining the string representation of each element.

Returns
Type Description
String

A string representation of the grid values inside the viewport.

ToString(Int32, Func<T, String>)

Returns a string representation of the grid values inside the viewport, using the function specified to turn elements into strings, and using the "field length" specified.

Declaration
public string ToString(int fieldSize, Func<T, string> elementStringifier = null)
Parameters
Type Name Description
Int32 fieldSize

The size of the field to give each value. A positive-number right-aligns the text within the field, while a negative number left-aligns the text.

Func<T, String> elementStringifier

Function to use to convert each element to a string. null defaults to the ToString function of type T.

Returns
Type Description
String

A string representation of the grid values inside the viewport.

Remarks

Each element of type T will have spaces added to cause it to take up exactly fieldSize characters, provided fieldSize is less than the length of the element's string representation.

Implements

IGridView<T>

Extension Methods

PropertyChangedEventHelpers.SafelySetProperty<TObject, TProperty>(TObject, ref TProperty, TProperty, EventHandler<ValueChangedEventArgs<TProperty>>)
PropertyChangedEventHelpers.SafelySetProperty<TObject, TProperty>(TObject, ref TProperty, TProperty, EventHandler<ValueChangedEventArgs<TProperty>>, EventHandler<ValueChangedEventArgs<TProperty>>)
In This Article
Back to top Generated by DocFX