From f43b009b96a31d18652cd25c0546a9f2e1193a3c Mon Sep 17 00:00:00 2001 From: DrabWeb Date: Thu, 29 Mar 2018 15:29:45 -0300 Subject: [PATCH 1/4] Add optional strip to OsuTabControl. --- .../Graphics/UserInterface/OsuTabControl.cs | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/osu.Game/Graphics/UserInterface/OsuTabControl.cs b/osu.Game/Graphics/UserInterface/OsuTabControl.cs index 20385a7dae..89188b29d7 100644 --- a/osu.Game/Graphics/UserInterface/OsuTabControl.cs +++ b/osu.Game/Graphics/UserInterface/OsuTabControl.cs @@ -20,16 +20,28 @@ namespace osu.Game.Graphics.UserInterface { public class OsuTabControl : TabControl { + private readonly Box strip; + protected override Dropdown CreateDropdown() => new OsuTabDropdown(); protected override TabItem CreateTabItem(T value) => new OsuTabItem(value); + protected virtual float StripWidth() => TabContainer.Children.Sum(c => c.IsPresent ? c.DrawWidth + TabContainer.Spacing.X : 0) - TabContainer.Spacing.X; + private static bool isEnumType => typeof(T).IsEnum; public OsuTabControl() { TabContainer.Spacing = new Vector2(10f, 0f); + Add(strip = new Box + { + Anchor = Anchor.BottomLeft, + Origin = Anchor.BottomLeft, + Height = 1, + Colour = Color4.White.Opacity(0), + }); + if (isEnumType) foreach (var val in (T[])Enum.GetValues(typeof(T))) AddItem(val); @@ -57,6 +69,12 @@ namespace osu.Game.Graphics.UserInterface } } + public Color4 StripColour + { + get => strip.Colour; + set => strip.Colour = value; + } + protected override TabFillFlowContainer CreateTabFlow() => new OsuTabFillFlowContainer { Direction = FillDirection.Full, @@ -65,6 +83,15 @@ namespace osu.Game.Graphics.UserInterface Masking = true }; + protected override void UpdateAfterChildren() + { + base.UpdateAfterChildren(); + + // dont bother calculating if the strip is invisible + if (strip.Colour.MaxAlpha > 0) + strip.ResizeWidthTo(StripWidth(), 500, Easing.OutQuint); + } + public class OsuTabItem : TabItem, IHasAccentColour { protected readonly SpriteText Text; From 3d05798d8047d216c6b2aeda02beca3444effa56 Mon Sep 17 00:00:00 2001 From: DrabWeb Date: Thu, 29 Mar 2018 15:34:53 -0300 Subject: [PATCH 2/4] Change SearchableListOverlay to use OsuTabControl strip. --- osu.Game/Overlays/Direct/Header.cs | 1 - .../Overlays/SearchableList/SearchableListHeader.cs | 12 +----------- osu.Game/Overlays/Social/Header.cs | 1 - 3 files changed, 1 insertion(+), 13 deletions(-) diff --git a/osu.Game/Overlays/Direct/Header.cs b/osu.Game/Overlays/Direct/Header.cs index 2245f70ed3..252e732614 100644 --- a/osu.Game/Overlays/Direct/Header.cs +++ b/osu.Game/Overlays/Direct/Header.cs @@ -13,7 +13,6 @@ namespace osu.Game.Overlays.Direct public class Header : SearchableListHeader { protected override Color4 BackgroundColour => OsuColour.FromHex(@"252f3a"); - protected override float TabStripWidth => 298; protected override DirectTab DefaultTab => DirectTab.Search; protected override Drawable CreateHeaderText() => new OsuSpriteText { Text = @"osu!direct", TextSize = 25 }; diff --git a/osu.Game/Overlays/SearchableList/SearchableListHeader.cs b/osu.Game/Overlays/SearchableList/SearchableListHeader.cs index 0f2650ad40..e053f2f773 100644 --- a/osu.Game/Overlays/SearchableList/SearchableListHeader.cs +++ b/osu.Game/Overlays/SearchableList/SearchableListHeader.cs @@ -14,12 +14,9 @@ namespace osu.Game.Overlays.SearchableList { public abstract class SearchableListHeader : Container { - private readonly Box tabStrip; - public readonly HeaderTabControl Tabs; protected abstract Color4 BackgroundColour { get; } - protected abstract float TabStripWidth { get; } //can be removed once (if?) TabControl support auto sizing protected abstract T DefaultTab { get; } protected abstract Drawable CreateHeaderText(); protected abstract FontAwesome Icon { get; } @@ -63,13 +60,6 @@ namespace osu.Game.Overlays.SearchableList CreateHeaderText(), }, }, - tabStrip = new Box - { - Anchor = Anchor.BottomLeft, - Origin = Anchor.BottomLeft, - Width = TabStripWidth, - Height = 1, - }, Tabs = new HeaderTabControl { Anchor = Anchor.BottomLeft, @@ -87,7 +77,7 @@ namespace osu.Game.Overlays.SearchableList [BackgroundDependencyLoader] private void load(OsuColour colours) { - tabStrip.Colour = colours.Green; + Tabs.StripColour = colours.Green; } } } diff --git a/osu.Game/Overlays/Social/Header.cs b/osu.Game/Overlays/Social/Header.cs index 7bb4b4dde9..89224e1315 100644 --- a/osu.Game/Overlays/Social/Header.cs +++ b/osu.Game/Overlays/Social/Header.cs @@ -17,7 +17,6 @@ namespace osu.Game.Overlays.Social private OsuSpriteText browser; protected override Color4 BackgroundColour => OsuColour.FromHex(@"38202e"); - protected override float TabStripWidth => 438; protected override SocialTab DefaultTab => SocialTab.AllPlayers; protected override FontAwesome Icon => FontAwesome.fa_users; From e3218250d52654e912c74ee4736236fd5538301b Mon Sep 17 00:00:00 2001 From: DrabWeb Date: Thu, 29 Mar 2018 15:41:27 -0300 Subject: [PATCH 3/4] Fix tab strip in BreadcrumbControl, allow strip height to be overriden. --- osu.Game.Tests/Visual/TestCaseBreadcrumbs.cs | 20 ++++++++++++++----- .../UserInterface/BreadcrumbControl.cs | 2 ++ .../Graphics/UserInterface/OsuTabControl.cs | 3 ++- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/osu.Game.Tests/Visual/TestCaseBreadcrumbs.cs b/osu.Game.Tests/Visual/TestCaseBreadcrumbs.cs index 20bdd6736c..e3cef06f2f 100644 --- a/osu.Game.Tests/Visual/TestCaseBreadcrumbs.cs +++ b/osu.Game.Tests/Visual/TestCaseBreadcrumbs.cs @@ -2,7 +2,9 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using NUnit.Framework; +using osu.Framework.Allocation; using osu.Framework.Graphics; +using osu.Game.Graphics; using osu.Game.Graphics.UserInterface; namespace osu.Game.Tests.Visual @@ -10,10 +12,12 @@ namespace osu.Game.Tests.Visual [TestFixture] public class TestCaseBreadcrumbs : OsuTestCase { + private readonly BreadcrumbControl breadcrumbs; + public TestCaseBreadcrumbs() { - BreadcrumbControl c; - Add(c = new BreadcrumbControl + + Add(breadcrumbs = new BreadcrumbControl { Anchor = Anchor.Centre, Origin = Anchor.Centre, @@ -21,9 +25,15 @@ namespace osu.Game.Tests.Visual Width = 0.5f, }); - AddStep(@"first", () => c.Current.Value = BreadcrumbTab.Click); - AddStep(@"second", () => c.Current.Value = BreadcrumbTab.The); - AddStep(@"third", () => c.Current.Value = BreadcrumbTab.Circles); + AddStep(@"first", () => breadcrumbs.Current.Value = BreadcrumbTab.Click); + AddStep(@"second", () => breadcrumbs.Current.Value = BreadcrumbTab.The); + AddStep(@"third", () => breadcrumbs.Current.Value = BreadcrumbTab.Circles); + } + + [BackgroundDependencyLoader] + private void load(OsuColour colours) + { + breadcrumbs.StripColour = colours.Blue; } private enum BreadcrumbTab diff --git a/osu.Game/Graphics/UserInterface/BreadcrumbControl.cs b/osu.Game/Graphics/UserInterface/BreadcrumbControl.cs index 5ee0aba9cf..7f30bd715a 100644 --- a/osu.Game/Graphics/UserInterface/BreadcrumbControl.cs +++ b/osu.Game/Graphics/UserInterface/BreadcrumbControl.cs @@ -17,6 +17,8 @@ namespace osu.Game.Graphics.UserInterface protected override TabItem CreateTabItem(T value) => new BreadcrumbTabItem(value); + protected override float StripWidth() => base.StripWidth() - (padding + 8); + public BreadcrumbControl() { Height = 26; diff --git a/osu.Game/Graphics/UserInterface/OsuTabControl.cs b/osu.Game/Graphics/UserInterface/OsuTabControl.cs index 89188b29d7..1624b255e0 100644 --- a/osu.Game/Graphics/UserInterface/OsuTabControl.cs +++ b/osu.Game/Graphics/UserInterface/OsuTabControl.cs @@ -27,6 +27,7 @@ namespace osu.Game.Graphics.UserInterface protected override TabItem CreateTabItem(T value) => new OsuTabItem(value); protected virtual float StripWidth() => TabContainer.Children.Sum(c => c.IsPresent ? c.DrawWidth + TabContainer.Spacing.X : 0) - TabContainer.Spacing.X; + protected virtual float StripHeight() => 1; private static bool isEnumType => typeof(T).IsEnum; @@ -38,7 +39,7 @@ namespace osu.Game.Graphics.UserInterface { Anchor = Anchor.BottomLeft, Origin = Anchor.BottomLeft, - Height = 1, + Height = StripHeight(), Colour = Color4.White.Opacity(0), }); From 65f0e91734d847ec53c6ef7d7ebf3f442a4053be Mon Sep 17 00:00:00 2001 From: DrabWeb Date: Wed, 4 Apr 2018 03:04:26 -0300 Subject: [PATCH 4/4] Use Interpolation function directly for resizing tab strips. --- osu.Game/Graphics/UserInterface/OsuTabControl.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/osu.Game/Graphics/UserInterface/OsuTabControl.cs b/osu.Game/Graphics/UserInterface/OsuTabControl.cs index 1624b255e0..8b692f32bc 100644 --- a/osu.Game/Graphics/UserInterface/OsuTabControl.cs +++ b/osu.Game/Graphics/UserInterface/OsuTabControl.cs @@ -14,6 +14,7 @@ using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.UserInterface; using osu.Framework.Input; +using osu.Framework.MathUtils; using osu.Game.Graphics.Sprites; namespace osu.Game.Graphics.UserInterface @@ -90,7 +91,7 @@ namespace osu.Game.Graphics.UserInterface // dont bother calculating if the strip is invisible if (strip.Colour.MaxAlpha > 0) - strip.ResizeWidthTo(StripWidth(), 500, Easing.OutQuint); + strip.Width = Interpolation.ValueAt(MathHelper.Clamp(Clock.ElapsedFrameTime, 0, 1000), strip.Width, StripWidth(), 0, 500, Easing.OutQuint); } public class OsuTabItem : TabItem, IHasAccentColour