feat(Hintergrund): Erstellen, um den Hintergrund von Anmerkungen mit der Eigenschaft MarginRatio zu konfigurieren.

- verschiebt Anmerkungen nach
This commit is contained in:
Developer 02
2025-04-23 15:31:35 +02:00
parent 13a87f29d9
commit ea6ee11a4e
6 changed files with 25 additions and 8 deletions

View File

@@ -0,0 +1,64 @@
using System.Text.Json.Serialization;
namespace EnvelopeGenerator.Web.Models.Annotation;
public class AnnotationParams
{
public AnnotationParams()
{
_annotationDictionaryInitor = new(() => _annots.ToDictionary(a => a.Name.ToLower(), a => a));
}
public Background? Background { get; init; }
[JsonIgnore]
public Annotation? DefaultAnnotation { get; init; }
private readonly List<Annotation> _annots = new List<Annotation>();
public Annotation this[string name] => _annots.First(a => a.Name == name);
public bool TryGet(string name, out Annotation annotation)
{
#pragma warning disable CS8601 // Possible null reference assignment.
annotation = _annots.FirstOrDefault(a => a.Name == name);
#pragma warning restore CS8601 // Possible null reference assignment.
return annotation is not null;
}
public required IEnumerable<Annotation> Annotations
{
get => _annots;
init
{
_annots = value.ToList();
if (DefaultAnnotation is not null)
foreach (var annot in _annots)
annot.Default = DefaultAnnotation;
foreach (var annot in _annots)
{
#region set bound annotations
// horizontal
if (annot.HorBoundAnnotName is string horBoundAnnotName)
if (TryGet(horBoundAnnotName, out var horBoundAnnot))
annot.HorBoundAnnot = horBoundAnnot;
else
throw new InvalidOperationException($"{horBoundAnnotName} added as bound anotation. However, it is not defined.");
// vertical
if (annot.VerBoundAnnotName is string verBoundAnnotName)
if (TryGet(verBoundAnnotName, out var verBoundAnnot))
annot.VerBoundAnnot = verBoundAnnot;
else
throw new InvalidOperationException($"{verBoundAnnotName} added as bound anotation. However, it is not defined.");
#endregion
}
}
}
private readonly Lazy<Dictionary<string, Annotation>> _annotationDictionaryInitor;
public Dictionary<string, Annotation> AnnotationDictionary => _annotationDictionaryInitor.Value;
}