/
FloatProperty.cs
72 lines (66 loc) · 2.38 KB
/
FloatProperty.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using System;
using System.ComponentModel;
using System.Linq;
using System.Reactive.Linq;
using System.Xml.Serialization;
namespace Bonsai.Expressions
{
/// <summary>
/// Represents a workflow property containing a single-precision floating-point number.
/// </summary>
[DisplayName("Float")]
[XmlType(Namespace = Constants.XmlNamespace)]
[Description("Represents a workflow property containing a single-precision floating-point number.")]
public class FloatProperty : WorkflowProperty
{
float value;
event Action<float> ValueChanged;
/// <summary>
/// Gets or sets the value of the property.
/// </summary>
[Range(0, 1)]
[Description("The value of the property.")]
[Editor(DesignTypes.SliderEditor, DesignTypes.UITypeEditor)]
public float Value
{
get { return value; }
set
{
this.value = value;
OnValueChanged(value);
}
}
internal override Type PropertyType
{
get { return typeof(float); }
}
void OnValueChanged(float value)
{
ValueChanged?.Invoke(value);
}
/// <summary>
/// Generates an observable sequence that produces a value whenever the
/// workflow property changes, starting with the initial property value.
/// </summary>
/// <returns>An observable sequence of property values.</returns>
public virtual IObservable<float> Generate()
{
return Observable
.Defer(() => Observable.Return(value))
.Concat(Observable.FromEvent<float>(
handler => ValueChanged += handler,
handler => ValueChanged -= handler));
}
/// <summary>
/// Generates an observable sequence that produces a value whenever the
/// source sequence emits a new element.
/// </summary>
/// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
/// <param name="source">The source sequence used to generate new values.</param>
/// <returns>An observable sequence of property values.</returns>
public IObservable<float> Generate<TSource>(IObservable<TSource> source)
{
return source.Select(x => value);
}
}
}