2023-06-23 00:37:25 +08:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2021-04-28 11:53:00 +08:00
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
|
|
|
|
using Markdig.Extensions.Tables;
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers.Markdown;
|
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2021-05-06 09:43:38 +08:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2021-04-28 11:53:00 +08:00
|
|
|
|
using osu.Game.Overlays;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Graphics.Containers.Markdown
|
|
|
|
|
{
|
2022-11-24 13:32:20 +08:00
|
|
|
|
public partial class OsuMarkdownTableCell : MarkdownTableCell
|
2021-04-28 11:53:00 +08:00
|
|
|
|
{
|
|
|
|
|
private readonly bool isHeading;
|
|
|
|
|
|
|
|
|
|
public OsuMarkdownTableCell(TableCell cell, TableColumnDefinition definition, bool isHeading)
|
|
|
|
|
: base(cell, definition)
|
|
|
|
|
{
|
|
|
|
|
this.isHeading = isHeading;
|
|
|
|
|
Masking = false;
|
|
|
|
|
BorderThickness = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2021-05-07 15:54:46 +08:00
|
|
|
|
private void load()
|
2021-04-28 11:53:00 +08:00
|
|
|
|
{
|
2021-05-07 15:54:46 +08:00
|
|
|
|
AddInternal(CreateBorder(isHeading));
|
2021-04-28 11:53:00 +08:00
|
|
|
|
}
|
2021-05-06 09:43:38 +08:00
|
|
|
|
|
|
|
|
|
public override MarkdownTextFlowContainer CreateTextFlow() => new TableCellTextFlowContainer
|
|
|
|
|
{
|
|
|
|
|
Weight = isHeading ? FontWeight.Bold : FontWeight.Regular,
|
|
|
|
|
Padding = new MarginPadding(10),
|
|
|
|
|
};
|
|
|
|
|
|
2021-05-07 15:54:46 +08:00
|
|
|
|
protected virtual Box CreateBorder(bool isHeading)
|
|
|
|
|
{
|
|
|
|
|
if (isHeading)
|
|
|
|
|
return new TableHeadBorder();
|
|
|
|
|
|
|
|
|
|
return new TableBodyBorder();
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-24 13:32:20 +08:00
|
|
|
|
private partial class TableHeadBorder : Box
|
2021-05-07 15:47:46 +08:00
|
|
|
|
{
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OverlayColourProvider colourProvider)
|
|
|
|
|
{
|
|
|
|
|
Colour = colourProvider.Background3;
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
Height = 2;
|
|
|
|
|
Anchor = Anchor.BottomLeft;
|
|
|
|
|
Origin = Anchor.BottomLeft;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-24 13:32:20 +08:00
|
|
|
|
private partial class TableBodyBorder : Box
|
2021-05-07 15:47:46 +08:00
|
|
|
|
{
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OverlayColourProvider colourProvider)
|
|
|
|
|
{
|
|
|
|
|
Colour = colourProvider.Background4;
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
Height = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-24 13:32:20 +08:00
|
|
|
|
private partial class TableCellTextFlowContainer : OsuMarkdownTextFlowContainer
|
2021-05-06 09:43:38 +08:00
|
|
|
|
{
|
|
|
|
|
public FontWeight Weight { get; set; }
|
|
|
|
|
|
2021-05-07 15:38:19 +08:00
|
|
|
|
protected override SpriteText CreateSpriteText() => base.CreateSpriteText().With(t => t.Font = t.Font.With(weight: Weight));
|
2021-05-06 09:43:38 +08:00
|
|
|
|
}
|
2021-04-28 11:53:00 +08:00
|
|
|
|
}
|
|
|
|
|
}
|