Class DecoratorView<T>.DecoratedProperty<T, TValue>
Definition
Namespace: StardewUI.Widgets
Assembly: StardewUI.dll
Helper for propagating a single property to and from the inner view.
Type Parameters
T
TValue
The type of value tracked.
Inheritance
Object ⇦ DecoratedProperty<T, TValue>
Remarks
Decorated properties must be initialized in the decorator's constructor by calling RegisterDecoratedProperty<TValue>(DecoratedProperty<T, TValue>), and have the following behavior:
- The current value is tracked independently of the inner view;
- If the current value has not been set, then it is ignored when initializing a new view;
- If the current value has been set, the view's value is overwritten on initialization.
Members
Constructors
Name | Description |
---|---|
DecoratedProperty<T, TValue>(Func<T, TValue>, Action<T, TValue>, TValue) | Helper for propagating a single property to and from the inner view. |
Methods
Name | Description |
---|---|
Get() | Gets the current value from the inner view. |
Set(TValue) | Updates the property value, also updating the inner view if one exists. |
Update() | Updates the inner view's property to the most recent value, if one has been set on the decorated property. |
Details
Constructors
DecoratedProperty<T, TValue>(Func<T, TValue>, Action<T, TValue>, TValue)
Helper for propagating a single property to and from the inner view.
public DecoratedProperty<T, TValue>(Func<T, TValue> getValue, Action<T, TValue> setValue, TValue defaultValue);
Parameters
getValue
Func<T, TValue>
Function to retrieve the current value from the inner view.
setValue
Action<T, TValue>
Delegate to change the current value on the inner view.
defaultValue
TValue
The initial value to return from Get() if no view exists and the value has not been changed. This is never written to the view, it is only used by Get() and is effectively a hack to allow DecoratedProperty<T, TValue> to deal with value (struct) types.
Remarks
Decorated properties must be initialized in the decorator's constructor by calling RegisterDecoratedProperty<TValue>(DecoratedProperty<T, TValue>), and have the following behavior:
- The current value is tracked independently of the inner view;
- If the current value has not been set, then it is ignored when initializing a new view;
- If the current value has been set, the view's value is overwritten on initialization.
Methods
Get()
Gets the current value from the inner view.
Returns
TValue
The value from the current view, if the view is non-null; otherwise, the default value configured for this property.
Set(TValue)
Updates the property value, also updating the inner view if one exists.
Parameters
value
TValue
The new value.
Remarks
If the inner view has not been created yet, then its corresponding property will be updated as soon as it is assigned to the View.
Update()
Updates the inner view's property to the most recent value, if one has been set on the decorated property.
Remarks
If there have been no calls to Set(TValue), then the view is left untouched, to preserve any non-default settings on the inner view.