Ejemplo n.º 1
0
        public void TestBindableFloat()
        {
            float lastUpdated = 0.0f;
            float orig        = 0f;
            var   bindable    = new ProxyBindableFloat(() => orig, (v) => orig = v);

            bindable.OnValueChanged += (v, _) => lastUpdated = v;

            Assert.AreEqual(float.MinValue, bindable.MinValue, FloatDelta);
            Assert.AreEqual(float.MaxValue, bindable.MaxValue, FloatDelta);
            Assert.AreEqual(0.0, bindable.Value, FloatDelta);

            bindable.MinValue = 1.0f;
            Assert.AreEqual(1.0f, bindable.MinValue, FloatDelta);
            Assert.AreEqual(1.0f, bindable.Value, FloatDelta);
            Assert.AreEqual(1.0f, lastUpdated, FloatDelta);

            bindable.Value = 2;
            Assert.AreEqual(2.0f, bindable.Value, FloatDelta);
            Assert.AreEqual(2.0f, lastUpdated, FloatDelta);

            orig     = 5f;
            bindable = new ProxyBindableFloat(() => orig, (v) => orig = v, -100, 100);
            bindable.OnValueChanged += (v, _) => lastUpdated = v;

            Assert.AreEqual(-100.0f, bindable.MinValue, FloatDelta);
            Assert.AreEqual(100.0f, bindable.MaxValue, FloatDelta);
            Assert.AreEqual(5.0f, bindable.Value, FloatDelta);

            bindable.MaxValue = -1;
            Assert.AreEqual(-1.0f, bindable.MaxValue, FloatDelta);
            Assert.AreEqual(-1.0f, bindable.Value, FloatDelta);
            Assert.AreEqual(-1.0f, lastUpdated, FloatDelta);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Instantiates a new proxy bindable, assuming a float for type T.
        /// </summary>
        private ProxyBindableFloat InitFloatBindable(string propertyName, float defaultValue, float minValue, float maxValue)
        {
            var bindable = new ProxyBindableFloat(
                () => storage == null ? defaultValue : storage.GetFloat(propertyName, defaultValue),
                (value) => storage.SetFloat(propertyName, value),
                minValue,
                maxValue
                );

            allSettings.Add(bindable);
            return(bindable);
        }