public void TestBasic() { RestoreDefaultValueButton <float> restoreDefaultValueButton = null; AddStep("create button", () => Child = new Container { RelativeSizeAxes = Axes.Both, Children = new Drawable[] { new Box { RelativeSizeAxes = Axes.Both, Colour = colours.GreySeafoam }, restoreDefaultValueButton = new RestoreDefaultValueButton <float> { Anchor = Anchor.Centre, Origin = Anchor.Centre, Scale = new Vector2(scale), Current = current, } } }); AddSliderStep("set scale", 1, 4, 1, scale => { this.scale = scale; if (restoreDefaultValueButton != null) { restoreDefaultValueButton.Scale = new Vector2(scale); } }); AddToggleStep("toggle default state", state => current.Value = state ? default : 1); AddToggleStep("toggle disabled state", state => current.Disabled = state); }
public void TestRestoreDefaultValueButtonPrecision(float initialValue) { BindableFloat current = null; SettingsSlider <float> sliderBar = null; RestoreDefaultValueButton <float> restoreDefaultValueButton = null; AddStep("create settings item", () => { Child = sliderBar = new SettingsSlider <float> { Current = current = new BindableFloat(initialValue) { MinValue = 0f, MaxValue = 10f, Precision = 0.1f, } }; }); AddUntilStep("wait for loaded", () => sliderBar.IsLoaded); AddStep("retrieve restore default button", () => restoreDefaultValueButton = sliderBar.ChildrenOfType <RestoreDefaultValueButton <float> >().Single()); AddAssert("restore button hidden", () => restoreDefaultValueButton.Alpha == 0); AddStep("change value to next closest", () => sliderBar.Current.Value += current.Precision * 0.6f); AddUntilStep("restore button shown", () => restoreDefaultValueButton.Alpha > 0); AddStep("restore default", () => sliderBar.Current.SetDefault()); AddUntilStep("restore button hidden", () => restoreDefaultValueButton.Alpha == 0); }
public void TestRestoreDefaultValueButtonVisibility() { SettingsTextBox textBox = null; RestoreDefaultValueButton <string> restoreDefaultValueButton = null; AddStep("create settings item", () => { Child = textBox = new SettingsTextBox { Current = new Bindable <string> { Default = "test", Value = "test" } }; }); AddUntilStep("wait for loaded", () => textBox.IsLoaded); AddStep("retrieve restore default button", () => restoreDefaultValueButton = textBox.ChildrenOfType <RestoreDefaultValueButton <string> >().Single()); AddAssert("restore button hidden", () => restoreDefaultValueButton.Alpha == 0); AddStep("change value from default", () => textBox.Current.Value = "non-default"); AddUntilStep("restore button shown", () => restoreDefaultValueButton.Alpha > 0); AddStep("restore default", () => textBox.Current.SetDefault()); AddUntilStep("restore button hidden", () => restoreDefaultValueButton.Alpha == 0); }
public void TestSetAndClearLabelText() { SettingsTextBox textBox = null; RestoreDefaultValueButton <string> restoreDefaultValueButton = null; OsuTextBox control = null; AddStep("create settings item", () => { Child = textBox = new SettingsTextBox { Current = new Bindable <string> { Default = "test", Value = "test" } }; }); AddUntilStep("wait for loaded", () => textBox.IsLoaded); AddStep("retrieve components", () => { restoreDefaultValueButton = textBox.ChildrenOfType <RestoreDefaultValueButton <string> >().Single(); control = textBox.ChildrenOfType <OsuTextBox>().Single(); }); AddStep("set non-default value", () => restoreDefaultValueButton.Current.Value = "non-default"); AddAssert("default value button centre aligned to control size", () => Precision.AlmostEquals(restoreDefaultValueButton.Parent.DrawHeight, control.DrawHeight, 1)); AddStep("set label", () => textBox.LabelText = "label text"); AddAssert("default value button centre aligned to label size", () => { var label = textBox.ChildrenOfType <OsuSpriteText>().Single(spriteText => spriteText.Text == "label text"); return(Precision.AlmostEquals(restoreDefaultValueButton.Parent.DrawHeight, label.DrawHeight, 1)); }); AddStep("clear label", () => textBox.LabelText = default); AddAssert("default value button centre aligned to control size", () => Precision.AlmostEquals(restoreDefaultValueButton.Parent.DrawHeight, control.DrawHeight, 1)); AddStep("set warning text", () => textBox.WarningText = "This is some very important warning text! Hopefully it doesn't break the alignment of the default value indicator..."); AddAssert("default value button centre aligned to control size", () => Precision.AlmostEquals(restoreDefaultValueButton.Parent.DrawHeight, control.DrawHeight, 1)); }