A game framework written with osu! in mind.
at master 2.9 kB view raw
1// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. 2// See the LICENCE file in the repository root for full licence text. 3 4using NUnit.Framework; 5using osu.Framework.Bindables; 6using osu.Framework.Graphics; 7using osu.Framework.Graphics.Containers; 8using osu.Framework.Graphics.UserInterface; 9using osuTK; 10 11namespace osu.Framework.Tests.Visual.UserInterface 12{ 13 public class TestSceneCheckboxes : FrameworkTestScene 14 { 15 private readonly BasicCheckbox basic; 16 17 public TestSceneCheckboxes() 18 { 19 BasicCheckbox swap, rotate; 20 21 Children = new Drawable[] 22 { 23 new FillFlowContainer 24 { 25 Anchor = Anchor.TopLeft, 26 Origin = Anchor.TopLeft, 27 Direction = FillDirection.Vertical, 28 Spacing = new Vector2(0, 10), 29 Padding = new MarginPadding(10), 30 AutoSizeAxes = Axes.Both, 31 Children = new Drawable[] 32 { 33 basic = new BasicCheckbox 34 { 35 LabelText = @"Basic Test" 36 }, 37 new BasicCheckbox 38 { 39 LabelText = @"FadeDuration Test", 40 FadeDuration = 300 41 }, 42 swap = new BasicCheckbox 43 { 44 LabelText = @"Checkbox Position", 45 }, 46 rotate = new BasicCheckbox 47 { 48 LabelText = @"Enabled/Disabled Actions Test", 49 }, 50 } 51 } 52 }; 53 54 swap.Current.ValueChanged += check => swap.RightHandedCheckbox = check.NewValue; 55 rotate.Current.ValueChanged += e => rotate.RotateTo(e.NewValue ? 45 : 0, 100); 56 } 57 58 /// <summary> 59 /// Test safety of <see cref="IHasCurrentValue{T}"/> implementation. 60 /// This is shared across all UI elements. 61 /// </summary> 62 [Test] 63 public void TestDirectToggle() 64 { 65 var testBindable = new Bindable<bool> { BindTarget = basic.Current }; 66 67 AddAssert("is unchecked", () => !basic.Current.Value); 68 AddAssert("bindable unchecked", () => !testBindable.Value); 69 70 AddStep("switch bindable directly", () => basic.Current.Value = true); 71 72 AddAssert("is checked", () => basic.Current.Value); 73 AddAssert("bindable checked", () => testBindable.Value); 74 75 AddStep("change bindable", () => basic.Current = new Bindable<bool>()); 76 77 AddAssert("is unchecked", () => !basic.Current.Value); 78 AddAssert("bindable unchecked", () => !testBindable.Value); 79 } 80 } 81}