mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 10:12:54 +08:00
Implement bidirectional footnote link navigation
This commit is contained in:
parent
5fb2a83f12
commit
a88812861e
@ -2,12 +2,14 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Markdig.Extensions.Footnotes;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Extensions.IEnumerableExtensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers.Markdown;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Overlays;
|
||||
using osuTK;
|
||||
|
||||
@ -27,14 +29,13 @@ namespace osu.Game.Graphics.Containers.Markdown.Footnotes
|
||||
public OsuMarkdownFootnoteBacklink(FootnoteLink backlink)
|
||||
{
|
||||
this.backlink = backlink;
|
||||
AutoSizeAxes = Axes.X;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OverlayColourProvider colourProvider)
|
||||
[BackgroundDependencyLoader(true)]
|
||||
private void load(OverlayColourProvider colourProvider, OsuMarkdownContainer markdownContainer, OverlayScrollContainer? scrollContainer)
|
||||
{
|
||||
float fontSize = parentTextComponent.CreateSpriteText().Font.Size;
|
||||
Height = fontSize;
|
||||
Size = new Vector2(fontSize);
|
||||
|
||||
IdleColour = colourProvider.Light2;
|
||||
HoverColour = colourProvider.Light1;
|
||||
@ -47,6 +48,15 @@ namespace osu.Game.Graphics.Containers.Markdown.Footnotes
|
||||
Size = new Vector2(fontSize / 2),
|
||||
Icon = FontAwesome.Solid.ArrowUp,
|
||||
});
|
||||
|
||||
if (scrollContainer != null)
|
||||
{
|
||||
Action = () =>
|
||||
{
|
||||
var footnoteLink = markdownContainer.ChildrenOfType<OsuMarkdownFootnoteLink>().Single(footnoteLink => footnoteLink.FootnoteLink.Index == backlink.Index);
|
||||
scrollContainer.ScrollIntoView(footnoteLink);
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Markdig.Extensions.Footnotes;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Extensions.IEnumerableExtensions;
|
||||
@ -10,13 +11,14 @@ using osu.Framework.Graphics.Containers.Markdown;
|
||||
using osu.Framework.Graphics.Cursor;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Localisation;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Overlays;
|
||||
|
||||
namespace osu.Game.Graphics.Containers.Markdown.Footnotes
|
||||
{
|
||||
public partial class OsuMarkdownFootnoteLink : OsuHoverContainer, IHasCustomTooltip
|
||||
{
|
||||
private readonly FootnoteLink footnoteLink;
|
||||
public readonly FootnoteLink FootnoteLink;
|
||||
|
||||
private SpriteText spriteText = null!;
|
||||
|
||||
@ -33,14 +35,13 @@ namespace osu.Game.Graphics.Containers.Markdown.Footnotes
|
||||
|
||||
public OsuMarkdownFootnoteLink(FootnoteLink footnoteLink)
|
||||
{
|
||||
this.footnoteLink = footnoteLink;
|
||||
FootnoteLink = footnoteLink;
|
||||
|
||||
AutoSizeAxes = Axes.Both;
|
||||
Action = () => { }; // TODO
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
[BackgroundDependencyLoader(true)]
|
||||
private void load(OsuMarkdownContainer markdownContainer, OverlayScrollContainer? scrollContainer)
|
||||
{
|
||||
IdleColour = colourProvider.Light2;
|
||||
HoverColour = colourProvider.Light1;
|
||||
@ -52,15 +53,24 @@ namespace osu.Game.Graphics.Containers.Markdown.Footnotes
|
||||
float baseSize = t.Font.Size;
|
||||
t.Font = t.Font.With(size: baseSize * 0.58f);
|
||||
t.Margin = new MarginPadding { Bottom = 0.33f * baseSize };
|
||||
t.Text = LocalisableString.Format("[{0}]", footnoteLink.Index);
|
||||
t.Text = LocalisableString.Format("[{0}]", FootnoteLink.Index);
|
||||
}));
|
||||
|
||||
if (scrollContainer != null)
|
||||
{
|
||||
Action = () =>
|
||||
{
|
||||
var footnote = markdownContainer.ChildrenOfType<OsuMarkdownFootnote>().Single(footnote => footnote.Footnote.Label == FootnoteLink.Footnote.Label);
|
||||
scrollContainer.ScrollIntoView(footnote);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public object TooltipContent
|
||||
{
|
||||
get
|
||||
{
|
||||
var span = footnoteLink.Footnote.LastChild.Span;
|
||||
var span = FootnoteLink.Footnote.LastChild.Span;
|
||||
return markdownContainer.Text.Substring(span.Start, span.Length);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user