1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-23 23:27:28 +08:00
osu-lazer/osu.Game/Graphics/Containers/Markdown/OsuMarkdownListItem.cs
Gagah Pangeran Rosfatiputra e6579352f9
add left padding for ordered list
In osu-md.less, this rule style[1] removes padding left in ordered list.
But in this rule style[2], pseudo element `::before` is used as marker
or counter and has minimal width 30px. So we use this as left padding
size.

[1] 5b0e3ac3ff/resources/assets/less/bem/osu-md.less (L196-L200)
[2] 5b0e3ac3ff/resources/assets/less/bem/osu-md.less (L210-L219)
2021-04-30 10:56:41 +07:00

82 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 osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Containers.Markdown;
using osuTK;
namespace osu.Game.Graphics.Containers.Markdown
{
public class OsuMarkdownListItem : CompositeDrawable
{
private readonly int level;
private readonly int order;
private readonly bool isOrdered;
private const float ordered_left_padding = 30;
private const float unordered_left_padding = 20;
[Resolved]
private IMarkdownTextComponent parentTextComponent { get; set; }
public FillFlowContainer Content { get; }
public OsuMarkdownListItem(int level, int order)
{
this.level = level;
this.order = order;
isOrdered = order != 0;
AutoSizeAxes = Axes.Y;
RelativeSizeAxes = Axes.X;
Padding = new MarginPadding { Left = isOrdered ? ordered_left_padding : unordered_left_padding };
InternalChildren = new Drawable[]
{
Content = new FillFlowContainer
{
AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.X,
Direction = FillDirection.Vertical,
Spacing = new Vector2(10, 10),
}
};
}
[BackgroundDependencyLoader]
private void load()
{
var marker = parentTextComponent.CreateSpriteText();
marker.Text = createTextMarker();
marker.Font = OsuFont.GetFont(size: marker.Font.Size / 2);
marker.Origin = Anchor.Centre;
marker.X = -default_left_padding / 2;
marker.Y = marker.Font.Size;
AddInternal(marker);
}
private string createTextMarker()
{
if (isOrdered)
{
return $"{order}.";
}
switch (level)
{
case 1:
return "●";
case 2:
return "○";
default:
return "■";
}
}
}
}