mirror of
https://github.com/osukey/osukey.git
synced 2025-08-02 22:26:41 +09:00
Move files to UI namespace
This commit is contained in:
21
osu.Game/Graphics/Containers/ExpandingButtonContainer.cs
Normal file
21
osu.Game/Graphics/Containers/ExpandingButtonContainer.cs
Normal file
@ -0,0 +1,21 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
namespace osu.Game.Graphics.Containers
|
||||
{
|
||||
/// <summary>
|
||||
/// An <see cref="ExpandingContainer"/> with a long hover expansion delay.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Mostly used for buttons with explanatory labels, in which the label would display after a "long hover".
|
||||
/// </remarks>
|
||||
public class ExpandingButtonContainer : ExpandingContainer
|
||||
{
|
||||
protected ExpandingButtonContainer(float contractedWidth, float expandedWidth)
|
||||
: base(contractedWidth, expandedWidth)
|
||||
{
|
||||
}
|
||||
|
||||
protected override double HoverExpansionDelay => 750;
|
||||
}
|
||||
}
|
100
osu.Game/Graphics/Containers/ExpandingContainer.cs
Normal file
100
osu.Game/Graphics/Containers/ExpandingContainer.cs
Normal file
@ -0,0 +1,100 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Framework.Threading;
|
||||
|
||||
namespace osu.Game.Graphics.Containers
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a <see cref="Container"/> with the ability to expand/contract on hover.
|
||||
/// </summary>
|
||||
public class ExpandingContainer : Container, IExpandingContainer
|
||||
{
|
||||
private readonly float contractedWidth;
|
||||
private readonly float expandedWidth;
|
||||
|
||||
public BindableBool Expanded { get; } = new BindableBool();
|
||||
|
||||
/// <summary>
|
||||
/// Delay before the container switches to expanded state from hover.
|
||||
/// </summary>
|
||||
protected virtual double HoverExpansionDelay => 0;
|
||||
|
||||
protected override Container<Drawable> Content => FillFlow;
|
||||
|
||||
protected FillFlowContainer FillFlow { get; }
|
||||
|
||||
protected ExpandingContainer(float contractedWidth, float expandedWidth)
|
||||
{
|
||||
this.contractedWidth = contractedWidth;
|
||||
this.expandedWidth = expandedWidth;
|
||||
|
||||
RelativeSizeAxes = Axes.Y;
|
||||
Width = contractedWidth;
|
||||
|
||||
InternalChild = new OsuScrollContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
ScrollbarVisible = false,
|
||||
Child = FillFlow = new FillFlowContainer
|
||||
{
|
||||
Origin = Anchor.CentreLeft,
|
||||
Anchor = Anchor.CentreLeft,
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Direction = FillDirection.Vertical,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
private ScheduledDelegate hoverExpandEvent;
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
Expanded.BindValueChanged(v =>
|
||||
{
|
||||
this.ResizeWidthTo(v.NewValue ? expandedWidth : contractedWidth, 500, Easing.OutQuint);
|
||||
}, true);
|
||||
}
|
||||
|
||||
protected override bool OnHover(HoverEvent e)
|
||||
{
|
||||
updateHoverExpansion();
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override bool OnMouseMove(MouseMoveEvent e)
|
||||
{
|
||||
updateHoverExpansion();
|
||||
return base.OnMouseMove(e);
|
||||
}
|
||||
|
||||
protected override void OnHoverLost(HoverLostEvent e)
|
||||
{
|
||||
if (hoverExpandEvent != null)
|
||||
{
|
||||
hoverExpandEvent?.Cancel();
|
||||
hoverExpandEvent = null;
|
||||
|
||||
Expanded.Value = false;
|
||||
return;
|
||||
}
|
||||
|
||||
base.OnHoverLost(e);
|
||||
}
|
||||
|
||||
private void updateHoverExpansion()
|
||||
{
|
||||
hoverExpandEvent?.Cancel();
|
||||
|
||||
if (IsHovered && !Expanded.Value)
|
||||
hoverExpandEvent = Scheduler.AddDelayed(() => Expanded.Value = true, HoverExpansionDelay);
|
||||
}
|
||||
}
|
||||
}
|
19
osu.Game/Graphics/Containers/IExpandable.cs
Normal file
19
osu.Game/Graphics/Containers/IExpandable.cs
Normal file
@ -0,0 +1,19 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
|
||||
namespace osu.Game.Graphics.Containers
|
||||
{
|
||||
/// <summary>
|
||||
/// An interface for drawables with ability to expand/contract.
|
||||
/// </summary>
|
||||
public interface IExpandable : IDrawable
|
||||
{
|
||||
/// <summary>
|
||||
/// Whether this drawable is in an expanded state.
|
||||
/// </summary>
|
||||
BindableBool Expanded { get; }
|
||||
}
|
||||
}
|
17
osu.Game/Graphics/Containers/IExpandingContainer.cs
Normal file
17
osu.Game/Graphics/Containers/IExpandingContainer.cs
Normal file
@ -0,0 +1,17 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Game.Overlays;
|
||||
|
||||
namespace osu.Game.Graphics.Containers
|
||||
{
|
||||
/// <summary>
|
||||
/// A target expanding container that should be resolved by children <see cref="IExpandable"/>s to propagate state changes.
|
||||
/// </summary>
|
||||
[Cached(typeof(IExpandingContainer))]
|
||||
public interface IExpandingContainer : IContainer, IExpandable
|
||||
{
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user