Skip to content

Commit

Permalink
Scroll to toolbox group when clicked
Browse files Browse the repository at this point in the history
  • Loading branch information
kongehund committed Dec 26, 2024
1 parent d37b4bc commit deda4b5
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
9 changes: 9 additions & 0 deletions osu.Game/Overlays/SettingsToolboxGroup.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. 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;
Expand Down Expand Up @@ -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<Drawable> Content => content;
Expand Down Expand Up @@ -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();
Expand Down
28 changes: 28 additions & 0 deletions osu.Game/Rulesets/Edit/ExpandingToolboxContainer.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. 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;

Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit deda4b5

Please sign in to comment.