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