1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-05 04:13:03 +08:00

Set position and color for tab control.

This commit is contained in:
Huo Yaoyuan 2017-06-09 14:25:23 +08:00
parent 283b6b2b5e
commit c31dd7a480
2 changed files with 37 additions and 7 deletions

View File

@ -14,7 +14,5 @@ namespace osu.Game.Users.Profile
{ {
User = user; User = user;
} }
public override string ToString() => Title; //for tab control
} }
} }

View File

@ -1,10 +1,12 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Allocation;
using osu.Framework.Extensions.IEnumerableExtensions; using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
@ -16,6 +18,7 @@ namespace osu.Game.Users
{ {
private readonly User user; private readonly User user;
private ProfileSection lastSection; private ProfileSection lastSection;
private readonly ProfileTabControl tabs;
public const float CONTENT_X_MARGIN = 50; public const float CONTENT_X_MARGIN = 50;
@ -32,12 +35,14 @@ namespace osu.Game.Users
new BeatmapsSection(user), new BeatmapsSection(user),
new KudosuSection(user) new KudosuSection(user)
}; };
var tab = new OsuTabControl<ProfileSection> tabs = new ProfileTabControl
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Height = 24 Height = 24
}; };
sections.ForEach(tab.AddItem); sections.ForEach(tabs.AddItem);
Add(new Box Add(new Box
{ {
@ -49,7 +54,7 @@ namespace osu.Game.Users
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
ExpandableHeader = new UserPageHeader(user), ExpandableHeader = new UserPageHeader(user),
FixedHeader = tab, FixedHeader = tabs,
HeaderBackground = new Box HeaderBackground = new Box
{ {
Colour = OsuColour.Gray(34), Colour = OsuColour.Gray(34),
@ -64,11 +69,11 @@ namespace osu.Game.Users
if (lastSection != s) if (lastSection != s)
{ {
lastSection = s as ProfileSection; lastSection = s as ProfileSection;
tab.Current.Value = lastSection; tabs.Current.Value = lastSection;
} }
}; };
tab.Current.ValueChanged += s => tabs.Current.ValueChanged += s =>
{ {
if (lastSection != s) if (lastSection != s)
{ {
@ -77,5 +82,32 @@ namespace osu.Game.Users
} }
}; };
} }
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
tabs.AccentColour = colours.Yellow;
}
private class ProfileTabControl : OsuTabControl<ProfileSection>
{
public ProfileTabControl()
{
TabContainer.RelativeSizeAxes &= ~Axes.X;
TabContainer.AutoSizeAxes |= Axes.X;
TabContainer.Anchor |= Anchor.x1;
TabContainer.Origin |= Anchor.x1;
}
protected override TabItem<ProfileSection> CreateTabItem(ProfileSection value) => new ProfileTabItem(value);
private class ProfileTabItem : OsuTabItem
{
public ProfileTabItem(ProfileSection value) : base(value)
{
Text.Text = value.Title;
}
}
}
} }
} }