1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-30 07:47:35 +08:00
osu-lazer/osu.Game/Overlays/Wiki/Markdown/WikiMarkdownImageBlock.cs
Gagah Pangeran Rosfatiputra e58f690210
centering image sprite
2021-06-28 21:09:00 +07:00

75 lines
2.3 KiB
C#

// 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 Markdig.Syntax.Inlines;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Containers.Markdown;
using osu.Framework.Graphics.Sprites;
using osuTK;
namespace osu.Game.Overlays.Wiki.Markdown
{
public class WikiMarkdownImageBlock : FillFlowContainer
{
[Resolved]
private IMarkdownTextComponent parentTextComponent { get; set; }
private readonly LinkInline linkInline;
public WikiMarkdownImageBlock(LinkInline linkInline)
{
this.linkInline = linkInline;
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
Direction = FillDirection.Vertical;
Spacing = new Vector2(0, 3);
}
[BackgroundDependencyLoader]
private void load()
{
Children = new Drawable[]
{
new BlockMarkdownImage(linkInline),
parentTextComponent.CreateSpriteText().With(t =>
{
t.Text = linkInline.Title;
t.Anchor = Anchor.TopCentre;
t.Origin = Anchor.TopCentre;
}),
};
}
private class BlockMarkdownImage : WikiMarkdownImage
{
public BlockMarkdownImage(LinkInline linkInline)
: base(linkInline)
{
AutoSizeAxes = Axes.Y;
RelativeSizeAxes = Axes.X;
}
protected override ImageContainer CreateImageContainer(string url) => new BlockImageContainer(url);
private class BlockImageContainer : ImageContainer
{
public BlockImageContainer(string url)
: base(url)
{
AutoSizeAxes = Axes.Y;
RelativeSizeAxes = Axes.X;
}
protected override Sprite CreateSpriteImage() => base.CreateSpriteImage().With(s =>
{
s.Anchor = Anchor.TopCentre;
s.Origin = Anchor.TopCentre;
});
}
}
}
}