Files
Chronos/src/Titano.Ui/Visuals/AspectRatioDecorator.cs
T
Claude 0ac73793c7 feat(ui-visuals): add SequenceCard with asynchronous hover scrubbing
Card control for the Library (16:9 thumbnail, badge, selection box, title,
secondary line, status glyphs) whose thumbnail scrubs through the sequence
from an IThumbnailSource, cancelling stale requests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
2026-10-02 10:26:50 +00:00

37 lines
1.2 KiB
C#

using System.Windows;
using System.Windows.Controls;
namespace Titano.Ui.Visuals;
/// <summary>Sizes its child to the available width and a height of width ÷ <see cref="Ratio"/> (card thumbnails are 16:9).</summary>
public sealed class AspectRatioDecorator : Decorator
{
public static readonly DependencyProperty RatioProperty = DependencyProperty.Register(
nameof(Ratio), typeof(double), typeof(AspectRatioDecorator),
new FrameworkPropertyMetadata(16.0 / 9.0, FrameworkPropertyMetadataOptions.AffectsMeasure),
v => v is double d && double.IsFinite(d) && d > 0);
/// <summary>Width ÷ height.</summary>
public double Ratio { get => (double)GetValue(RatioProperty); set => SetValue(RatioProperty, value); }
protected override Size MeasureOverride(Size constraint)
{
var size = Fit(constraint);
Child?.Measure(size);
return size;
}
protected override Size ArrangeOverride(Size arrangeSize)
{
var size = Fit(arrangeSize);
Child?.Arrange(new Rect(size));
return size;
}
private Size Fit(Size available)
{
var width = double.IsInfinity(available.Width) ? 0 : available.Width;
return new Size(width, width / Ratio);
}
}