1
0
mirror of https://github.com/ppy/osu.git synced 2026-05-19 05:09:54 +08:00

Don't use bindables when binding isn't happening

This commit is contained in:
Dean Herbert
2025-04-07 20:51:22 +09:00
Unverified
parent 0d9cff487b
commit 881785900a
3 changed files with 53 additions and 34 deletions
+37 -12
View File
@@ -3,7 +3,6 @@
using System;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osuTK;
@@ -16,14 +15,35 @@ namespace osu.Game.Overlays
/// Whether the marquee should be allowed to scroll the content if it overflows.
/// Note that upon changing the value of this, any existing scrolls will be terminated instantly.
/// </summary>
public Bindable<bool> AllowScrolling { get; } = new BindableBool(true);
public bool AllowScrolling
{
get => allowScrolling;
set
{
allowScrolling = value;
ScheduleAfterChildren(updateScrolling);
}
}
private bool allowScrolling = true;
/// <summary>
/// The <see cref="Anchor"/> to anchor the content to if it does not overflow.
/// </summary>
public Anchor NonOverflowingContentAnchor { get; init; } = Anchor.TopLeft;
public Bindable<Func<Drawable>> CreateContent = new Bindable<Func<Drawable>>();
public Func<Drawable>? CreateContent
{
set
{
createContent = value;
if (IsLoaded)
updateContent();
}
}
private Func<Drawable>? createContent;
private const float initial_move_delay = 1000;
private const float pixels_per_second = 50;
@@ -57,21 +77,26 @@ namespace osu.Game.Overlays
{
base.LoadComplete();
AllowScrolling.BindValueChanged(_ => ScheduleAfterChildren(updateScrolling));
CreateContent.BindValueChanged(_ =>
{
flow.Clear();
flow.Add(mainContent = CreateContent.Value.Invoke());
flow.Add(fillerContent = CreateContent.Value.Invoke().With(d => d.Alpha = 0));
ScheduleAfterChildren(updateScrolling);
}, true);
updateContent();
}
private void updateContent()
{
flow.Clear();
if (createContent == null)
return;
flow.Add(mainContent = createContent());
flow.Add(fillerContent = createContent().With(d => d.Alpha = 0));
ScheduleAfterChildren(updateScrolling);
}
private void updateScrolling()
{
float overflowWidth = mainContent.DrawWidth + padding - DrawWidth;
if (overflowWidth > 0 && AllowScrolling.Value)
if (overflowWidth > 0 && AllowScrolling)
{
fillerContent.Alpha = 1;
flow.Anchor = Anchor.TopLeft;
+4 -4
View File
@@ -47,7 +47,7 @@ namespace osu.Game.Overlays.Music
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
RelativeSizeAxes = Axes.X,
AllowScrolling = { Value = false }
AllowScrolling = false,
};
selectedSet.BindTo(playlistOverlay.SelectedSet);
@@ -68,7 +68,7 @@ namespace osu.Game.Overlays.Music
var title = new RomanisableString(metadata.TitleUnicode, metadata.Title);
var artist = new RomanisableString(metadata.ArtistUnicode, metadata.Artist);
text.CreateContent.Value = () =>
text.CreateContent = () =>
{
var flow = new OsuTextFlowContainer
{
@@ -113,13 +113,13 @@ namespace osu.Game.Overlays.Music
protected override bool OnHover(HoverEvent e)
{
text.AllowScrolling.Value = true;
text.AllowScrolling = true;
return true;
}
protected override void OnHoverLost(HoverLostEvent e)
{
text.AllowScrolling.Value = false;
text.AllowScrolling = false;
base.OnHoverLost(e);
}
}
+12 -18
View File
@@ -113,15 +113,12 @@ namespace osu.Game.Overlays
Anchor = Anchor.TopCentre,
Position = new Vector2(0, 40),
Colour = Color4.White,
CreateContent =
CreateContent = () => new OsuSpriteText
{
Value = () => new OsuSpriteText
{
Font = title_font,
Text = @"Nothing to play",
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
}
Font = title_font,
Text = @"Nothing to play",
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
},
NonOverflowingContentAnchor = Anchor.Centre,
},
@@ -131,15 +128,12 @@ namespace osu.Game.Overlays
Anchor = Anchor.TopCentre,
Position = new Vector2(0, 45),
Colour = Color4.White,
CreateContent =
CreateContent = () => new OsuSpriteText
{
Value = () => new OsuSpriteText
{
Font = artist_font,
Text = @"Nothing to play",
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
}
Font = artist_font,
Text = @"Nothing to play",
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
},
NonOverflowingContentAnchor = Anchor.Centre,
},
@@ -338,14 +332,14 @@ namespace osu.Game.Overlays
{
BeatmapMetadata metadata = beatmap.Metadata;
title.CreateContent.Value = () => new OsuSpriteText
title.CreateContent = () => new OsuSpriteText
{
Text = new RomanisableString(metadata.TitleUnicode, metadata.Title),
Font = title_font,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
};
artist.CreateContent.Value = () => new OsuSpriteText
artist.CreateContent = () => new OsuSpriteText
{
Text = new RomanisableString(metadata.ArtistUnicode, metadata.Artist),
Font = artist_font,