package gui.widget;

import imgui.ImGui;
import imgui.ImVec2;

public class SmoothProgressBar {

	private float lastProgress = 0;
	private final float speed = 2.0f;
	private final float clipConstant = 0.001f;

	private void updateProgress(float newProgress) {
		float delta = newProgress - lastProgress;
		if (Math.abs(delta) < clipConstant)
			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);
	}

}
