Repository navigation
Open
Labels
Description
Thought someone else might find these useful. Please feel free to use / change or upgrade code as needed. These are rough but work well enough for my use. (Note: Loosely inspired by Material Design.)
Screenshots/Video
If you do change them, please post your versions, I'd love to see what you come up with.
Full Code (usage example can be found below):
namespace ImGui {
bool BufferingBar(const char* label, float value, const ImVec2& size_arg, const ImU32& bg_col, const ImU32& fg_col) {
ImGuiWindow* window = GetCurrentWindow();
if (window->SkipItems)
return false;
ImGuiContext& g = *GImGui;
const ImGuiStyle& style = g.Style;
const ImGuiID id = window->GetID(label);
ImVec2 pos = window->DC.CursorPos;
ImVec2 size = size_arg;
size.x -= style.FramePadding.x * 2;
const ImRect bb(pos, ImVec2(pos.x + size.x, pos.y + size.y));
ItemSize(bb, style.FramePadding.y);
if (!ItemAdd(bb, id))
return false;
// Render
const float circleStart = size.x * 0.7f;
const float circleEnd = size.x;
const float circleWidth = circleEnd - circleStart;
window->DrawList->AddRectFilled(bb.Min, ImVec2(pos.x + circleStart, bb.Max.y), bg_col);
window->DrawList->AddRectFilled(bb.Min, ImVec2(pos.x + circleStart*value, bb.Max.y), fg_col);
const float t = g.Time;
const float r = size.y / 2;
const float speed = 1.5f;
const float a = speed*0;
const float b = speed*0.333f;
const float c = speed*0.666f;
const float o1 = (circleWidth+r) * (t+a - speed * (int)((t+a) / speed)) / speed;
const float o2 = (circleWidth+r) * (t+b - speed * (int)((t+b) / speed)) / speed;
const float o3 = (circleWidth+r) * (t+c - speed * (int)((t+c) / speed)) / speed;
window->DrawList->AddCircleFilled(ImVec2(pos.x + circleEnd - o1, bb.Min.y + r), r, bg_col);
window->DrawList->AddCircleFilled(ImVec2(pos.x + circleEnd - o2, bb.Min.y + r), r, bg_col);
window->DrawList->AddCircleFilled(ImVec2(pos.x + circleEnd - o3, bb.Min.y + r), r, bg_col);
}
bool Spinner(const char* label, float radius, int thickness, const ImU32& color) {
ImGuiWindow* window = GetCurrentWindow();
if (window->SkipItems)
return false;
ImGuiContext& g = *GImGui;
const ImGuiStyle& style = g.Style;
const ImGuiID id = window->GetID(label);
ImVec2 pos = window->DC.CursorPos;
ImVec2 size((radius )*2, (radius + style.FramePadding.y)*2);
const ImRect bb(pos, ImVec2(pos.x + size.x, pos.y + size.y));
ItemSize(bb, style.FramePadding.y);
if (!ItemAdd(bb, id))
return false;
// Render
window->DrawList->PathClear();
int num_segments = 30;
int start = abs(ImSin(g.Time*1.8f)*(num_segments-5));
const float a_min = IM_PI*2.0f * ((float)start) / (float)num_segments;
const float a_max = IM_PI*2.0f * ((float)num_segments-3) / (float)num_segments;
const ImVec2 centre = ImVec2(pos.x+radius, pos.y+radius+style.FramePadding.y);
for (int i = 0; i < num_segments; i++) {
const float a = a_min + ((float)i / (float)num_segments) * (a_max - a_min);
window->DrawList->PathLineTo(ImVec2(centre.x + ImCos(a+g.Time*8) * radius,
centre.y + ImSin(a+g.Time*8) * radius));
}
window->DrawList->PathStroke(color, false, thickness);
}
}Version/Branch of Dear ImGui: dear imgui, v1.62 WIP
Standalone, minimal, complete and verifiable example:
ImGui::Begin("Progress Indicators");
const ImU32 col = ImGui::GetColorU32(ImGuiCol_ButtonHovered);
const ImU32 bg = ImGui::GetColorU32(ImGuiCol_Button);
ImGui::Spinner("##spinner", 15, 6, col);
ImGui::BufferingBar("##buffer_bar", 0.7f, ImVec2(400, 6), bg, col);
ImGui::End();edit (June 25th): Updated code based on feedback provided (#1901 (comment))
Reacted by Rami Awar, Jacckii, Selim Anaç, Matheus Eduardo, well.james, Pisto Pancho, HackAssIa, Richbabe, Maxim Zhuchkov, Yupei Qi and 19 more
Reacted by Shahrooz Leon and aslan-gabriel
Reacted by omar, Stefano Cristiano, Wang Kai, Tesla Zhang, Ilya, Dmitry, Kevin Birk, Igor, Jacckii, Valencio Hoffman and 29 more
Reacted by Nicolas C. Lettiere, HackAssIa, Fahim Fuad, Alphonz, Patitotective, Aditya M., Manthan Raj Rajoria and aslan-gabriel

Activity
ocornut commentedon Jun 25, 2018
Thanks for posting those! Added this thread to the wiki index.
Two suggestions:
std::vectorand usewindow->DrawList->PathLineTo(). There's already a vector in there for that purpose and it would have amortized so it'll work with no allocation (whereas your new vector would need to allocate)g.Timevalue as well (in seconds) to avoid that parameter.zfedoran commentedon Jun 25, 2018
@ocornut Thanks for the great feedback! I've updated the code in the original post above.
DoctorGester commentedon Jun 26, 2018
That's useful, thanks!
I've been using something extremely simple in my app like
ocornut commentedon Jun 27, 2018
@DoctorGester I've been using an even more lo-fi version of that :)
ImGui::Text("Loading %c", "|/-\\"[(int)(ImGui::GetTime() / 0.05f) & 3]);inflex commentedon Jul 29, 2018
@ocornut I want to do something in my software just so I can use that text spinner in my status bar 😆
alexsr commentedon Dec 6, 2018
I thought I might also share my loading indicator. It's pretty simple, but might be interesting to some.

Edit 2023-11-16: Updated loading circles to fix content box.
Viewer: use imgui spinner from ocornut/imgui#1901
hofstee commentedon Nov 10, 2019
I tried my hand at making the original spinner by @zfedoran adhere more closely to the material design implementations. This is inspired by the implementation in Flutter (found here), and I just used the cubic_bezier implementation from chromium.
I've tried to make sense of all the random constants in the Flutter version as well and assign them to meaningful variables.
jdumas commentedon Jan 6, 2021
@zfedoran could you confirm what's the license on your code snippet? This is really cool!
zfedoran commentedon Jan 7, 2021
Feel free to use the snippet however you'd like. Consider the license on the snippet MIT, same as this repository. If you build something cool with it, we'd love to see it ;)
jdumas commentedon Jan 7, 2021
Thanks!
OPstriker commentedon May 18, 2022
Works Great TY
ProgressBar: added indeterminate mode by passing an animated negative…
xdCraze commentedon Jun 13, 2024
I know this is a little old but how do I make the spinner play for a certian time?
obsqrbtz commentedon Jun 14, 2024
You may store the start time at some variable and then display the spinner only if current time is less than start + {whatever interval you need}
xdCraze commentedon Jun 15, 2024
Can you make an example?
obsqrbtz commentedon Jun 17, 2024
Tried it out. Simply sleeping for n seconds seems easier.
[ImNodeFlow][ImGuiIndicators] Added another node editor and more spin…
sirnacnud commentedon Feb 21, 2026
FYI, the
SpinnerandBufferingBarfunctions have a return type specified asbool, but don't actually return at the end of the functions. This will cause a runtime crash if you just copy the code as is.