1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-09 10:17:24 +08:00
osu-lazer/osu.Desktop.VisualTests/Tests/TestCaseTooltip.cs

105 lines
3.3 KiB
C#
Raw Normal View History

2017-04-03 00:19:59 +08:00
// 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;
using osu.Framework.Graphics.Containers;
using osu.Framework.Testing;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Framework.Configuration;
using osu.Framework.Input;
using osu.Game.Graphics.Cursor;
using OpenTK;
2017-04-03 00:19:59 +08: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-14 06:18:17 +08:00
TooltipSlider slider;
2017-04-03 00:19:59 +08:00
Children = new Drawable[]
{
new FillFlowContainer
{
RelativeSizeAxes = Axes.Both,
Direction = FillDirection.Vertical,
2017-04-14 06:18:17 +08:00
Spacing = new Vector2(0,10),
Children = new Drawable[]
2017-04-03 00:19:59 +08:00
{
2017-04-19 21:01:05 +08:00
new TooltipTextContainer("Text with some tooltip"),
new TooltipTextContainer("and another one with a custom delay")
{
TooltipDelay = 1000,
},
new TooltipTextbox
2017-04-03 00:19:59 +08:00
{
Text = "a box with a tooltip",
2017-04-14 06:18:17 +08:00
Size = new Vector2(300,30),
2017-04-03 00:19:59 +08:00
},
2017-04-14 06:18:17 +08:00
slider = new TooltipSlider
2017-04-03 00:19:59 +08:00
{
2017-04-14 06:18:17 +08:00
Width = 300,
2017-04-03 00:19:59 +08:00
},
},
},
};
2017-04-14 06:18:17 +08:00
slider.Current.BindTo(new BindableInt(5)
{
MaxValue = 10,
MinValue = 0
});
2017-04-03 00:19:59 +08:00
}
2017-04-19 21:01:05 +08:00
private class TooltipTextContainer : Container, IHasTooltipWithCustomDelay
{
private readonly OsuSpriteText text;
public string TooltipText => text.Text;
2017-04-19 21:01:05 +08:00
public int TooltipDelay { get; set; } = TooltipContainer.DEFAULT_APPEAR_DELAY;
2017-04-19 21:01:05 +08:00
public TooltipTextContainer(string tooltipText)
{
AutoSizeAxes = Axes.Both;
Children = new[]
{
text = new OsuSpriteText
{
Text = tooltipText,
}
};
}
}
private class TooltipTextbox : OsuTextBox, IHasTooltip
2017-04-03 00:19:59 +08:00
{
public string TooltipText => Text;
2017-04-03 00:19:59 +08:00
}
private class TooltipSlider : OsuSliderBar<int>, IHasDisappearingTooltip
{
public string TooltipText => Current.Value.ToString();
public bool Disappear { get; set; } = true;
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
{
Disappear = false;
return base.OnMouseDown(state, args);
}
protected override bool OnMouseUp(InputState state, MouseUpEventArgs args)
{
Disappear = true;
return base.OnMouseUp(state, args);
}
}
2017-04-03 00:19:59 +08:00
}
}