renaming and some changes in TestCaseTooltip

This commit is contained in:
Jorolf
2017-04-19 13:47:00 +02:00
parent 095b6fded6
commit 4f9c5dd44d
4 changed files with 37 additions and 30 deletions

View File

@ -33,7 +33,10 @@ namespace osu.Desktop.VisualTests.Tests
Children = new Drawable[] Children = new Drawable[]
{ {
new TooltipContainer("Text with some tooltip"), new TooltipContainer("Text with some tooltip"),
new TooltipContainer("and another one"), new TooltipContainer("and another one with a custom delay")
{
TooltipDelay = 1000,
},
new TooltipTextbox new TooltipTextbox
{ {
Text = "a box with a tooltip", 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; 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) public TooltipContainer(string tooltipText)
{ {
@ -75,26 +80,24 @@ namespace osu.Desktop.VisualTests.Tests
private class TooltipTextbox : OsuTextBox, IHasTooltip 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 Disappear { get; set; } = true;
public bool Overhanging { get; set; }
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
{ {
Overhanging = true; Disappear = false;
return base.OnMouseDown(state, args); return base.OnMouseDown(state, args);
} }
protected override bool OnMouseUp(InputState state, MouseUpEventArgs args) protected override bool OnMouseUp(InputState state, MouseUpEventArgs args)
{ {
Overhanging = false; Disappear = true;
return base.OnMouseUp(state, args); return base.OnMouseUp(state, args);
} }
} }

View File

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

View File

@ -20,7 +20,7 @@ namespace osu.Game.Graphics.Cursor
protected override Drawable CreateCursor() => new Cursor(); protected override Drawable CreateCursor() => new Cursor();
private bool dragging; private bool dragging;
private Tooltip tooltip; private readonly Tooltip tooltip;
public MenuCursor() public MenuCursor()
{ {

View File

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