Skip to content

Commit

Permalink
Merge pull request #26086 from peppy/fix-toolbar-button-lag
Browse files Browse the repository at this point in the history
Use a realm subscription to avoid overhead when hovering a toolbar button
  • Loading branch information
peppy authored Dec 23, 2023
2 parents a0915a0 + 68430d6 commit ee00f7e
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions osu.Game/Overlays/Toolbar/ToolbarButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,15 @@ protected ToolbarButton()
};
}

[BackgroundDependencyLoader]
private void load()
{
if (Hotkey != null)
{
realm.SubscribeToPropertyChanged(r => r.All<RealmKeyBinding>().FirstOrDefault(rkb => rkb.RulesetName == null && rkb.ActionInt == (int)Hotkey.Value), kb => kb.KeyCombinationString, updateKeyBindingTooltip);
}
}

protected override bool OnMouseDown(MouseDownEvent e) => false;

protected override bool OnClick(ClickEvent e)
Expand All @@ -168,8 +177,6 @@ protected override bool OnClick(ClickEvent e)

protected override bool OnHover(HoverEvent e)
{
updateKeyBindingTooltip();

HoverBackground.FadeIn(200);
tooltipContainer.FadeIn(100);

Expand Down Expand Up @@ -197,19 +204,13 @@ public void OnReleased(KeyBindingReleaseEvent<GlobalAction> e)
{
}

private void updateKeyBindingTooltip()
private void updateKeyBindingTooltip(string keyCombination)
{
if (Hotkey == null) return;

var realmKeyBinding = realm.Realm.All<RealmKeyBinding>().FirstOrDefault(rkb => rkb.RulesetName == null && rkb.ActionInt == (int)Hotkey.Value);
string keyBindingString = keyCombinationProvider.GetReadableString(keyCombination);

if (realmKeyBinding != null)
{
string keyBindingString = keyCombinationProvider.GetReadableString(realmKeyBinding.KeyCombination);

if (!string.IsNullOrEmpty(keyBindingString))
keyBindingTooltip.Text = $" ({keyBindingString})";
}
keyBindingTooltip.Text = !string.IsNullOrEmpty(keyBindingString)
? $" ({keyBindingString})"
: string.Empty;
}
}

Expand Down

0 comments on commit ee00f7e

Please sign in to comment.