using System;
using Studio;
using UniRx;
namespace KKAPI.Studio.UI
{
///
/// Base class of controls that hold a value.
/// Subscribe to to update your control's state whenever the value changes.
///
/// Type of the held value
public abstract class BaseCurrentStateEditableGuiEntry : CurrentStateCategorySubItemBase
{
private readonly Func _updateValue;
///
/// Create a new control that holds a value
///
/// Name of the control
/// Function called every time current character changes and the value needs to be updated
/// Initial value used before first updateValue call
protected BaseCurrentStateEditableGuiEntry(string name, Func updateValue, T initialValue = default(T)) : base(name)
{
_updateValue = updateValue ?? throw new ArgumentNullException(nameof(updateValue));
Value = new BehaviorSubject(initialValue);
}
///
/// Current value of this control
///
public BehaviorSubject Value { get; }
///
protected internal override void OnUpdateInfo(OCIChar ociChar)
{
Value.OnNext(_updateValue.Invoke(ociChar));
}
}
}