2017-04-02 16:19:59 +00:00
|
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
2017-04-13 21:00:49 +00:00
|
|
|
|
using System;
|
2017-04-02 16:19:59 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Testing;
|
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2017-04-13 21:00:49 +00:00
|
|
|
|
using osu.Framework.Configuration;
|
|
|
|
|
using osu.Framework.Input;
|
|
|
|
|
using osu.Game.Graphics.Cursor;
|
|
|
|
|
using OpenTK;
|
2017-04-02 16:19:59 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Desktop.VisualTests.Tests
|
|
|
|
|
{
|
|
|
|
|
internal class TestCaseTooltip : TestCase
|
|
|
|
|
{
|
|
|
|
|
public override string Description => "tests tooltips on various elements";
|
|
|
|
|
|
|
|
|
|
public override void Reset()
|
|
|
|
|
{
|
|
|
|
|
base.Reset();
|
2017-04-13 22:18:17 +00:00
|
|
|
|
TooltipSlider slider;
|
2017-04-02 16:19:59 +00:00
|
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Direction = FillDirection.Vertical,
|
2017-04-13 22:18:17 +00:00
|
|
|
|
Spacing = new Vector2(0,10),
|
2017-04-13 21:00:49 +00:00
|
|
|
|
Children = new Drawable[]
|
2017-04-02 16:19:59 +00:00
|
|
|
|
{
|
2017-04-13 21:00:49 +00:00
|
|
|
|
new TooltipContainer("Text with some tooltip"),
|
|
|
|
|
new TooltipContainer("and another one"),
|
|
|
|
|
new TooltipTextbox
|
2017-04-02 16:19:59 +00:00
|
|
|
|
{
|
2017-04-13 21:00:49 +00:00
|
|
|
|
Text = "a box with a tooltip",
|
2017-04-13 22:18:17 +00:00
|
|
|
|
Size = new Vector2(300,30),
|
2017-04-02 16:19:59 +00:00
|
|
|
|
},
|
2017-04-13 22:18:17 +00:00
|
|
|
|
slider = new TooltipSlider
|
2017-04-02 16:19:59 +00:00
|
|
|
|
{
|
2017-04-13 22:18:17 +00:00
|
|
|
|
Width = 300,
|
2017-04-02 16:19:59 +00:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
};
|
2017-04-13 22:18:17 +00:00
|
|
|
|
|
|
|
|
|
slider.Current.BindTo(new BindableInt(5)
|
|
|
|
|
{
|
|
|
|
|
MaxValue = 10,
|
|
|
|
|
MinValue = 0
|
|
|
|
|
});
|
2017-04-02 16:19:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-13 21:00:49 +00:00
|
|
|
|
private class TooltipContainer : Container, IHasTooltip
|
|
|
|
|
{
|
|
|
|
|
private readonly OsuSpriteText text;
|
|
|
|
|
|
|
|
|
|
public string Tooltip => text.Text;
|
|
|
|
|
|
|
|
|
|
public TooltipContainer(string tooltipText)
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
|
|
|
|
text = new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Text = tooltipText,
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class TooltipTextbox : OsuTextBox, IHasTooltip
|
2017-04-02 16:19:59 +00:00
|
|
|
|
{
|
|
|
|
|
public string Tooltip => Text;
|
|
|
|
|
}
|
2017-04-13 21:00:49 +00:00
|
|
|
|
|
2017-04-13 22:18:17 +00:00
|
|
|
|
private class TooltipSlider : OsuSliderBar<int>, IHasDelayedTooltip, IHasOverhangingTooltip
|
2017-04-13 21:00:49 +00:00
|
|
|
|
{
|
2017-04-13 22:18:17 +00:00
|
|
|
|
public string Tooltip => Current.Value.ToString();
|
2017-04-13 21:00:49 +00:00
|
|
|
|
|
2017-04-13 22:18:17 +00:00
|
|
|
|
int IHasDelayedTooltip.Delay => Overhanging ? 0 : 250;
|
2017-04-13 21:00:49 +00:00
|
|
|
|
|
2017-04-13 22:18:17 +00:00
|
|
|
|
public bool Overhanging { get; set; }
|
2017-04-13 21:00:49 +00:00
|
|
|
|
|
|
|
|
|
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
|
|
|
|
|
{
|
2017-04-13 22:18:17 +00:00
|
|
|
|
Overhanging = true;
|
2017-04-13 21:00:49 +00:00
|
|
|
|
return base.OnMouseDown(state, args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnMouseUp(InputState state, MouseUpEventArgs args)
|
|
|
|
|
{
|
2017-04-13 22:18:17 +00:00
|
|
|
|
Overhanging = false;
|
2017-04-13 21:00:49 +00:00
|
|
|
|
return base.OnMouseUp(state, args);
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-04-02 16:19:59 +00:00
|
|
|
|
}
|
|
|
|
|
}
|