1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 11:07:52 +08:00

Merge pull request #26924 from EVAST9919/user-card-containers

Rework `UserPanel`s to reduce container nesting
This commit is contained in:
Bartłomiej Dach 2024-02-05 18:46:42 +01:00 committed by GitHub
commit 1582536f04
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 136 additions and 147 deletions

View File

@ -2,14 +2,15 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Overlays; using osu.Game.Overlays;
namespace osu.Game.Tests.Visual.Online namespace osu.Game.Tests.Visual.Online
{ {
public partial class TestSceneDashboardOverlay : OsuTestScene public partial class TestSceneDashboardOverlay : OsuTestScene
{ {
protected override bool UseOnlineAPI => true;
private readonly DashboardOverlay overlay; private readonly DashboardOverlay overlay;
public TestSceneDashboardOverlay() public TestSceneDashboardOverlay()
@ -17,6 +18,30 @@ namespace osu.Game.Tests.Visual.Online
Add(overlay = new DashboardOverlay()); Add(overlay = new DashboardOverlay());
} }
[BackgroundDependencyLoader]
private void load()
{
int supportLevel = 0;
for (int i = 0; i < 1000; i++)
{
supportLevel++;
if (supportLevel > 3)
supportLevel = 0;
((DummyAPIAccess)API).Friends.Add(new APIUser
{
Username = @"peppy",
Id = 2,
Colour = "99EB47",
CoverUrl = @"https://osu.ppy.sh/images/headers/profile-covers/c3.jpg",
IsSupporter = supportLevel > 0,
SupportLevel = supportLevel
});
}
}
[Test] [Test]
public void TestShow() public void TestShow()
{ {

View File

@ -35,98 +35,84 @@ namespace osu.Game.Users
{ {
FillFlowContainer details; FillFlowContainer details;
var layout = new Container var layout = new GridContainer
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding(margin), Padding = new MarginPadding(margin),
Child = new GridContainer ColumnDimensions = new[]
{ {
RelativeSizeAxes = Axes.Both, new Dimension(GridSizeMode.AutoSize),
ColumnDimensions = new[] new Dimension()
},
RowDimensions = new[]
{
new Dimension(GridSizeMode.AutoSize),
new Dimension()
},
Content = new[]
{
new Drawable[]
{ {
new Dimension(GridSizeMode.AutoSize), CreateAvatar().With(avatar =>
new Dimension()
},
RowDimensions = new[]
{
new Dimension(GridSizeMode.AutoSize),
new Dimension(GridSizeMode.Absolute, margin),
new Dimension()
},
Content = new[]
{
new Drawable[]
{ {
CreateAvatar().With(avatar => avatar.Size = new Vector2(60);
avatar.Masking = true;
avatar.CornerRadius = 6;
avatar.Margin = new MarginPadding { Bottom = margin };
}),
new GridContainer
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Left = margin, Bottom = margin },
ColumnDimensions = new[]
{ {
avatar.Size = new Vector2(60); new Dimension()
avatar.Masking = true; },
avatar.CornerRadius = 6; RowDimensions = new[]
}),
new Container
{ {
RelativeSizeAxes = Axes.Both, new Dimension(GridSizeMode.AutoSize),
Padding = new MarginPadding { Left = margin }, new Dimension()
Child = new GridContainer },
Content = new[]
{
new Drawable[]
{ {
RelativeSizeAxes = Axes.Both, details = new FillFlowContainer
ColumnDimensions = new[]
{ {
new Dimension() AutoSizeAxes = Axes.Both,
}, Direction = FillDirection.Horizontal,
RowDimensions = new[] Spacing = new Vector2(6),
{ Children = new Drawable[]
new Dimension(GridSizeMode.AutoSize),
new Dimension()
},
Content = new[]
{
new Drawable[]
{ {
details = new FillFlowContainer CreateFlag(),
{ // supporter icon is being added later
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(6),
Children = new Drawable[]
{
CreateFlag(),
// supporter icon is being added later
}
}
},
new Drawable[]
{
CreateUsername().With(username =>
{
username.Anchor = Anchor.CentreLeft;
username.Origin = Anchor.CentreLeft;
})
} }
} }
},
new Drawable[]
{
CreateUsername().With(username =>
{
username.Anchor = Anchor.CentreLeft;
username.Origin = Anchor.CentreLeft;
})
} }
} }
},
new[]
{
// padding
Empty(),
Empty()
},
new Drawable[]
{
CreateStatusIcon().With(icon =>
{
icon.Anchor = Anchor.Centre;
icon.Origin = Anchor.Centre;
}),
CreateStatusMessage(false).With(message =>
{
message.Anchor = Anchor.CentreLeft;
message.Origin = Anchor.CentreLeft;
message.Margin = new MarginPadding { Left = margin };
})
} }
},
new Drawable[]
{
CreateStatusIcon().With(icon =>
{
icon.Anchor = Anchor.Centre;
icon.Origin = Anchor.Centre;
}),
CreateStatusMessage(false).With(message =>
{
message.Anchor = Anchor.CentreLeft;
message.Origin = Anchor.CentreLeft;
message.Margin = new MarginPadding { Left = margin };
})
} }
} }
}; };

View File

@ -81,117 +81,95 @@ namespace osu.Game.Users
}, },
new GridContainer new GridContainer
{ {
AutoSizeAxes = Axes.Y, RelativeSizeAxes = Axes.Both,
RelativeSizeAxes = Axes.X, Padding = new MarginPadding(padding),
ColumnDimensions = new[] ColumnDimensions = new[]
{ {
new Dimension(GridSizeMode.Absolute, padding),
new Dimension(GridSizeMode.AutoSize), new Dimension(GridSizeMode.AutoSize),
new Dimension(), new Dimension(),
new Dimension(GridSizeMode.Absolute, padding),
}, },
RowDimensions = new[] RowDimensions = new[]
{ {
new Dimension(GridSizeMode.Absolute, padding), new Dimension()
new Dimension(GridSizeMode.AutoSize),
}, },
Content = new[] Content = new[]
{ {
new[] new Drawable[]
{ {
// padding
Empty(),
Empty(),
Empty(),
Empty()
},
new[]
{
Empty(), // padding
CreateAvatar().With(avatar => CreateAvatar().With(avatar =>
{ {
avatar.Size = new Vector2(60); avatar.Size = new Vector2(60);
avatar.Masking = true; avatar.Masking = true;
avatar.CornerRadius = 6; avatar.CornerRadius = 6;
}), }),
new Container new GridContainer
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Left = padding }, Padding = new MarginPadding { Left = padding },
Child = new GridContainer ColumnDimensions = new[]
{ {
RelativeSizeAxes = Axes.Both, new Dimension()
ColumnDimensions = new[] },
RowDimensions = new[]
{
new Dimension(GridSizeMode.AutoSize),
new Dimension()
},
Content = new[]
{
new Drawable[]
{ {
new Dimension() details = new FillFlowContainer
},
RowDimensions = new[]
{
new Dimension(GridSizeMode.AutoSize),
new Dimension()
},
Content = new[]
{
new Drawable[]
{ {
details = new FillFlowContainer AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(6),
Children = new Drawable[]
{ {
AutoSizeAxes = Axes.Both, CreateFlag(),
Direction = FillDirection.Horizontal, // supporter icon is being added later
Spacing = new Vector2(6),
Children = new Drawable[]
{
CreateFlag(),
// supporter icon is being added later
}
} }
},
new Drawable[]
{
CreateUsername().With(username =>
{
username.Anchor = Anchor.CentreLeft;
username.Origin = Anchor.CentreLeft;
})
} }
},
new Drawable[]
{
CreateUsername().With(username =>
{
username.Anchor = Anchor.CentreLeft;
username.Origin = Anchor.CentreLeft;
})
} }
} }
}, }
Empty() // padding
} }
} }
} }
} }
}, },
new Container new GridContainer
{ {
Name = "Bottom content", Name = "Bottom content",
Margin = new MarginPadding { Top = main_content_height }, Margin = new MarginPadding { Top = main_content_height },
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y, AutoSizeAxes = Axes.Y,
Padding = new MarginPadding { Left = 80, Vertical = padding }, Padding = new MarginPadding { Left = 80, Vertical = padding },
Child = new GridContainer ColumnDimensions = new[]
{ {
RelativeSizeAxes = Axes.X, new Dimension(),
AutoSizeAxes = Axes.Y, new Dimension()
ColumnDimensions = new[] },
RowDimensions = new[] { new Dimension(GridSizeMode.AutoSize) },
Content = new[]
{
new Drawable[]
{ {
new Dimension(), globalRankDisplay = new ProfileValueDisplay(true)
new Dimension()
},
RowDimensions = new[] { new Dimension(GridSizeMode.AutoSize) },
Content = new[]
{
new Drawable[]
{ {
globalRankDisplay = new ProfileValueDisplay(true) Title = UsersStrings.ShowRankGlobalSimple,
{ },
Title = UsersStrings.ShowRankGlobalSimple, countryRankDisplay = new ProfileValueDisplay(true)
}, {
countryRankDisplay = new ProfileValueDisplay(true) Title = UsersStrings.ShowRankCountrySimple,
{
Title = UsersStrings.ShowRankCountrySimple,
}
} }
} }
} }