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

Explicitly implement tooltips on date drawables to avoid "convert to auto-property" inspections

This commit is contained in:
Salman Ahmed 2021-08-31 20:06:34 +03:00
parent da7ff4b160
commit 69c23a2371
3 changed files with 23 additions and 17 deletions

View File

@ -142,13 +142,11 @@ namespace osu.Game.Overlays.Dashboard.Home.News
private class Date : CompositeDrawable, IHasCustomTooltip<DateTimeOffset> private class Date : CompositeDrawable, IHasCustomTooltip<DateTimeOffset>
{ {
public ITooltip<DateTimeOffset> GetCustomTooltip() => new DateTooltip(); private readonly DateTimeOffset date;
public DateTimeOffset TooltipContent { get; }
public Date(DateTimeOffset date) public Date(DateTimeOffset date)
{ {
TooltipContent = date; this.date = date;
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
@ -172,7 +170,7 @@ namespace osu.Game.Overlays.Dashboard.Home.News
Origin = Anchor.TopRight, Origin = Anchor.TopRight,
Font = OsuFont.GetFont(weight: FontWeight.Bold), // using Bold since there is no 800 weight alternative Font = OsuFont.GetFont(weight: FontWeight.Bold), // using Bold since there is no 800 weight alternative
Colour = colourProvider.Light1, Colour = colourProvider.Light1,
Text = $"{TooltipContent:dd}" Text = $"{date:dd}"
}, },
new TextFlowContainer(f => new TextFlowContainer(f =>
{ {
@ -183,11 +181,15 @@ namespace osu.Game.Overlays.Dashboard.Home.News
Anchor = Anchor.TopRight, Anchor = Anchor.TopRight,
Origin = Anchor.TopRight, Origin = Anchor.TopRight,
AutoSizeAxes = Axes.Both, AutoSizeAxes = Axes.Both,
Text = $"{TooltipContent:MMM yyyy}" Text = $"{date:MMM yyyy}"
} }
} }
}; };
} }
ITooltip<DateTimeOffset> IHasCustomTooltip<DateTimeOffset>.GetCustomTooltip() => new DateTooltip();
DateTimeOffset IHasCustomTooltip<DateTimeOffset>.TooltipContent => date;
} }
} }
} }

View File

@ -69,13 +69,11 @@ namespace osu.Game.Overlays.Dashboard.Home.News
private class Date : CompositeDrawable, IHasCustomTooltip<DateTimeOffset> private class Date : CompositeDrawable, IHasCustomTooltip<DateTimeOffset>
{ {
public ITooltip<DateTimeOffset> GetCustomTooltip() => new DateTooltip(); private readonly DateTimeOffset date;
public DateTimeOffset TooltipContent { get; }
public Date(DateTimeOffset date) public Date(DateTimeOffset date)
{ {
TooltipContent = date; this.date = date;
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
@ -98,16 +96,20 @@ namespace osu.Game.Overlays.Dashboard.Home.News
Margin = new MarginPadding { Vertical = 5 } Margin = new MarginPadding { Vertical = 5 }
}; };
textFlow.AddText($"{TooltipContent:dd}", t => textFlow.AddText($"{date:dd}", t =>
{ {
t.Font = OsuFont.GetFont(size: 14, weight: FontWeight.Bold); t.Font = OsuFont.GetFont(size: 14, weight: FontWeight.Bold);
}); });
textFlow.AddText($"{TooltipContent: MMM}", t => textFlow.AddText($"{date: MMM}", t =>
{ {
t.Font = OsuFont.GetFont(size: 14, weight: FontWeight.Regular); t.Font = OsuFont.GetFont(size: 14, weight: FontWeight.Regular);
}); });
} }
ITooltip<DateTimeOffset> IHasCustomTooltip<DateTimeOffset>.GetCustomTooltip() => new DateTooltip();
DateTimeOffset IHasCustomTooltip<DateTimeOffset>.TooltipContent => date;
} }
} }
} }

View File

@ -125,13 +125,11 @@ namespace osu.Game.Overlays.News
private class DateContainer : CircularContainer, IHasCustomTooltip<DateTimeOffset> private class DateContainer : CircularContainer, IHasCustomTooltip<DateTimeOffset>
{ {
public ITooltip<DateTimeOffset> GetCustomTooltip() => new DateTooltip(); private readonly DateTimeOffset date;
public DateTimeOffset TooltipContent { get; }
public DateContainer(DateTimeOffset date) public DateContainer(DateTimeOffset date)
{ {
TooltipContent = date; this.date = date;
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
@ -148,7 +146,7 @@ namespace osu.Game.Overlays.News
}, },
new OsuSpriteText new OsuSpriteText
{ {
Text = TooltipContent.ToString("d MMM yyyy").ToUpper(), Text = date.ToString("d MMM yyyy").ToUpper(),
Font = OsuFont.GetFont(size: 10, weight: FontWeight.SemiBold), Font = OsuFont.GetFont(size: 10, weight: FontWeight.SemiBold),
Margin = new MarginPadding Margin = new MarginPadding
{ {
@ -160,6 +158,10 @@ namespace osu.Game.Overlays.News
} }
protected override bool OnClick(ClickEvent e) => true; // Protects the NewsCard from clicks while hovering DateContainer protected override bool OnClick(ClickEvent e) => true; // Protects the NewsCard from clicks while hovering DateContainer
ITooltip<DateTimeOffset> IHasCustomTooltip<DateTimeOffset>.GetCustomTooltip() => new DateTooltip();
DateTimeOffset IHasCustomTooltip<DateTimeOffset>.TooltipContent => date;
} }
} }
} }