1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 20:07:29 +08:00

renaming and some changes in TestCaseTooltip

This commit is contained in:
Jorolf 2017-04-19 13:47:00 +02:00
parent 095b6fded6
commit 8e4288168a
3 changed files with 36 additions and 29 deletions

View File

@ -33,7 +33,10 @@ namespace osu.Desktop.VisualTests.Tests
Children = new Drawable[]
{
new TooltipContainer("Text with some tooltip"),
new TooltipContainer("and another one"),
new TooltipContainer("and another one with a custom delay")
{
TooltipDelay = 1000,
},
new TooltipTextbox
{
Text = "a box with a tooltip",
@ -54,11 +57,13 @@ namespace osu.Desktop.VisualTests.Tests
});
}
private class TooltipContainer : Container, IHasTooltip
private class TooltipContainer : Container, IHasTooltipWithCustomDelay
{
private readonly OsuSpriteText text;
public string Tooltip => text.Text;
public string TooltipText => text.Text;
public int TooltipDelay { get; set; } = Tooltip.DEFAULT_APPEAR_DELAY;
public TooltipContainer(string tooltipText)
{
@ -75,26 +80,24 @@ namespace osu.Desktop.VisualTests.Tests
private class TooltipTextbox : OsuTextBox, IHasTooltip
{
public string Tooltip => Text;
public string TooltipText => Text;
}
private class TooltipSlider : OsuSliderBar<int>, IHasDelayedTooltip, IHasOverhangingTooltip
private class TooltipSlider : OsuSliderBar<int>, IHasDisappearingTooltip
{
public string Tooltip => Current.Value.ToString();
public string TooltipText => Current.Value.ToString();
int IHasDelayedTooltip.Delay => Overhanging ? 0 : 250;
public bool Overhanging { get; set; }
public bool Disappear { get; set; } = true;
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
{
Overhanging = true;
Disappear = false;
return base.OnMouseDown(state, args);
}
protected override bool OnMouseUp(InputState state, MouseUpEventArgs args)
{
Overhanging = false;
Disappear = true;
return base.OnMouseUp(state, args);
}
}

View File

@ -1,35 +1,37 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Graphics;
namespace osu.Game.Graphics.Cursor
{
public interface IHasTooltip
public interface IHasTooltip : IDrawable
{
/// <summary>
/// Tooltip that shows when hovering the object
/// Tooltip that shows when hovering the drawable
/// </summary>
string Tooltip { get; }
string TooltipText { get; }
}
/// <summary>
/// Tooltip with custom appear time
/// </summary>
public interface IHasDelayedTooltip : IHasTooltip
public interface IHasTooltipWithCustomDelay : IHasTooltip
{
/// <summary>
/// Time until the tooltip appears (in milliseconds)
/// </summary>
int Delay { get; }
int TooltipDelay { get; }
}
/// <summary>
/// Tooltip which can show after hovering over the object
/// Tooltip which can decide when to disappear
/// </summary>
public interface IHasOverhangingTooltip : IHasTooltip
public interface IHasDisappearingTooltip : IHasTooltip
{
/// <summary>
/// Should the tooltip still show?
/// Should the tooltip disappear?
/// </summary>
bool Overhanging { get; }
bool Disappear { get; }
}
}

View File

@ -22,7 +22,9 @@ namespace osu.Game.Graphics.Cursor
private ScheduledDelegate show;
private UserInputManager input;
private IHasOverhangingTooltip overhang;
private IHasDisappearingTooltip disappearingTooltip;
public const int DEFAULT_APPEAR_DELAY = 250;
public string TooltipText {
get
@ -43,16 +45,16 @@ namespace osu.Game.Graphics.Cursor
{
set
{
if (value.Position != value.LastPosition && overhang?.Overhanging != true)
if (value.Position != value.LastPosition && disappearingTooltip?.Disappear != false)
{
show?.Cancel();
TooltipText = string.Empty;
IHasTooltip hasTooltip = input.HoveredDrawables.OfType<IHasTooltip>().FirstOrDefault();
if (hasTooltip != null)
{
IHasDelayedTooltip delayedTooltip = hasTooltip as IHasDelayedTooltip;
overhang = hasTooltip as IHasOverhangingTooltip;
show = Scheduler.AddDelayed(() => TooltipText = hasTooltip.Tooltip, delayedTooltip?.Delay ?? 250);
IHasTooltipWithCustomDelay delayedTooltip = hasTooltip as IHasTooltipWithCustomDelay;
disappearingTooltip = hasTooltip as IHasDisappearingTooltip;
show = Scheduler.AddDelayed(() => TooltipText = hasTooltip.TooltipText, delayedTooltip?.TooltipDelay ?? DEFAULT_APPEAR_DELAY);
}
}
}
@ -99,11 +101,11 @@ namespace osu.Game.Graphics.Cursor
protected override void Update()
{
if (overhang?.Overhanging ?? false)
TooltipText = overhang.Tooltip;
else if (overhang != null)
if (disappearingTooltip?.Disappear == false)
TooltipText = disappearingTooltip.TooltipText;
else if (disappearingTooltip != null)
{
overhang = null;
disappearingTooltip = null;
TooltipText = string.Empty;
}
}