1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 02:02:53 +08:00

add IHasOverhangingTooltip

This commit is contained in:
Jorolf 2017-04-14 00:18:17 +02:00
parent f6f75fac74
commit 7f08c3c417
4 changed files with 41 additions and 19 deletions

View File

@ -21,6 +21,7 @@ namespace osu.Desktop.VisualTests.Tests
public override void Reset()
{
base.Reset();
TooltipSlider slider;
Children = new Drawable[]
{
@ -28,6 +29,7 @@ namespace osu.Desktop.VisualTests.Tests
{
RelativeSizeAxes = Axes.Both,
Direction = FillDirection.Vertical,
Spacing = new Vector2(0,10),
Children = new Drawable[]
{
new TooltipContainer("Text with some tooltip"),
@ -35,20 +37,22 @@ namespace osu.Desktop.VisualTests.Tests
new TooltipTextbox
{
Text = "a box with a tooltip",
Width = 300,
Size = new Vector2(300,30),
},
new TooltipSlider
slider = new TooltipSlider
{
Bindable = new BindableInt(5)
{
MaxValue = 10,
MinValue = 0,
},
Size = new Vector2(300,16),
Width = 300,
},
},
},
};
slider.Current.BindTo(new BindableInt(5)
{
MaxValue = 10,
MinValue = 0
});
}
private class TooltipContainer : Container, IHasTooltip
@ -76,23 +80,23 @@ namespace osu.Desktop.VisualTests.Tests
public string Tooltip => Text;
}
private class TooltipSlider : OsuSliderBar<int>, IHasDelayedTooltip
private class TooltipSlider : OsuSliderBar<int>, IHasDelayedTooltip, IHasOverhangingTooltip
{
public string Tooltip => Bindable.Value.ToString();
public string Tooltip => Current.Value.ToString();
int IHasDelayedTooltip.Delay => mousePressed ? 0 : 250;
int IHasDelayedTooltip.Delay => Overhanging ? 0 : 250;
private bool mousePressed;
public bool Overhanging { get; set; }
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
{
mousePressed = true;
Overhanging = true;
return base.OnMouseDown(state, args);
}
protected override bool OnMouseUp(InputState state, MouseUpEventArgs args)
{
mousePressed = false;
Overhanging = false;
return base.OnMouseUp(state, args);
}
}

View File

@ -12,7 +12,7 @@ namespace osu.Game.Graphics.Cursor
}
/// <summary>
/// Interface of <see cref="IHasTooltip"/> with custom appear time
/// Tooltip with custom appear time
/// </summary>
public interface IHasDelayedTooltip : IHasTooltip
{
@ -21,4 +21,15 @@ namespace osu.Game.Graphics.Cursor
/// </summary>
int Delay { get; }
}
/// <summary>
/// Tooltip which can show after hovering over the object
/// </summary>
public interface IHasOverhangingTooltip : IHasTooltip
{
/// <summary>
/// Should the tooltip still show?
/// </summary>
bool Overhanging { get; }
}
}

View File

@ -31,24 +31,33 @@ namespace osu.Game.Graphics.Cursor
private ScheduledDelegate show;
private OsuGameBase game;
private IHasOverhangingTooltip overhang;
protected override bool OnMouseMove(InputState state)
{
if (state.Mouse.Position != state.Mouse.LastPosition)
Tooltip tooltip = ((Cursor)ActiveCursor).Tooltip;
if (overhang?.Overhanging ?? false)
tooltip.TooltipText = overhang.Tooltip;
else if (state.Mouse.Position != state.Mouse.LastPosition)
{
Tooltip tooltip = ((Cursor)ActiveCursor).Tooltip;
show?.Cancel();
tooltip.TooltipText = string.Empty;
IHasTooltip hasTooltip = null;
if (game.InternalChildren.OfType<IContainer>().Any(child => (hasTooltip = searchTooltip(child as IContainerEnumerable<Drawable>)) != null))
{
IHasDelayedTooltip delayedTooltip = hasTooltip as IHasDelayedTooltip;
overhang = hasTooltip as IHasOverhangingTooltip;
show = Scheduler.AddDelayed(delegate
{
tooltip.TooltipText = hasTooltip.Tooltip;
}, delayedTooltip?.Delay ?? 250);
}
}
else if(overhang != null)
{
overhang = null;
tooltip.TooltipText = string.Empty;
}
if (dragging)
{

View File

@ -34,8 +34,6 @@ namespace osu.Game.Graphics.Cursor
public Tooltip()
{
Depth = float.MinValue;
AlwaysReceiveInput = true;
Children = new[]
{
new Container