mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-11-03 10:01:38 -05:00
fix(ui): scale the fill time in the status bar
Long fills read as thousands of milliseconds. Keep milliseconds under a second, then show seconds and minutes so the time stays readable. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0a0da50006
commit
763e2a1d4a
2 files changed
+31
-1
No files matched your search
@@ -0,0 +1,18 @@
|
||||
using OpenNest.Controls;
|
||||
|
||||
namespace OpenNest.WinForms.Tests.Controls;
|
||||
|
||||
public class PlateViewFillTimeTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData(0, "0 ms")]
|
||||
[InlineData(850, "850 ms")]
|
||||
[InlineData(999, "999 ms")]
|
||||
[InlineData(1000, "1.0 s")]
|
||||
[InlineData(2400, "2.4 s")]
|
||||
[InlineData(59960, "59.9 s")]
|
||||
[InlineData(60000, "1m 00s")]
|
||||
[InlineData(125000, "2m 05s")]
|
||||
public void FillTimeIsShownInTheLargestUnitThatFits(int milliseconds, string expected) =>
|
||||
Assert.Equal(expected, PlateView.FormatFillTime(TimeSpan.FromMilliseconds(milliseconds)));
|
||||
}
|
||||
@@ -995,7 +995,7 @@ namespace OpenNest.Controls
|
||||
change.Complete();
|
||||
|
||||
sw.Stop();
|
||||
Status = $"Fill: {parts.Count} parts in {sw.ElapsedMilliseconds} ms";
|
||||
Status = $"Fill: {parts.Count} parts in {FormatFillTime(sw.Elapsed)}";
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1023,6 +1023,18 @@ namespace OpenNest.Controls
|
||||
}
|
||||
}
|
||||
|
||||
// Truncates so a time just under a unit boundary never reads as "60.0 s".
|
||||
internal static string FormatFillTime(TimeSpan elapsed)
|
||||
{
|
||||
if (elapsed.TotalSeconds < 1)
|
||||
return $"{(int)elapsed.TotalMilliseconds} ms";
|
||||
|
||||
if (elapsed.TotalMinutes < 1)
|
||||
return $"{(int)(elapsed.TotalSeconds * 10) / 10.0:0.0} s";
|
||||
|
||||
return $"{(int)elapsed.TotalMinutes}m {elapsed.Seconds:00}s";
|
||||
}
|
||||
|
||||
public void RemoveSelectedParts() => selection.RemoveSelectedParts();
|
||||
|
||||
private void redrawTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
|
||||
|
||||
Reference in new issue
Block a user