Class LambdaSettableGridView<T>
Class implementing ISettableGridView<T>, by providing the "get" and "set" functionality via functions that are passed in at construction. For a version that implements IGridView<T>, see LambdaGridView<T>.
Inherited Members
Namespace: SadRogue.Primitives.GridViews
Assembly: TheSadRogue.Primitives.dll
Syntax
public sealed class LambdaSettableGridView<T> : SettableGridViewBase<T>, ISettableGridView<T>, IGridView<T>
Type Parameters
Name | Description |
---|---|
T | The type of value being returned by the indexer functions. |
Constructors
LambdaSettableGridView(Func<Int32>, Func<Int32>, Func<Point, T>, Action<Point, T>)
Constructor. Takes functions that retrieve the width and height of the grid, and the functions used to retrieve/set the value for a location.
Declaration
public LambdaSettableGridView(Func<int> widthGetter, Func<int> heightGetter, Func<Point, T> valueGetter, Action<Point, T> valueSetter)
Parameters
Type | Name | Description |
---|---|---|
Func<Int32> | widthGetter | A function/lambda that retrieves the width of the grid being represented. |
Func<Int32> | heightGetter | A function/lambda that retrieves the height of the grid being represented. |
Func<Point, T> | valueGetter | A function/lambda that returns the value of type T associated with the location it is given. |
Action<Point, T> | valueSetter | A function/lambda that updates the grid being represented accordingly, given a type T and position to which it was set. |
Remarks
This constructor is useful if the width and height of the underlying representation may change -- one can provide functions that retrieve the width and height of the map being represented, and these functions will be called any time the Width and Height properties are retrieved.
LambdaSettableGridView(Int32, Int32, Func<Point, T>, Action<Point, T>)
Constructor. Takes the width and height of the grid, and the functions to use to retrieve/set the value for a location.
Declaration
public LambdaSettableGridView(int width, int height, Func<Point, T> valueGetter, Action<Point, T> valueSetter)
Parameters
Type | Name | Description |
---|---|---|
Int32 | width | The (constant) width of the map. |
Int32 | height | The (constant) height of the map. |
Func<Point, T> | valueGetter | A function/lambda that returns the value of type T associated with the location it is given. |
Action<Point, T> | valueSetter | A function/lambda that updates the underlying representation of the grid being represented accordingly, given a type T and position to which it was set. |
Remarks
This constructor is useful if the width and height of the underlying representation do not change, so they can safely be passed in as constants.
Properties
Height
The height of the grid being represented.
Declaration
public override int Height { get; }
Property Value
Type | Description |
---|---|
Int32 |
Overrides
Item[Point]
Given a position, returns/sets the "value" associated with that location, by calling the valueGetter/valueSetter functions provided at construction.
Declaration
public override T this[Point pos] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
Point | pos | Location to retrieve/set the value for. |
Property Value
Type | Description |
---|---|
T | The "value" associated with the provided location, according to the valueGetter function provided at construction. |
Overrides
Width
The width of the grid being represented.
Declaration
public override int Width { get; }
Property Value
Type | Description |
---|---|
Int32 |
Overrides
Methods
ToString()
Returns a string representation of the grid values.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
String | A string representation of the grid values. |
ToString(Func<T, String>)
Returns a string representation of the grid values, 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. |
ToString(Int32, Func<T, 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<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. |
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.