This commit is contained in:
@@ -9,13 +9,22 @@ public class SmoothProgressBar {
|
||||
private final float speed = 2.0f;
|
||||
private final float clipConstant = 0.001f;
|
||||
|
||||
public void render(String label, ImVec2 size, float progress) {
|
||||
float delta = progress - lastProgress;
|
||||
private void updateProgress(float newProgress) {
|
||||
float delta = newProgress - lastProgress;
|
||||
if (Math.abs(delta) < clipConstant)
|
||||
lastProgress = progress;
|
||||
lastProgress = newProgress;
|
||||
else
|
||||
lastProgress = lastProgress + delta * ImGui.getIO().getDeltaTime() * speed;
|
||||
}
|
||||
|
||||
public void render(String label, ImVec2 size, float progress) {
|
||||
updateProgress(progress);
|
||||
ImGui.progressBar(lastProgress, size, label);
|
||||
}
|
||||
|
||||
public void render(float progress) {
|
||||
updateProgress(progress);
|
||||
ImGui.progressBar(lastProgress);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -37,10 +37,13 @@ public class SudokuSelector {
|
||||
|
||||
private Thread genThread = null;
|
||||
|
||||
private final SmoothProgressBar genProgressBar;
|
||||
|
||||
public SudokuSelector(boolean canGenEmptyGrid, String confirmMessage) {
|
||||
this.canGenEmptyGrid = canGenEmptyGrid;
|
||||
this.confirmMessage = confirmMessage;
|
||||
initConstraints();
|
||||
this.genProgressBar = new SmoothProgressBar();
|
||||
}
|
||||
|
||||
private List<IConstraint> getConstraints() {
|
||||
@@ -68,6 +71,9 @@ public class SudokuSelector {
|
||||
private void renderGenProgress() {
|
||||
if (ImGui.beginPopup("genProgress")) {
|
||||
ImGui.text("Loading ...");
|
||||
int filled = this.doku.getFilledCells().size();
|
||||
int total = this.doku.getCells().size();
|
||||
this.genProgressBar.render(filled / (float) total);
|
||||
ImGui.endPopup();
|
||||
} else {
|
||||
stopGenThread();
|
||||
|
||||
Reference in New Issue
Block a user