fix(scoreboard): the defaults were never applied — a record struct zero-initialises

Creator's defaults: white text, Background ON (black, 20%), speed capped at 200 px/s, text size shown
in real pixels, and "plate" dropped from the label.

The important find is underneath those: `ScoreboardStyle` is a record STRUCT, and `new
ScoreboardStyle()` zero-initialises — it does NOT run the constructor's parameter defaults. So the
shipped strip had null text colour, NO background and zero opacity, whatever the source said. That is
why the Background checkbox and the opacity slider looked like they had no code behind them: the
renderer was faithfully drawing the zeros it was handed.

An explicit parameterless constructor now carries the real defaults, and the renderer test asserts
them (white / on / black / 0.20 / max speed 200) so this class of silent-zero cannot return.

Readouts fixed too: the opacity and text-size setters never raised their own property, so the numbers
never moved while the render did. Text size now reads "24 px" instead of a bare slider value, and
snaps to whole pixels.
This commit is contained in:
2026-10-30 15:24:14 -07:00
parent 28525c90aa
commit c03acd0aa0
6 changed files with 43 additions and 9 deletions
+5 -5
View File
@@ -485,7 +485,7 @@
<TextBlock DockPanel.Dock="Right" Width="56" TextAlignment="Right" FontSize="11"
Foreground="{StaticResource Brush.OnSurfaceVariant}" VerticalAlignment="Center"
Text="{Binding ScoreboardScrollSpeed, StringFormat={}{0:0} px/s}"/>
<Slider Minimum="20" Maximum="400" SmallChange="10" LargeChange="40"
<Slider Minimum="20" Maximum="200" SmallChange="10" LargeChange="40"
Value="{Binding ScoreboardScrollSpeed, Mode=TwoWay}" VerticalAlignment="Center"/>
</DockPanel>
@@ -514,7 +514,7 @@
ItemsSource="{Binding ScoreboardColorOptions}" DisplayMemberPath="Name"
SelectedValuePath="Hex" SelectedValue="{Binding ScoreboardTextColor, Mode=TwoWay}"/>
<CheckBox Style="{StaticResource YtCheckBox}" Content="Background plate" Margin="10,0,0,4"
<CheckBox Style="{StaticResource YtCheckBox}" Content="Background" Margin="10,0,0,4"
IsChecked="{Binding ScoreboardBackgroundEnabled, Mode=TwoWay}"/>
<ComboBox Style="{StaticResource YtComboBox}" Height="24" FontSize="11" Margin="10,0,0,6"
ItemsSource="{Binding ScoreboardColorOptions}" DisplayMemberPath="Name"
@@ -532,10 +532,10 @@
<DockPanel Margin="10,0,0,0">
<TextBlock DockPanel.Dock="Left" Text="Text size" Foreground="{StaticResource Brush.OnSurfaceVariant}"
FontSize="11" Width="60" VerticalAlignment="Center"/>
<TextBlock DockPanel.Dock="Right" Width="42" TextAlignment="Right" FontSize="11"
<TextBlock DockPanel.Dock="Right" Width="56" TextAlignment="Right" FontSize="11"
Foreground="{StaticResource Brush.OnSurfaceVariant}" VerticalAlignment="Center"
Text="{Binding ScoreboardFontSize, StringFormat={}{0:0}}"/>
<Slider Minimum="14" Maximum="24" SmallChange="1" LargeChange="2"
Text="{Binding ScoreboardFontSizeLabel}"/>
<Slider Minimum="14" Maximum="24" SmallChange="1" LargeChange="2" TickFrequency="1" IsSnapToTickEnabled="True"
Value="{Binding ScoreboardFontSize, Mode=TwoWay}" VerticalAlignment="Center"/>
</DockPanel>
</StackPanel>
+1 -1
View File
@@ -37,7 +37,7 @@ public sealed class ScoreboardPresenter
public const double DefaultPixelsPerSecond = 120;
public const double MinPixelsPerSecond = 20;
public const double MaxPixelsPerSecond = 400;
public const double MaxPixelsPerSecond = 200; // creator cap: faster than this is unreadable
/// <summary>Advances the scroll by <paramref name="seconds"/>. The strip is a marquee: one
/// measured run, cropped to a moving window, so a tick is a row-wise byte copy rather than a
+11 -2
View File
@@ -15,9 +15,18 @@ public readonly record struct ScoreboardStyle(
string TextColor = "#FFFFFF",
bool BackgroundEnabled = true,
string BackgroundColor = "#000000",
double BackgroundOpacity = 0.55,
double BackgroundOpacity = 0.20,
double FontSize = ScoreboardLayout.MaxFontSize,
double SeparatorOpacity = 0.45);
double SeparatorOpacity = 0.45)
{
/// <summary>A record STRUCT's implicit parameterless constructor zero-initialises — it does NOT
/// run the parameter defaults. Without this, `new ScoreboardStyle()` produced null text colour,
/// no background and zero opacity: every "default" in this file was a lie, and the plate/opacity
/// controls looked dead because the renderer was faithfully drawing what it was given.</summary>
public ScoreboardStyle() : this("#FFFFFF", true, "#000000", 0.20, ScoreboardLayout.MaxFontSize, 0.45)
{
}
}
/// <summary>Rasterises the scoreboard strip (one line, shrinking/wrapping via
/// <see cref="ScoreboardLayout.FitLine"/>) into a straight-alpha BGRA frame the compositor blits.
+8
View File
@@ -193,6 +193,9 @@ public partial class MainViewModel
{
_scoreboardStyle = _scoreboardStyle with { BackgroundOpacity = Math.Clamp(value, 0, 1) };
PushStyle();
// The readout binds THIS property: without its own raise the number never moves even
// though the render does (creator: "bzzzt!").
OnPropertyChanged(nameof(ScoreboardBackgroundOpacity));
}
}
@@ -206,9 +209,14 @@ public partial class MainViewModel
FontSize = Math.Clamp(value, ScoreboardLayout.FloorFontSize, ScoreboardLayout.MaxFontSize),
};
PushStyle();
OnPropertyChanged(nameof(ScoreboardFontSize)); // same bug as the opacity readout
OnPropertyChanged(nameof(ScoreboardFontSizeLabel));
}
}
/// <summary>"24 px" — the panel shows real pixels, not a bare slider number.</summary>
public string ScoreboardFontSizeLabel => $"{_scoreboardStyle.FontSize:0} px";
/// <summary>The colours offered for text and plate: the app's one palette.</summary>
public IReadOnlyList<NamedColor> ScoreboardColorOptions => BorderColorPalette.All;
+10 -1
View File
@@ -25,13 +25,22 @@ public class ScoreboardPropertiesTests
Assert.Contains("Sign in to YouTube to use the scoreboard.", block);
Assert.Contains("CanUseScoreboard, Converter={StaticResource InverseBoolToVis}", block);
// Defaults the creator asked for, and readouts that actually move.
Assert.Contains("Background", block);
Assert.DoesNotContain("Background plate", block);
Assert.Contains("ScoreboardFontSizeLabel", block); // "24 px", not a bare number
var vm = SourceAssert.Text("ViewModels", "MainViewModel.Scoreboard.cs");
Assert.Contains("OnPropertyChanged(nameof(ScoreboardBackgroundOpacity));", vm);
Assert.Contains("OnPropertyChanged(nameof(ScoreboardFontSize));", vm);
// Dev-only labels are ORANGE, so a development affordance cannot pass for product.
Assert.Contains("Simulate (dev)", block);
Assert.Contains("Brush.Attention", block);
// Scroll speed: a real dial, persisted, with its range owned by the presenter.
Assert.Contains("ScoreboardScrollSpeed", block);
Assert.Contains("Minimum=\"20\" Maximum=\"400\"", block);
Assert.Contains("Minimum=\"20\" Maximum=\"200\"", block);
Assert.Contains("Scoreboard.ScrollSpeed", SourceAssert.Text("Services", "LayoutStore.Settings.cs"));
// The master switch sits in the same panel: off hides the strip and stops the polling.
+8
View File
@@ -17,6 +17,14 @@ public class ScoreboardRendererTests
[Fact]
public void The_strip_paints_the_plate_and_the_text_and_never_needs_a_scroll()
{
// The shipped defaults: white text, background ON, black, 20%.
var defaults = new ScoreboardStyle();
Assert.Equal("#FFFFFF", defaults.TextColor);
Assert.True(defaults.BackgroundEnabled);
Assert.Equal("#000000", defaults.BackgroundColor);
Assert.Equal(0.20, defaults.BackgroundOpacity, 3);
Assert.Equal(200, ytLive.Services.Compositor.ScoreboardPresenter.MaxPixelsPerSecond, 3);
Exception? failure = null;
var thread = new Thread(() =>