dalerank / imspinner

Set of nice spinners for imgui
MIT License
437 stars 40 forks source link

Missing `min` prevents compiling. #5

Closed nitz closed 2 years ago

nitz commented 2 years ago

Howdy!

First, thanks for these fantastic spinners, I absolutely love them. (Quick aside: do you have a ko-fi or other similar for a one-time donation?)

So my issue is really sortof a non-issue, and I imagine is probably more related to my platform and toolchain than anything, but I just was hoping to get your opinion on the "proper" way to solve it.

I'm using Microsoft's toolchain, (particularly cl 19.33.31630 with the win 10 sdk v10.0.19041,) targeting an x86_64 platform. When I include imspinner.h, there's no global min symbol defined, so compiling fails.

I could obviously define one before including it or etc, but I was just mostly curious if there's a specific min macro/method you're invoking there. Perhaps if you're intending to use std::min, a patch like this may clarify intent?

diff --git a/imspinner.h b/imspinner.h
index ac274f5..4e160fb 100644
--- a/imspinner.h
+++ b/imspinner.h
@@ -28,6 +28,7 @@

 #include <functional>
 #include <array>
+#include <algorithm>

 namespace ImSpinner
 {
@@ -317,7 +318,7 @@ namespace ImSpinner
         // Render
         float start = (float)ImGui::GetTime() * speed;
         const float bg_angle_offset = IM_PI * 2.f / dots;
-        dots = min(dots, 32);
+        dots = std::min(dots, (size_t)32);

         float def_nextdot = 0;
         float &ref_nextdot = nextdot ? *nextdot : def_nextdot;
@@ -354,7 +355,7 @@ namespace ImSpinner
         // Render
         float start = (float)ImGui::GetTime() * speed;
         const float bg_angle_offset = IM_PI * 2.f / dots;
-        dots = min(dots, 32);
+        dots = std::min(dots, (size_t)32);

         for (size_t i = 0; i <= dots; i++)
         {
@@ -1123,7 +1124,7 @@ namespace ImSpinner
       float astart = ImFmod(start, IM_PI / dots);
       start -= astart;
       const float bg_angle_offset = IM_PI / dots;
-      dots = min(dots, 32);
+      dots = std::min(dots, (size_t)32);

       for (size_t i = 0; i <= dots; i++)
       {

Cheers and hope you're well.

dalerank commented 2 years ago

Hi, nope, but u can buy me a beer if we meet :) Sure, thanks, ofcourse it my mistake, ocornut using ImMin instead min/max. Wll fix it soon

dalerank commented 2 years ago

closed in last commit