1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 07:32:55 +08:00

Fix carousel items' borders getting blown out when selected and hovered

I tried restructuring the hierarchy to avoid needing this added property
(moving the hover layer out of the border container) but this leads to
some subpixel leakage outside the borders which looks even worse.

Closes #6915.
This commit is contained in:
Dean Herbert 2021-02-18 16:59:43 +09:00
parent e30fb72ee2
commit c3a98b6ad1

View File

@ -24,9 +24,13 @@ namespace osu.Game.Screens.Select.Carousel
public Container BorderContainer; public Container BorderContainer;
public readonly Bindable<CarouselItemState> State = new Bindable<CarouselItemState>(CarouselItemState.NotSelected); public readonly Bindable<CarouselItemState> State = new Bindable<CarouselItemState>(CarouselItemState.NotSelected);
private HoverLayer hoverLayer;
protected override Container<Drawable> Content { get; } = new Container { RelativeSizeAxes = Axes.Both }; protected override Container<Drawable> Content { get; } = new Container { RelativeSizeAxes = Axes.Both };
private const float corner_radius = 10;
private const float border_thickness = 2.5f;
public CarouselHeader() public CarouselHeader()
{ {
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;
@ -36,12 +40,12 @@ namespace osu.Game.Screens.Select.Carousel
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Masking = true, Masking = true,
CornerRadius = 10, CornerRadius = corner_radius,
BorderColour = new Color4(221, 255, 255, 255), BorderColour = new Color4(221, 255, 255, 255),
Children = new Drawable[] Children = new Drawable[]
{ {
Content, Content,
new HoverLayer() hoverLayer = new HoverLayer()
} }
}; };
} }
@ -59,6 +63,8 @@ namespace osu.Game.Screens.Select.Carousel
{ {
case CarouselItemState.Collapsed: case CarouselItemState.Collapsed:
case CarouselItemState.NotSelected: case CarouselItemState.NotSelected:
hoverLayer.InsetForBorder = false;
BorderContainer.BorderThickness = 0; BorderContainer.BorderThickness = 0;
BorderContainer.EdgeEffect = new EdgeEffectParameters BorderContainer.EdgeEffect = new EdgeEffectParameters
{ {
@ -70,7 +76,9 @@ namespace osu.Game.Screens.Select.Carousel
break; break;
case CarouselItemState.Selected: case CarouselItemState.Selected:
BorderContainer.BorderThickness = 2.5f; hoverLayer.InsetForBorder = true;
BorderContainer.BorderThickness = border_thickness;
BorderContainer.EdgeEffect = new EdgeEffectParameters BorderContainer.EdgeEffect = new EdgeEffectParameters
{ {
Type = EdgeEffectType.Glow, Type = EdgeEffectType.Glow,
@ -107,6 +115,26 @@ namespace osu.Game.Screens.Select.Carousel
sampleHover = audio.Samples.Get("SongSelect/song-ping"); sampleHover = audio.Samples.Get("SongSelect/song-ping");
} }
public bool InsetForBorder
{
set
{
if (value)
{
// apply same border as above to avoid applying additive overlay to it (and blowing out the colour).
Masking = true;
CornerRadius = corner_radius;
BorderThickness = border_thickness;
}
else
{
BorderThickness = 0;
CornerRadius = 0;
Masking = false;
}
}
}
protected override bool OnHover(HoverEvent e) protected override bool OnHover(HoverEvent e)
{ {
box.FadeIn(100, Easing.OutQuint); box.FadeIn(100, Easing.OutQuint);