Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use fixed width for digital clock display #31885

Merged
merged 1 commit into from
Feb 16, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 30 additions & 9 deletions osu.Game/Overlays/Toolbar/DigitalClockDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
using osu.Framework.Allocation;
using osu.Framework.Extensions.LocalisationExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osuTK;

namespace osu.Game.Overlays.Toolbar
{
Expand All @@ -17,6 +19,8 @@ public partial class DigitalClockDisplay : ClockDisplay
private OsuSpriteText realTime;
private OsuSpriteText gameTime;

private FillFlowContainer runningText;

private bool showRuntime = true;

public bool ShowRuntime
Expand Down Expand Up @@ -52,17 +56,36 @@ public bool Use24HourDisplay
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
AutoSizeAxes = Axes.Y;
AutoSizeAxes = Axes.Both;

InternalChildren = new Drawable[]
{
realTime = new OsuSpriteText(),
gameTime = new OsuSpriteText
realTime = new OsuSpriteText
{
Font = OsuFont.Default.With(fixedWidth: true),
Spacing = new Vector2(-1.5f, 0),
},
runningText = new FillFlowContainer
{
Y = 14,
Colour = colours.PinkLight,
Font = OsuFont.Default.With(size: 10, weight: FontWeight.SemiBold),
}
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(2, 0),
Children = new Drawable[]
{
new OsuSpriteText
{
Text = "running",
Font = OsuFont.Default.With(size: 10, weight: FontWeight.SemiBold),
},
gameTime = new OsuSpriteText
{
Font = OsuFont.Default.With(size: 10, fixedWidth: true, weight: FontWeight.SemiBold),
Spacing = new Vector2(-0.5f, 0),
}
}
},
};

updateMetrics();
Expand All @@ -71,14 +94,12 @@ private void load(OsuColour colours)
protected override void UpdateDisplay(DateTimeOffset now)
{
realTime.Text = now.ToLocalisableString(use24HourDisplay ? @"HH:mm:ss" : @"h:mm:ss tt");
gameTime.Text = $"running {new TimeSpan(TimeSpan.TicksPerSecond * (int)(Clock.CurrentTime / 1000)):c}";
gameTime.Text = $"{new TimeSpan(TimeSpan.TicksPerSecond * (int)(Clock.CurrentTime / 1000)):c}";
}

private void updateMetrics()
{
Width = showRuntime || !use24HourDisplay ? 66 : 45; // Allows for space for game time up to 99 days (in the padding area since this is quite rare).

gameTime.FadeTo(showRuntime ? 1 : 0);
runningText.FadeTo(showRuntime ? 1 : 0);
}
}
}
Loading