From c31dd7a480b437a6fe21eb073652c2190a3d2fa7 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Fri, 9 Jun 2017 14:25:23 +0800 Subject: [PATCH] Set position and color for tab control. --- osu.Game/Users/Profile/ProfileSection.cs | 2 -- osu.Game/Users/UserProfile.cs | 42 +++++++++++++++++++++--- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/osu.Game/Users/Profile/ProfileSection.cs b/osu.Game/Users/Profile/ProfileSection.cs index 904b5d77a3..ce362109cc 100644 --- a/osu.Game/Users/Profile/ProfileSection.cs +++ b/osu.Game/Users/Profile/ProfileSection.cs @@ -14,7 +14,5 @@ namespace osu.Game.Users.Profile { User = user; } - - public override string ToString() => Title; //for tab control } } diff --git a/osu.Game/Users/UserProfile.cs b/osu.Game/Users/UserProfile.cs index eaa89ce42c..cde36cbed8 100644 --- a/osu.Game/Users/UserProfile.cs +++ b/osu.Game/Users/UserProfile.cs @@ -1,10 +1,12 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // 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.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Sprites; +using osu.Framework.Graphics.UserInterface; using osu.Game.Graphics; using osu.Game.Graphics.Containers; using osu.Game.Graphics.UserInterface; @@ -16,6 +18,7 @@ namespace osu.Game.Users { private readonly User user; private ProfileSection lastSection; + private readonly ProfileTabControl tabs; public const float CONTENT_X_MARGIN = 50; @@ -32,12 +35,14 @@ namespace osu.Game.Users new BeatmapsSection(user), new KudosuSection(user) }; - var tab = new OsuTabControl + tabs = new ProfileTabControl { RelativeSizeAxes = Axes.X, + Anchor = Anchor.TopCentre, + Origin = Anchor.TopCentre, Height = 24 }; - sections.ForEach(tab.AddItem); + sections.ForEach(tabs.AddItem); Add(new Box { @@ -49,7 +54,7 @@ namespace osu.Game.Users { RelativeSizeAxes = Axes.Both, ExpandableHeader = new UserPageHeader(user), - FixedHeader = tab, + FixedHeader = tabs, HeaderBackground = new Box { Colour = OsuColour.Gray(34), @@ -64,11 +69,11 @@ namespace osu.Game.Users if (lastSection != s) { lastSection = s as ProfileSection; - tab.Current.Value = lastSection; + tabs.Current.Value = lastSection; } }; - tab.Current.ValueChanged += s => + tabs.Current.ValueChanged += 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 + { + public ProfileTabControl() + { + TabContainer.RelativeSizeAxes &= ~Axes.X; + TabContainer.AutoSizeAxes |= Axes.X; + TabContainer.Anchor |= Anchor.x1; + TabContainer.Origin |= Anchor.x1; + } + + protected override TabItem CreateTabItem(ProfileSection value) => new ProfileTabItem(value); + + private class ProfileTabItem : OsuTabItem + { + public ProfileTabItem(ProfileSection value) : base(value) + { + Text.Text = value.Title; + } + } + } } }