kitchen receipt alignment change

This commit is contained in:
EugeneTes
2026-01-26 15:28:56 +01:00
parent 1125222cbe
commit 43c118f527
2 changed files with 60 additions and 8 deletions

View File

@@ -5,7 +5,7 @@
<TargetFramework>net8.0</TargetFramework> <TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<Version>1.0.3</Version> <Version>1.0.4</Version>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@@ -100,32 +100,84 @@ public class KitchenReceiptConverter
return commands; return commands;
} }
private static void PrintDish(Dish dish, List<PrintCommand> commands) private void PrintDish(Dish dish, List<PrintCommand> commands)
{ {
string dishLine = $"{dish.Number}x {dish.Name}"; string quantityPrefix = $"{dish.Number}x ";
string guestInfo = dish.GuestId.HasValue ? $"{dish.GuestId.Value} " : ""; string guestInfo = dish.GuestId.HasValue ? $"{dish.GuestId.Value} " : "";
string fullPrefix = guestInfo + quantityPrefix;
string fullLine = fullPrefix + dish.Name;
//todo: add word wrap if guest id is present and guestInfo + dish line too long. add spaces in front of continued lines to align with dish name start position if (fullLine.Length <= _lineWidth || string.IsNullOrEmpty(dish.Name))
{
commands.Add(new PrintCommand(fullLine) { IsTall = true });
}
else
{
int availableWidth = _lineWidth - fullPrefix.Length;
if (availableWidth <= 0)
{
// Prefix alone exceeds line width, print without wrapping
commands.Add(new PrintCommand(fullLine) { IsTall = true });
}
else
{
string continuationIndent = new string(' ', guestInfo.Length);
var words = dish.Name.Split(' ');
var lines = new List<string>();
string currentLine = "";
commands.Add(new PrintCommand(guestInfo+dishLine) {IsTall = true}); foreach (var word in words)
{
if (currentLine.Length == 0)
{
currentLine = word;
}
else if (currentLine.Length + 1 + word.Length <= availableWidth)
{
currentLine += " " + word;
}
else
{
lines.Add(currentLine);
currentLine = word;
}
}
if (currentLine.Length > 0)
{
lines.Add(currentLine);
}
// First line with full prefix
commands.Add(new PrintCommand(fullPrefix + lines[0]) { IsTall = true });
// Continuation lines with indent to align with dish name
for (int i = 1; i < lines.Count; i++)
{
commands.Add(new PrintCommand(continuationIndent + lines[i]) { IsTall = true });
}
}
}
// Modifications // Modifications
if (dish.Modifications != null && (dish.Modifications.Removed.Any() || dish.Modifications.Added.Any())) if (dish.Modifications != null && (dish.Modifications.Removed.Any() || dish.Modifications.Added.Any()))
{ {
string modificationIndent = new string(' ', guestInfo.Length + 1);
foreach (var removed in dish.Modifications.Removed) foreach (var removed in dish.Modifications.Removed)
{ {
commands.Add(new PrintCommand($" - {removed}", isBold:true) { IsTall = true }); commands.Add(new PrintCommand($"{modificationIndent}- {removed}", isBold:true) { IsTall = true });
} }
foreach (var added in dish.Modifications.Added) foreach (var added in dish.Modifications.Added)
{ {
commands.Add(new PrintCommand($" + {added}", isBold: true) { IsTall = true }); commands.Add(new PrintCommand($"{modificationIndent}+ {added}", isBold: true) { IsTall = true });
} }
} }
// SpecialInstruction // SpecialInstruction
if (!string.IsNullOrEmpty(dish.Comment)) if (!string.IsNullOrEmpty(dish.Comment))
{ {
commands.Add(new PrintCommand($" Comment: {dish.Comment}", isBold: true) { IsTall = true }); string commentIndent = new string(' ', guestInfo.Length);
commands.Add(new PrintCommand($"{commentIndent}Comment: {dish.Comment}", isBold: true) { IsTall = true });
} }
//commands.Add(new PrintCommand($"")); //commands.Add(new PrintCommand($""));