From deda4b5b4549b21fe7447be35da6f4509f43c325 Mon Sep 17 00:00:00 2001 From: kongehund <63306696+kongehund@users.noreply.github.com> Date: Thu, 26 Dec 2024 13:55:11 +0100 Subject: [PATCH] Scroll to toolbox group when clicked --- osu.Game/Overlays/SettingsToolboxGroup.cs | 9 ++++++ .../Edit/ExpandingToolboxContainer.cs | 28 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/osu.Game/Overlays/SettingsToolboxGroup.cs b/osu.Game/Overlays/SettingsToolboxGroup.cs index f8cf218564d3..bde2817c40ad 100644 --- a/osu.Game/Overlays/SettingsToolboxGroup.cs +++ b/osu.Game/Overlays/SettingsToolboxGroup.cs @@ -1,6 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Caching; @@ -28,6 +29,8 @@ public partial class SettingsToolboxGroup : Container, IExpandable private const int header_height = 30; private const int corner_radius = 5; + public event EventHandler? Clicked; + private readonly Cached headerTextVisibilityCache = new Cached(); protected override Container Content => content; @@ -145,6 +148,12 @@ protected override void OnHoverLost(HoverLostEvent e) base.OnHoverLost(e); } + protected override bool OnClick(ClickEvent e) + { + Clicked?.Invoke(this, EventArgs.Empty); + return base.OnClick(e); + } + protected override void Update() { base.Update(); diff --git a/osu.Game/Rulesets/Edit/ExpandingToolboxContainer.cs b/osu.Game/Rulesets/Edit/ExpandingToolboxContainer.cs index d0164ceae24b..b3ee3888b740 100644 --- a/osu.Game/Rulesets/Edit/ExpandingToolboxContainer.cs +++ b/osu.Game/Rulesets/Edit/ExpandingToolboxContainer.cs @@ -1,12 +1,14 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Input.Events; using osu.Game.Configuration; using osu.Game.Graphics.Containers; +using osu.Game.Overlays; using osu.Game.Screens.Edit; using osuTK; @@ -42,6 +44,32 @@ private void load(OsuConfigManager config) config.BindWith(OsuSetting.EditorContractSidebars, contractSidebars); } + protected override void LoadComplete() + { + foreach (EditorToolboxGroup group in Children) + { + group.Clicked += onToolboxGroupClicked; + } + base.LoadComplete(); + } + + private void onToolboxGroupClicked(object? sender, EventArgs args) + { + if (sender is not SettingsToolboxGroup toolboxGroup) + return; + + scrollToToolboxGroup(toolboxGroup); + } + + private void scrollToToolboxGroup(SettingsToolboxGroup toolboxGroup) + { + if (InternalChild is OsuScrollContainer scrollContainer) + { + float pos = scrollContainer.GetChildPosInContent(toolboxGroup); + scrollContainer.ScrollTo(pos); + } + } + protected override void Update() { base.Update();