Class PropertyStateList<T>
Definition
Namespace: StardewUI.Framework.Behaviors
Assembly: StardewUI.dll
Simple list-based implementation of IPropertyStates<T> optimized for low override counts, typically fewer than 5 and never more than 10-20.
public class PropertyStateList<T> :
StardewUI.Framework.Behaviors.IPropertyStates<T>,
System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, T>>,
System.Collections.IEnumerable,
System.Collections.Generic.IReadOnlyList<System.Collections.Generic.KeyValuePair<string, T>>,
System.Collections.Generic.IReadOnlyCollection<System.Collections.Generic.KeyValuePair<string, T>>
Type Parameters
T
The property value type.
Inheritance
Object ⇦ PropertyStateList<T>
Implements
IPropertyStates<T>, IEnumerable<KeyValuePair<string, T>>, IEnumerable, IReadOnlyList<KeyValuePair<string, T>>, IReadOnlyCollection<KeyValuePair<string, T>>
Remarks
Internally uses a List<T>, which is memory-efficient and has fast appends, but requires shifting items when a state is removed from the middle of the list. This is suitable for small stacks (e.g. a pressed state on top of a hover state, where the latter might be removed before the former), but if the stacks become very large, i.e. having hundreds of items, then a different implementation such as linked list or linked hash set might be required. Pushing a new state also requires checking for the existing state first, which is faster than hashing for very small lists but, similar to removals, may be inefficient for very large ones.
Members
Constructors
Name | Description |
---|---|
PropertyStateList<T>() |
Properties
Name | Description |
---|---|
Count | |
Item[int] |
Methods
Name | Description |
---|---|
GetEnumerator() | |
Push(string, T) | Pushes a new state to the top of the stack, making it the active override. |
Replace(string, T) | Replaces the value associated with a specified state. |
TryPeek(ValueTuple<string, T>) | Gets the state name and value with highest priority, i.e. on top of the stack. |
TryPeekValue(T&<>) | Gets the value with highest priority, i.e. on top of the stack. |
TryRemove(string, T&<>) | Removes a specified state override, if one exists. |
Details
Constructors
PropertyStateList<T>()
Properties
Count
Property Value
Item[int]
Property Value
Methods
GetEnumerator()
public System.Collections.Generic.IEnumerator<System.Collections.Generic.KeyValuePair<string, T>> GetEnumerator();
Returns
IEnumerator<KeyValuePair<string, T>>
Push(string, T)
Pushes a new state to the top of the stack, making it the active override.
Parameters
stateName
string
The name of the new state.
value
T
The property value to use when while the state is active.
Remarks
If a state with the specified stateName
already exists on the stack, then this will remove the previous instance and add the new instance on top.
Replace(string, T)
Replaces the value associated with a specified state.
Parameters
stateName
string
The name of the state on the stack.
value
T
The new value to associate with the specified stateName
.
Returns
Remarks
If no state with the specified stateName
is on the stack, then this does nothing. It will not push a new state.
TryPeek(ValueTuple<string, T>)
Gets the state name and value with highest priority, i.e. on top of the stack.
Parameters
result
ValueTuple<string, T>
The state name and value of the active override, or the default for T
if the function returned false
.
Returns
TryPeekValue(T&<>)
Gets the value with highest priority, i.e. on top of the stack.
Parameters
value
T
The value of the active override, or the default for T
if the function returned false
.
Returns
TryRemove(string, T&<>)
Removes a specified state override, if one exists.
Parameters
stateName
string
The name of the state on the stack.
value
T
The value associated with the specified stateName
, if there was an existing override, or null
if there was no instance of that state.