mirror of
https://github.com/osukey/osukey.git
synced 2025-08-07 00:23:59 +09:00
Merge pull request #21937 from bdach/fix-toolbar-gradient
Fix toolbar gradient not showing when mouse is hovered over buttons
This commit is contained in:
@ -207,7 +207,7 @@ namespace osu.Game.Tests.Visual.Menus
|
|||||||
AddStep("set toolbar width", () =>
|
AddStep("set toolbar width", () =>
|
||||||
{
|
{
|
||||||
toolbar.RelativeSizeAxes = Axes.None;
|
toolbar.RelativeSizeAxes = Axes.None;
|
||||||
toolbar.Width = 0;
|
toolbar.Width = 400;
|
||||||
});
|
});
|
||||||
AddStep("move mouse over news toggle button", () =>
|
AddStep("move mouse over news toggle button", () =>
|
||||||
{
|
{
|
||||||
@ -215,6 +215,7 @@ namespace osu.Game.Tests.Visual.Menus
|
|||||||
InputManager.MoveMouseTo(button);
|
InputManager.MoveMouseTo(button);
|
||||||
});
|
});
|
||||||
AddAssert("no ruleset toggle buttons hovered", () => !toolbar.ChildrenOfType<ToolbarRulesetTabButton>().Any(button => button.IsHovered));
|
AddAssert("no ruleset toggle buttons hovered", () => !toolbar.ChildrenOfType<ToolbarRulesetTabButton>().Any(button => button.IsHovered));
|
||||||
|
AddUntilStep("toolbar gradient visible", () => toolbar.ChildrenOfType<Toolbar.ToolbarBackground>().Single().Children.All(d => d.Alpha > 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
public partial class TestToolbar : Toolbar
|
public partial class TestToolbar : Toolbar
|
||||||
|
@ -65,9 +65,12 @@ namespace osu.Game.Overlays.Toolbar
|
|||||||
[BackgroundDependencyLoader(true)]
|
[BackgroundDependencyLoader(true)]
|
||||||
private void load(OsuGame osuGame)
|
private void load(OsuGame osuGame)
|
||||||
{
|
{
|
||||||
|
ToolbarBackground background;
|
||||||
|
HoverInterceptor interceptor;
|
||||||
|
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
new ToolbarBackground(),
|
background = new ToolbarBackground(),
|
||||||
new GridContainer
|
new GridContainer
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
@ -180,9 +183,15 @@ namespace osu.Game.Overlays.Toolbar
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
interceptor = new HoverInterceptor
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
((IBindable<bool>)background.ShowGradient).BindTo(interceptor.ReceivedHover);
|
||||||
|
|
||||||
if (osuGame != null)
|
if (osuGame != null)
|
||||||
OverlayActivationMode.BindTo(osuGame.OverlayActivationMode);
|
OverlayActivationMode.BindTo(osuGame.OverlayActivationMode);
|
||||||
}
|
}
|
||||||
@ -196,6 +205,8 @@ namespace osu.Game.Overlays.Toolbar
|
|||||||
|
|
||||||
public partial class ToolbarBackground : Container
|
public partial class ToolbarBackground : Container
|
||||||
{
|
{
|
||||||
|
public Bindable<bool> ShowGradient { get; } = new BindableBool();
|
||||||
|
|
||||||
private readonly Box gradientBackground;
|
private readonly Box gradientBackground;
|
||||||
|
|
||||||
public ToolbarBackground()
|
public ToolbarBackground()
|
||||||
@ -220,15 +231,43 @@ namespace osu.Game.Overlays.Toolbar
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void LoadComplete()
|
||||||
|
{
|
||||||
|
base.LoadComplete();
|
||||||
|
|
||||||
|
ShowGradient.BindValueChanged(_ => updateState(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateState()
|
||||||
|
{
|
||||||
|
if (ShowGradient.Value)
|
||||||
|
gradientBackground.FadeIn(transition_time, Easing.OutQuint);
|
||||||
|
else
|
||||||
|
gradientBackground.FadeOut(transition_time, Easing.OutQuint);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whenever the mouse cursor is within the bounds of the toolbar, we want the background gradient to show, for toolbar button descriptions to be legible.
|
||||||
|
/// Unfortunately we also need to ensure that the toolbar buttons handle hover, to prevent the possibility of multiple descriptions being shown
|
||||||
|
/// due to hover events passing through multiple buttons.
|
||||||
|
/// This drawable is a workaround, that when placed front-most in the toolbar, allows to see whether hover events have been propagated through it without handling them.
|
||||||
|
/// </summary>
|
||||||
|
private partial class HoverInterceptor : Drawable
|
||||||
|
{
|
||||||
|
public IBindable<bool> ReceivedHover => receivedHover;
|
||||||
|
private readonly Bindable<bool> receivedHover = new BindableBool();
|
||||||
|
|
||||||
protected override bool OnHover(HoverEvent e)
|
protected override bool OnHover(HoverEvent e)
|
||||||
{
|
{
|
||||||
gradientBackground.FadeIn(transition_time, Easing.OutQuint);
|
receivedHover.Value = true;
|
||||||
return true;
|
return base.OnHover(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnHoverLost(HoverLostEvent e)
|
protected override void OnHoverLost(HoverLostEvent e)
|
||||||
{
|
{
|
||||||
gradientBackground.FadeOut(transition_time, Easing.OutQuint);
|
receivedHover.Value = false;
|
||||||
|
base.OnHoverLost(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user