Exemple #1
0
        public void TestTickSnapping()
        {
            var slider = new Slider { TickFrequency = 1 };

            slider.Value = 0.55f;
            slider.SnapToClosestTick();
            Assert.AreEqual(1f, slider.Value);

            slider.Value = 0.45f;
            slider.SnapToClosestTick();
            Assert.AreEqual(0f, slider.Value);

            slider.TickFrequency = 20;
            slider.Value = 0.44f;
            slider.ShouldSnapToTicks = true;
            Utilities.AssertAreNearlyEqual(0.45f, slider.Value);

            slider.TickFrequency = 5;
            Utilities.AssertAreNearlyEqual(0.4f, slider.Value);

            slider.Value = 0.22f;
            Utilities.AssertAreNearlyEqual(0.2f, slider.Value);

            slider.Step = 0.16f;
            slider.Increase();
            Utilities.AssertAreNearlyEqual(0.4f, slider.Value);
        }
Exemple #2
0
        public void TestValueChanged()
        {
            var valueChanged = false;
            var slider = new Slider();
            slider.ValueChanged += (s, e) => valueChanged = true;

            slider.Value = 0;
            Assert.AreEqual(false, valueChanged);
            valueChanged = false;

            slider.Value = 1;
            Assert.AreEqual(true, valueChanged);
            valueChanged = false;

            slider.Value = 2;
            Assert.AreEqual(false, valueChanged); // because of maximum
            valueChanged = false;

            slider.Value = 0.55f;
            valueChanged = false;
            slider.SnapToClosestTick();
            Assert.AreEqual(true, valueChanged);
            valueChanged = false;

            slider.Value = 0.5f;
            valueChanged = false;
            slider.TickFrequency = 3f;
            slider.ShouldSnapToTicks = true;
            Assert.AreEqual(true, valueChanged);
            valueChanged = false;

            slider.TickFrequency = 4f;
            Assert.AreEqual(true, valueChanged);
            valueChanged = false;
        }