1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 16:06:06 +08:00

Remove bindable

This commit is contained in:
Andrei Zavatski 2020-04-09 13:10:09 +03:00
parent 2d3ea95469
commit 134feefa14
2 changed files with 19 additions and 23 deletions

View File

@ -55,13 +55,13 @@ namespace osu.Game.Tests.Visual.UserInterface
[Test]
public void TestButtonVisibility()
{
AddAssert("button is hidden", () => scroll.Button.Current.Value == Visibility.Hidden);
AddAssert("button is hidden", () => scroll.Button.State == Visibility.Hidden);
AddStep("scroll to end", () => scroll.ScrollToEnd(false));
AddAssert("button is visible", () => scroll.Button.Current.Value == Visibility.Visible);
AddAssert("button is visible", () => scroll.Button.State == Visibility.Visible);
AddStep("scroll to start", () => scroll.ScrollToStart(false));
AddAssert("button is hidden", () => scroll.Button.Current.Value == Visibility.Hidden);
AddAssert("button is hidden", () => scroll.Button.State == Visibility.Hidden);
}
[Test]

View File

@ -3,14 +3,12 @@
using System.Collections.Generic;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Effects;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events;
using osu.Game.Graphics.Containers;
using osuTK;
@ -43,7 +41,7 @@ namespace osu.Game.Overlays
{
ScrollToStart();
currentTarget = Target;
Button.Current.Value = Visibility.Hidden;
Button.State = Visibility.Hidden;
}
});
}
@ -54,7 +52,7 @@ namespace osu.Game.Overlays
if (ScrollContent.DrawHeight + button_scroll_position < DrawHeight)
{
Button.Current.Value = Visibility.Hidden;
Button.State = Visibility.Hidden;
return;
}
@ -62,19 +60,27 @@ namespace osu.Game.Overlays
return;
currentTarget = Target;
Button.Current.Value = Current > button_scroll_position ? Visibility.Visible : Visibility.Hidden;
Button.State = Current > button_scroll_position ? Visibility.Visible : Visibility.Hidden;
}
public class ScrollToTopButton : OsuHoverContainer, IHasCurrentValue<Visibility>
public class ScrollToTopButton : OsuHoverContainer
{
private const int fade_duration = 500;
private readonly BindableWithCurrent<Visibility> current = new BindableWithCurrent<Visibility>();
private Visibility state;
public Bindable<Visibility> Current
public Visibility State
{
get => current.Current;
set => current.Current = value;
get => state;
set
{
if (value == state)
return;
state = value;
Enabled.Value = state == Visibility.Visible;
this.FadeTo(state == Visibility.Visible ? 1 : 0, fade_duration, Easing.OutQuint);
}
}
protected override IEnumerable<Drawable> EffectTargets => new[] { background };
@ -128,16 +134,6 @@ namespace osu.Game.Overlays
flashColour = colourProvider.Light1;
}
protected override void LoadComplete()
{
base.LoadComplete();
Current.BindValueChanged(visibility =>
{
Enabled.Value = visibility.NewValue == Visibility.Visible;
this.FadeTo(visibility.NewValue == Visibility.Visible ? 1 : 0, fade_duration, Easing.OutQuint);
}, true);
}
protected override bool OnClick(ClickEvent e)
{
background.FlashColour(flashColour, 800, Easing.OutQuint);