Skip to content

Commit

Permalink
Merge pull request #30101 from bdach/menu-padding-left
Browse files Browse the repository at this point in the history
Do not add checkbox padding to the left of menu items if no item actually needs it
  • Loading branch information
bdach authored Oct 4, 2024
2 parents 4fc0aae + e136568 commit 96b6780
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
6 changes: 6 additions & 0 deletions osu.Game/Graphics/UserInterface/DrawableOsuMenuItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
Expand All @@ -26,6 +27,8 @@ public partial class DrawableOsuMenuItem : Menu.DrawableMenuItem
public const int TEXT_SIZE = 17;
public const int TRANSITION_LENGTH = 80;

public BindableBool ShowCheckbox { get; } = new BindableBool();

private TextContainer text;
private HotkeyDisplay hotkey;
private HoverClickSounds hoverClickSounds;
Expand Down Expand Up @@ -72,6 +75,7 @@ protected override void LoadComplete()
{
base.LoadComplete();

ShowCheckbox.BindValueChanged(_ => updateState());
Item.Action.BindDisabledChanged(_ => updateState(), true);
FinishTransforms();
}
Expand Down Expand Up @@ -138,6 +142,8 @@ private void updateState()
text.BoldText.FadeOut(TRANSITION_LENGTH, Easing.OutQuint);
text.NormalText.FadeIn(TRANSITION_LENGTH, Easing.OutQuint);
}

text.CheckboxContainer.Alpha = ShowCheckbox.Value ? 1 : 0;
}

protected sealed override Drawable CreateContent() => text = CreateTextContainer();
Expand Down
19 changes: 19 additions & 0 deletions osu.Game/Graphics/UserInterface/OsuMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,25 @@ private void load(AudioManager audio)
sampleClose = audio.Samples.Get(@"UI/dropdown-close");
}

protected override void Update()
{
base.Update();

bool showCheckboxes = false;

foreach (var drawableItem in ItemsContainer)
{
if (drawableItem.Item is StatefulMenuItem)
showCheckboxes = true;
}

foreach (var drawableItem in ItemsContainer)
{
if (drawableItem is DrawableOsuMenuItem osuItem)
osuItem.ShowCheckbox.Value = showCheckboxes;
}
}

protected override void AnimateOpen()
{
if (!TopLevelMenu && !wasOpened)
Expand Down

0 comments on commit 96b6780

Please sign in to comment.