Make progress less jittery

This commit is contained in:
crschnick
2024-03-04 14:10:27 +00:00
parent 492458c7f9
commit 596c3bd524
3 changed files with 6 additions and 5 deletions
@@ -445,7 +445,7 @@ final class BrowserFileListComp extends SimpleComp {
if (path.getRawFileEntry().resolved().getKind() == FileKind.DIRECTORY) {
setText("");
} else {
setText(byteCount(fileSize.longValue()));
setText(byteCount(fileSize.longValue(), true));
}
}
}
@@ -46,13 +46,13 @@ public class BrowserStatusBarComp extends SimpleComp {
var transferredCount = PlatformThread.sync(Bindings.createStringBinding(
() -> {
return HumanReadableFormat.byteCount(
model.getProgress().getValue().getTransferred());
model.getProgress().getValue().getTransferred(), false);
},
model.getProgress()));
var allCount = PlatformThread.sync(Bindings.createStringBinding(
() -> {
return HumanReadableFormat.byteCount(
model.getProgress().getValue().getTotal());
model.getProgress().getValue().getTotal(), true);
},
model.getProgress()));
var progressComp = new LabelComp(Bindings.createStringBinding(
@@ -16,7 +16,7 @@ public final class HumanReadableFormat {
public static final DateTimeFormatter DAY_OF_WEEK = DateTimeFormatter.ofPattern("EEE");
public static final DateTimeFormatter HOUR_MINUTE = DateTimeFormatter.ofPattern("HH:mm");
public static String byteCount(long bytes) {
public static String byteCount(long bytes, boolean precise) {
if (-1024 < bytes && bytes < 1024) {
return bytes + " B";
}
@@ -25,7 +25,8 @@ public final class HumanReadableFormat {
bytes /= 1024;
ci.next();
}
return String.format("%.1f %cB", bytes / 1024.0, ci.current());
var f = precise ? "%.1f" : "%.0f";
return String.format(f + " %cB", bytes / 1024.0, ci.current());
}
public static String date(LocalDateTime x) {