Show / Hide Table of Contents

Class TranslationGridView<T1, T2>

Class implementing IGridView<T> by providing a function that translates values from one grid view with complex data types, to a grid view with simple data types. For a version that provides "set" functionality, see SettableTranslationGridView<T1, T2>.

Inheritance
object
GridViewBase<T2>
TranslationGridView<T1, T2>
LambdaTranslationGridView<T1, T2>
Implements
IGridView<T2>
Inherited Members
GridViewBase<T2>.Count
GridViewBase<T2>.this[int, int]
GridViewBase<T2>.this[int]
object.GetType()
object.MemberwiseClone()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
Namespace: SadRogue.Primitives.GridViews
Assembly: TheSadRogue.Primitives.dll
Syntax
public abstract class TranslationGridView<T1, T2> : GridViewBase<T2>, IGridView<T2>
Type Parameters
Name Description
T1

The type of your underlying data.

T2

The type of the data being exposed by the grid view.

Remarks

This class is useful if the underlying representation of the data you are creating a grid view for is complex, and you simply need to map a complex data type to a simpler one. For example, you might implement the TranslateGet(Point, T1) function to extract a property from a more complex structure. If your mapping is very simple, or you do not wish to create a subclass, see LambdaTranslationGridView<T1, T2>.

Constructors

View Source

TranslationGridView(IGridView<T1>)

Constructor. Takes an existing grid view to create a view from.

Declaration
protected TranslationGridView(IGridView<T1> baseGrid)
Parameters
Type Name Description
IGridView<T1> baseGrid

A grid view exposing your underlying data.

Properties

View Source

BaseGrid

The underlying grid data, exposed as a grid view.

Declaration
public IGridView<T1> BaseGrid { get; }
Property Value
Type Description
IGridView<T1>
View Source

Height

The height of the grid.

Declaration
public override int Height { get; }
Property Value
Type Description
int
Overrides
GridViewBase<T2>.Height
View Source

this[Point]

Given a position, translates and returns the "value" associated with that position.

Declaration
public override T2 this[Point pos] { get; }
Parameters
Type Name Description
Point pos

Location to get the value for.

Property Value
Type Description
T2

The translated "value" associated with the provided location.

Overrides
GridViewBase<T2>.this[Point]
View Source

Width

The width of the grid.

Declaration
public override int Width { get; }
Property Value
Type Description
int
Overrides
GridViewBase<T2>.Width

Methods

View Source

ToString()

Returns a string representation of the exposed grid values.

Declaration
public override string ToString()
Returns
Type Description
string

A string representation of the exposed grid values.

Overrides
object.ToString()
View Source

ToString(Func<T2, string>)

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

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

Function determining the string representation of each element.

Returns
Type Description
string

A string representation of the grid values.

View Source

ToString(int, Func<T2, string>?)

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

Declaration
public string ToString(int fieldSize, Func<T2, string>? elementStringifier = null)
Parameters
Type Name Description
int 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<T2, 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.

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.

View Source

TranslateGet(Point, T1)

Translates your actual data into the view type using the position and the data value itself. If you need only the data value to perform the translation, implement TranslateGet(T1) instead.

Declaration
protected virtual T2 TranslateGet(Point position, T1 value)
Parameters
Type Name Description
Point position

The position of the given data value.

T1 value

The data value from your underlying grid view.

Returns
Type Description
T2

A value of the mapped data type.

View Source

TranslateGet(T1)

Translates your actual data into the view type using just the data value itself. If you need the location as well to perform the translation, implement TranslateGet(Point, T1) instead.

Declaration
protected virtual T2 TranslateGet(T1 value)
Parameters
Type Name Description
T1 value

The data value from the base grid view.

Returns
Type Description
T2

A value of the mapped data type.

Implements

IGridView<T>

Extension Methods

GridViewExtensions.Bounds<T>(IGridView<T>)
GridViewExtensions.Contains<T>(IGridView<T>, Point)
GridViewExtensions.Contains<T>(IGridView<T>, int, int)
GridViewExtensions.ExtendToString<T>(IGridView<T>, int, string, string, Func<T, string>?, string, string, string, string)
GridViewExtensions.ExtendToString<T>(IGridView<T>, string, string, Func<T, string>?, string, string, string, string)
GridViewExtensions.Positions<T>(IGridView<T>)
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>>?)
  • View Source
In this article
Back to top Generated by DocFX