Make document footer more dynamic

This commit is contained in:
2023-08-17 16:30:47 +02:00
parent 9e1ea293aa
commit 258b2b3c5b
2 changed files with 45 additions and 5 deletions

View File

@ -195,5 +195,44 @@ namespace Elwig.Helpers {
var d = new ManualWeighingDialog();
return d.ShowDialog() == true ? (d.Weight, d.Reason) : null;
}
public static Footer GenerateFooter(string lineBreak, string seperator) {
return new Footer(lineBreak, seperator);
}
public class Footer {
private string Text = "";
private readonly string LineBreak;
private readonly string Seperator;
private bool FirstLine = true;
private bool FirstItemInLine = true;
public Footer(string lineBreak, string seperator) {
LineBreak = lineBreak;
Seperator = seperator;
}
public Footer Item(string? text) {
if (text == null) return this;
Text += FirstItemInLine ? (FirstLine ? "" : LineBreak) : Seperator;
Text += text;
FirstLine = false;
FirstItemInLine = false;
return this;
}
public Footer Item(string name, string? text) {
return text == null ? this : Item($"{name}: {text}");
}
public Footer NextLine() {
FirstItemInLine = true;
return this;
}
public override string ToString() {
return Text;
}
}
}
}