mirror of
https://github.com/ppy/osu.git
synced 2024-11-16 13:17:26 +08:00
985604fab5
There were no usages of more than one column being provided per row, so it seemed like unnecessarily complexity. I'm currently trying to reduce complexity so we can improve the layout of the results screen, which currently has up to three levels of nested `GridContainer`s. Of note, I can't add backwards compatibility because the method signature has not changed in `Ruleset` (only the return type). If we do want to keep compatibility with other rulesets, we could designate a new name for the updated method.
126 lines
4.0 KiB
C#
126 lines
4.0 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.
|
|
|
|
#nullable disable
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using JetBrains.Annotations;
|
|
using osu.Framework.Allocation;
|
|
using osu.Framework.Extensions.Color4Extensions;
|
|
using osu.Framework.Graphics;
|
|
using osu.Framework.Graphics.Containers;
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
namespace osu.Game.Screens.Ranking.Statistics
|
|
{
|
|
/// <summary>
|
|
/// Represents a table with simple statistics (ones that only need textual display).
|
|
/// Richer visualisations should be done with <see cref="StatisticItem"/>s.
|
|
/// </summary>
|
|
public partial class SimpleStatisticTable : CompositeDrawable
|
|
{
|
|
private readonly SimpleStatisticItem[] items;
|
|
private readonly int columnCount;
|
|
|
|
private FillFlowContainer[] columns;
|
|
|
|
/// <summary>
|
|
/// Creates a statistic row for the supplied <see cref="SimpleStatisticItem"/>s.
|
|
/// </summary>
|
|
/// <param name="columnCount">The number of columns to layout the <paramref name="items"/> into.</param>
|
|
/// <param name="items">The <see cref="SimpleStatisticItem"/>s to display in this row.</param>
|
|
public SimpleStatisticTable(int columnCount, [ItemNotNull] IEnumerable<SimpleStatisticItem> items)
|
|
{
|
|
if (columnCount < 1)
|
|
throw new ArgumentOutOfRangeException(nameof(columnCount));
|
|
|
|
this.columnCount = columnCount;
|
|
this.items = items.ToArray();
|
|
}
|
|
|
|
[BackgroundDependencyLoader]
|
|
private void load()
|
|
{
|
|
columns = new FillFlowContainer[columnCount];
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
InternalChild = new GridContainer
|
|
{
|
|
RelativeSizeAxes = Axes.X,
|
|
AutoSizeAxes = Axes.Y,
|
|
RowDimensions = new[]
|
|
{
|
|
new Dimension(GridSizeMode.AutoSize)
|
|
},
|
|
ColumnDimensions = createColumnDimensions().ToArray(),
|
|
Content = new[] { createColumns().ToArray() }
|
|
};
|
|
|
|
for (int i = 0; i < items.Length; ++i)
|
|
columns[i % columnCount].Add(items[i]);
|
|
}
|
|
|
|
private IEnumerable<Dimension> createColumnDimensions()
|
|
{
|
|
for (int column = 0; column < columnCount; ++column)
|
|
{
|
|
if (column > 0)
|
|
yield return new Dimension(GridSizeMode.Absolute, 30);
|
|
|
|
yield return new Dimension();
|
|
}
|
|
}
|
|
|
|
private IEnumerable<Drawable> createColumns()
|
|
{
|
|
for (int column = 0; column < columnCount; ++column)
|
|
{
|
|
if (column > 0)
|
|
{
|
|
yield return new Spacer
|
|
{
|
|
Alpha = items.Length > column ? 1 : 0
|
|
};
|
|
}
|
|
|
|
yield return columns[column] = createColumn();
|
|
}
|
|
}
|
|
|
|
private FillFlowContainer createColumn() => new FillFlowContainer
|
|
{
|
|
RelativeSizeAxes = Axes.X,
|
|
AutoSizeAxes = Axes.Y,
|
|
Direction = FillDirection.Vertical
|
|
};
|
|
|
|
private partial class Spacer : CompositeDrawable
|
|
{
|
|
public Spacer()
|
|
{
|
|
RelativeSizeAxes = Axes.Both;
|
|
Padding = new MarginPadding { Vertical = 4 };
|
|
|
|
InternalChild = new CircularContainer
|
|
{
|
|
RelativeSizeAxes = Axes.Y,
|
|
Width = 3,
|
|
Origin = Anchor.Centre,
|
|
Anchor = Anchor.Centre,
|
|
CornerRadius = 2,
|
|
Masking = true,
|
|
Child = new Box
|
|
{
|
|
RelativeSizeAxes = Axes.Both,
|
|
Colour = Color4Extensions.FromHex("#222")
|
|
}
|
|
};
|
|
}
|
|
}
|
|
}
|
|
}
|