Interface IPropertyStates<T>
Definition
Namespace: StardewUI.Framework.Behaviors
Assembly: StardewUI.dll
Provides methods for tracking and modifying state-based overrides for a view's property.
public interface IPropertyStates<T> :
System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, T>>,
System.Collections.IEnumerable
Type Parameters
T
The property value type.
Implements
IEnumerable<KeyValuePair<string, T>>, IEnumerable
Remarks
State overrides provide a clean priority scheme and reversion path for semantic states such as "hover" or "pressed". Instead of behaviors modifying an IView directly, they can instead push their override to the view's propert states, and as long as that override remains the topmost state, it is authoritative for that specific view and property. If it is later removed, then whichever other state is subsequently on top takes precedence.
Using this abstraction avoids the need for individual behaviors to save the previous value, and more importantly, prevents unintended conflicts between multiple behaviors each trying to act on the same property of the same view.
Members
Methods
Name | Description |
---|---|
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. |
ReplaceOrPush(string, T) | Replaces any existing value associated with a specified state, or pushes a new state to the top of the stack if a previous state does not already exist. |
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
Methods
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.
ReplaceOrPush(string, T)
Replaces any existing value associated with a specified state, or pushes a new state to the top of the stack if a previous state does not already exist.
Parameters
stateName
string
The name of the new state.
value
T
The property value to associate with the specified stateName
.
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
true
if there was at least one active override for this property; false
if the stack is currently empty.
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
true
if there was at least one active override for this property; false
if the stack is currently empty.
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.
Returns
true
if an override for the specified stateName
was removed from the stack; false
if no such state was on the stack.