# Conflicts: # LehrerApp.TemplateDesigner.Tests/ProjectLifecycleTests.cs # LehrerApp.TemplateDesigner/DesignerViewModel.cs # LehrerApp.TemplateDesigner/MainWindow.axaml # LehrerApp.Templating/LayoutParser.cs # LehrerApp.Templating/QuestTemplateRenderer.cs
This commit is contained in:
@@ -135,6 +135,36 @@ public sealed class LayoutParser
|
||||
flowBox ? 0 : Number(tokens[2]), flowBox ? 0 : Number(tokens[3]),
|
||||
flowBox ? 0 : Number(tokens[4]), boxContent, boxRef.Name, boxRef.Format,
|
||||
Attributes(tokens, flowBox ? 2 : 6)); break;
|
||||
case "FLOWBOX":
|
||||
var nestedFlowBox = currentFlowName is not null;
|
||||
Require(tokens, nestedFlowBox ? 2 : 6);
|
||||
var flowContent = tokens[nestedFlowBox ? 1 : 5];
|
||||
var flowRef = Reference(flowContent);
|
||||
parsedElement = new FlowBoxElement(lineNumber,
|
||||
nestedFlowBox ? 0 : Number(tokens[1]), nestedFlowBox ? 0 : Number(tokens[2]),
|
||||
nestedFlowBox ? 0 : Number(tokens[3]), nestedFlowBox ? 0 : Number(tokens[4]),
|
||||
flowContent, flowRef.Name, flowRef.Format, Attributes(tokens, nestedFlowBox ? 2 : 6));
|
||||
break;
|
||||
case "DRAWBOX":
|
||||
var flowDrawing = currentFlowName is not null;
|
||||
Require(tokens, flowDrawing ? 2 : 6);
|
||||
var drawingAttributes = Attributes(tokens, flowDrawing ? 2 : 6);
|
||||
parsedElement = new DrawBoxElement(lineNumber,
|
||||
flowDrawing ? 0 : Number(tokens[1]), flowDrawing ? 0 : Number(tokens[2]),
|
||||
flowDrawing ? RequiredPositiveNumber(drawingAttributes, "w") : Number(tokens[3]),
|
||||
flowDrawing ? RequiredPositiveNumber(drawingAttributes, "h") : Number(tokens[4]),
|
||||
RequiredReference(tokens[flowDrawing ? 1 : 5]), drawingAttributes);
|
||||
break;
|
||||
case "FLOWDRAWBOX":
|
||||
var nestedFlowDrawing = currentFlowName is not null;
|
||||
Require(tokens, nestedFlowDrawing ? 2 : 6);
|
||||
var flowDrawingAttributes = Attributes(tokens, nestedFlowDrawing ? 2 : 6);
|
||||
parsedElement = new FlowDrawBoxElement(lineNumber,
|
||||
nestedFlowDrawing ? 0 : Number(tokens[1]), nestedFlowDrawing ? 0 : Number(tokens[2]),
|
||||
nestedFlowDrawing ? RequiredPositiveNumber(flowDrawingAttributes, "w") : Number(tokens[3]),
|
||||
nestedFlowDrawing ? RequiredPositiveNumber(flowDrawingAttributes, "h") : Number(tokens[4]),
|
||||
RequiredReference(tokens[nestedFlowDrawing ? 1 : 5]), flowDrawingAttributes);
|
||||
break;
|
||||
case "TABLE":
|
||||
var flowTable = currentFlowName is not null;
|
||||
Require(tokens, flowTable ? 2 : 6);
|
||||
@@ -201,6 +231,7 @@ public sealed class LayoutParser
|
||||
|
||||
private static (string? Name, string? Format) Reference(string value)
|
||||
{
|
||||
if (SystemVariables.IsStandalone(value)) return (null, null);
|
||||
if (!value.StartsWith('$')) return (null, null);
|
||||
var parts = value[1..].Split('|', 2);
|
||||
if (string.IsNullOrWhiteSpace(parts[0])) throw new FormatException("Platzhaltername fehlt.");
|
||||
@@ -216,6 +247,14 @@ public sealed class LayoutParser
|
||||
private static float OptionalNumber(IReadOnlyDictionary<string, string> attributes, string name) =>
|
||||
attributes.TryGetValue(name, out var value) ? Number(value) : 0;
|
||||
|
||||
private static float RequiredPositiveNumber(IReadOnlyDictionary<string, string> attributes, string name)
|
||||
{
|
||||
if (!attributes.TryGetValue(name, out var raw))
|
||||
throw new FormatException($"Das Element benötigt {name}=…");
|
||||
var value = Number(raw);
|
||||
return value > 0 ? value : throw new FormatException($"{name} muss positiv sein.");
|
||||
}
|
||||
|
||||
public static float Percentage(string value)
|
||||
{
|
||||
var normalized = value.EndsWith('%') ? value[..^1] : value;
|
||||
|
||||
Reference in New Issue
Block a user