Skip to content

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.

void Push(string stateName, T value);
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.

bool Replace(string stateName, T value);
Parameters

stateName   string
The name of the state on the stack.

value   T
The new value to associate with the specified stateName.

Returns

Boolean

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.

void ReplaceOrPush(string stateName, T value);
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.

bool TryPeek(out ValueTuple<string, T> result);
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

Boolean

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.

bool TryPeekValue(out T&<> value);
Parameters

value   T
The value of the active override, or the default for T if the function returned false.

Returns

Boolean

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.

bool TryRemove(string stateName, out T&<> value);
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

Boolean

true if an override for the specified stateName was removed from the stack; false if no such state was on the stack.