2022-01-03 12:18:27 +08:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2022-01-03 12:18:27 +08:00
|
|
|
using System;
|
2022-01-20 05:30:49 +08:00
|
|
|
using osu.Framework.Graphics;
|
2022-01-03 12:18:27 +08:00
|
|
|
using osu.Framework.Input.Events;
|
|
|
|
using osu.Framework.Utils;
|
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
|
|
|
|
namespace osu.Game.Beatmaps.Drawables.Cards
|
|
|
|
{
|
|
|
|
public partial class ExpandedContentScrollContainer : OsuScrollContainer
|
|
|
|
{
|
2022-01-04 12:22:00 +08:00
|
|
|
public const float HEIGHT = 200;
|
2022-01-03 12:18:27 +08:00
|
|
|
|
2022-01-20 05:30:49 +08:00
|
|
|
protected override ScrollbarContainer CreateScrollbar(Direction direction) => new ExpandedContentScrollbar(direction);
|
|
|
|
|
2022-01-03 12:18:27 +08:00
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
Height = Math.Min(Content.DrawHeight, HEIGHT);
|
2022-01-20 05:21:05 +08:00
|
|
|
ScrollbarVisible = allowScroll;
|
2022-01-03 12:18:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private bool allowScroll => !Precision.AlmostEquals(DrawSize, Content.DrawSize);
|
|
|
|
|
|
|
|
protected override bool OnDragStart(DragStartEvent e)
|
|
|
|
{
|
|
|
|
if (!allowScroll)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return base.OnDragStart(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnDrag(DragEvent e)
|
|
|
|
{
|
|
|
|
if (!allowScroll)
|
|
|
|
return;
|
|
|
|
|
|
|
|
base.OnDrag(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnDragEnd(DragEndEvent e)
|
|
|
|
{
|
|
|
|
if (!allowScroll)
|
|
|
|
return;
|
|
|
|
|
|
|
|
base.OnDragEnd(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override bool OnScroll(ScrollEvent e)
|
|
|
|
{
|
|
|
|
if (!allowScroll)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return base.OnScroll(e);
|
|
|
|
}
|
2022-01-20 05:30:49 +08:00
|
|
|
|
2022-11-14 00:18:44 +08:00
|
|
|
protected override bool OnClick(ClickEvent e) => true;
|
|
|
|
|
2022-01-20 05:30:49 +08:00
|
|
|
private partial class ExpandedContentScrollbar : OsuScrollbar
|
|
|
|
{
|
|
|
|
public ExpandedContentScrollbar(Direction scrollDir)
|
|
|
|
: base(scrollDir)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
|
|
|
{
|
|
|
|
base.OnHover(e);
|
|
|
|
// do not handle hover, as handling hover would make the beatmap card's expanded content not-hovered
|
|
|
|
// and therefore cause it to hide when trying to drag the scroll bar.
|
|
|
|
// see: `BeatmapCardContent.dropdownContent` and its `Unhovered` handler.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2022-01-03 12:18:27 +08:00
|
|
|
}
|
|
|
|
}
|