From 58e236a2471f2f815f947fe5141d3feaa5046de8 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Mon, 8 Jul 2024 08:48:52 +0300 Subject: [PATCH] Add transition to dropdown chevrons --- osu.Game/Collections/CollectionDropdown.cs | 2 +- .../Graphics/UserInterface/OsuDropdown.cs | 25 ++++++++++++++++--- .../Music/NowPlayingCollectionDropdown.cs | 4 +-- .../Overlays/Rankings/SpotlightSelector.cs | 2 +- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/osu.Game/Collections/CollectionDropdown.cs b/osu.Game/Collections/CollectionDropdown.cs index c04689b097..6d8f65c257 100644 --- a/osu.Game/Collections/CollectionDropdown.cs +++ b/osu.Game/Collections/CollectionDropdown.cs @@ -163,7 +163,7 @@ namespace osu.Game.Collections public CollectionDropdownHeader() { Height = 25; - Icon.Size = new Vector2(16); + Chevron.Size = new Vector2(16); Foreground.Padding = new MarginPadding { Top = 4, Bottom = 4, Left = 8, Right = 4 }; } } diff --git a/osu.Game/Graphics/UserInterface/OsuDropdown.cs b/osu.Game/Graphics/UserInterface/OsuDropdown.cs index c8bb45b59d..562258f5b2 100644 --- a/osu.Game/Graphics/UserInterface/OsuDropdown.cs +++ b/osu.Game/Graphics/UserInterface/OsuDropdown.cs @@ -30,6 +30,12 @@ namespace osu.Game.Graphics.UserInterface protected override DropdownMenu CreateMenu() => new OsuDropdownMenu(); + public OsuDropdown() + { + if (Header is OsuDropdownHeader osuHeader) + osuHeader.Dropdown = this; + } + public bool OnPressed(KeyBindingPressEvent e) { if (e.Repeat) return false; @@ -307,7 +313,9 @@ namespace osu.Game.Graphics.UserInterface set => Text.Text = value; } - protected readonly SpriteIcon Icon; + protected readonly SpriteIcon Chevron; + + public OsuDropdown? Dropdown { get; set; } public OsuDropdownHeader() { @@ -341,7 +349,7 @@ namespace osu.Game.Graphics.UserInterface Origin = Anchor.CentreLeft, RelativeSizeAxes = Axes.X, }, - Icon = new SpriteIcon + Chevron = new SpriteIcon { Icon = FontAwesome.Solid.ChevronDown, Anchor = Anchor.CentreRight, @@ -365,6 +373,9 @@ namespace osu.Game.Graphics.UserInterface { base.LoadComplete(); + if (Dropdown != null) + Dropdown.Menu.StateChanged += _ => updateChevron(); + SearchBar.State.ValueChanged += _ => updateColour(); Enabled.BindValueChanged(_ => updateColour()); updateColour(); @@ -392,16 +403,22 @@ namespace osu.Game.Graphics.UserInterface if (SearchBar.State.Value == Visibility.Visible) { - Icon.Colour = hovered ? hoveredColour.Lighten(0.5f) : Colour4.White; + Chevron.Colour = hovered ? hoveredColour.Lighten(0.5f) : Colour4.White; Background.Colour = unhoveredColour; } else { - Icon.Colour = Color4.White; + Chevron.Colour = Color4.White; Background.Colour = hovered ? hoveredColour : unhoveredColour; } } + private void updateChevron() + { + bool open = Dropdown?.Menu.State == MenuState.Open; + Chevron.ScaleTo(open ? new Vector2(1f, -1f) : Vector2.One, 300, Easing.OutQuint); + } + protected override DropdownSearchBar CreateSearchBar() => new OsuDropdownSearchBar { Padding = new MarginPadding { Right = 26 }, diff --git a/osu.Game/Overlays/Music/NowPlayingCollectionDropdown.cs b/osu.Game/Overlays/Music/NowPlayingCollectionDropdown.cs index fa9a2e3972..0f2e9400d9 100644 --- a/osu.Game/Overlays/Music/NowPlayingCollectionDropdown.cs +++ b/osu.Game/Overlays/Music/NowPlayingCollectionDropdown.cs @@ -53,8 +53,8 @@ namespace osu.Game.Overlays.Music { CornerRadius = 5; Height = 30; - Icon.Size = new Vector2(14); - Icon.Margin = new MarginPadding(0); + Chevron.Size = new Vector2(14); + Chevron.Margin = new MarginPadding(0); Foreground.Padding = new MarginPadding { Top = 4, Bottom = 4, Left = 10, Right = 10 }; EdgeEffect = new EdgeEffectParameters { diff --git a/osu.Game/Overlays/Rankings/SpotlightSelector.cs b/osu.Game/Overlays/Rankings/SpotlightSelector.cs index 190da04a5d..69dc8aba85 100644 --- a/osu.Game/Overlays/Rankings/SpotlightSelector.cs +++ b/osu.Game/Overlays/Rankings/SpotlightSelector.cs @@ -200,7 +200,7 @@ namespace osu.Game.Overlays.Rankings Text.Font = OsuFont.GetFont(size: 15); Text.Padding = new MarginPadding { Vertical = 1.5f }; // osu-web line-height difference compensation Foreground.Padding = new MarginPadding { Horizontal = 10, Vertical = 15 }; - Margin = Icon.Margin = new MarginPadding(0); + Margin = Chevron.Margin = new MarginPadding(0); } [BackgroundDependencyLoader]