// Copyright (c) ppy Pty Ltd . 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 { /// /// Represents a table with simple statistics (ones that only need textual display). /// Richer visualisations should be done with s. /// public partial class SimpleStatisticTable : CompositeDrawable { private readonly SimpleStatisticItem[] items; private readonly int columnCount; private FillFlowContainer[] columns; /// /// Creates a statistic row for the supplied s. /// /// The number of columns to layout the into. /// The s to display in this row. public SimpleStatisticTable(int columnCount, [ItemNotNull] IEnumerable 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 createColumnDimensions() { for (int column = 0; column < columnCount; ++column) { if (column > 0) yield return new Dimension(GridSizeMode.Absolute, 30); yield return new Dimension(); } } private IEnumerable 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; 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") } }; } } } }