mirror of https://github.com/ppy/osu
use WikiTableOfContents in WikiSidebar
This commit is contained in:
parent
55f3a328a4
commit
9f45a28623
|
@ -1,22 +1,19 @@
|
|||
// 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.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Markdig.Syntax;
|
||||
using Markdig.Syntax.Inlines;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Containers.Markdown;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
|
||||
namespace osu.Game.Overlays.Wiki
|
||||
{
|
||||
public class WikiSidebar : OverlaySidebar
|
||||
{
|
||||
private FillFlowContainer tableOfContents;
|
||||
private WikiTableOfContents tableOfContents;
|
||||
|
||||
protected override Drawable CreateContent() => new FillFlowContainer
|
||||
{
|
||||
|
@ -29,13 +26,9 @@ public class WikiSidebar : OverlaySidebar
|
|||
{
|
||||
Text = "CONTENTS",
|
||||
Font = OsuFont.GetFont(size: 12, weight: FontWeight.Bold),
|
||||
Margin = new MarginPadding { Bottom = 5 },
|
||||
},
|
||||
tableOfContents = new FillFlowContainer
|
||||
{
|
||||
Direction = FillDirection.Vertical,
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
}
|
||||
tableOfContents = new WikiTableOfContents(),
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -45,8 +38,7 @@ public void AddEntry(HeadingBlock headingBlock, MarkdownHeading heading)
|
|||
{
|
||||
case 2:
|
||||
case 3:
|
||||
string title = getTitle(headingBlock.Inline);
|
||||
tableOfContents.Add(new TableOfContentsEntry(title, heading, headingBlock.Level == 3));
|
||||
tableOfContents.AddEntry(getTitle(headingBlock.Inline), heading, headingBlock.Level == 3);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -70,44 +62,5 @@ private string getTitle(ContainerInline containerInline)
|
|||
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
private class TableOfContentsEntry : OsuHoverContainer
|
||||
{
|
||||
[Resolved]
|
||||
private OverlayColourProvider colourProvider { get; set; }
|
||||
|
||||
private readonly MarkdownHeading target;
|
||||
|
||||
private readonly OsuTextFlowContainer textFlow;
|
||||
|
||||
public TableOfContentsEntry(string text, MarkdownHeading target, bool subtitle = false)
|
||||
{
|
||||
this.target = target;
|
||||
|
||||
RelativeSizeAxes = Axes.X;
|
||||
AutoSizeAxes = Axes.Y;
|
||||
Child = textFlow = new OsuTextFlowContainer(t =>
|
||||
{
|
||||
t.Font = OsuFont.GetFont(size: subtitle ? 12 : 15);
|
||||
}).With(f =>
|
||||
{
|
||||
f.AddText(text);
|
||||
f.RelativeSizeAxes = Axes.X;
|
||||
f.AutoSizeAxes = Axes.Y;
|
||||
});
|
||||
Margin = new MarginPadding { Top = subtitle ? 5 : 10 };
|
||||
Padding = new MarginPadding { Left = subtitle ? 10 : 0 };
|
||||
}
|
||||
|
||||
protected override IEnumerable<Drawable> EffectTargets => new Drawable[] { textFlow };
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OverlayScrollContainer scrollContainer)
|
||||
{
|
||||
IdleColour = colourProvider.Light2;
|
||||
HoverColour = colourProvider.Light1;
|
||||
Action = () => scrollContainer.ScrollTo(target);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue