Browse Source

DragFloat, DragInt: Default format string is none is passed to the function. Fixed demo using old style %.0f.

omar 7 năm trước cách đây
mục cha
commit
dcd26f1295
2 tập tin đã thay đổi với 8 bổ sung5 xóa
  1. 4 1
      imgui.cpp
  2. 4 4
      imgui_demo.cpp

+ 4 - 1
imgui.cpp

@@ -9321,8 +9321,11 @@ bool ImGui::DragScalar(const char* label, ImGuiDataType data_type, void* v, floa
     }
     }
     const bool hovered = ItemHoverable(frame_bb, id);
     const bool hovered = ItemHoverable(frame_bb, id);
 
 
+    // Default format string when passing NULL
     // Patch old "%.0f" format string to use "%d", read function comments for more details.
     // Patch old "%.0f" format string to use "%d", read function comments for more details.
-    if (data_type == ImGuiDataType_S32 && strcmp(format, "%d") != 0)
+    if (format == NULL)
+        format = GDataTypeInfo[data_type].PrintFmt;
+    else if (data_type == ImGuiDataType_S32 && strcmp(format, "%d") != 0)
         format = PatchFormatStringFloatToInt(format);
         format = PatchFormatStringFloatToInt(format);
 
 
     // Tabbing or CTRL-clicking on Drag turns it into an input box
     // Tabbing or CTRL-clicking on Drag turns it into an input box

+ 4 - 4
imgui_demo.cpp

@@ -361,7 +361,7 @@ void ImGui::ShowDemoWindow(bool* p_open)
                 ImGui::DragInt("drag int", &i1, 1);
                 ImGui::DragInt("drag int", &i1, 1);
                 ImGui::SameLine(); ShowHelpMarker("Click and drag to edit value.\nHold SHIFT/ALT for faster/slower edit.\nDouble-click or CTRL+click to input value.");
                 ImGui::SameLine(); ShowHelpMarker("Click and drag to edit value.\nHold SHIFT/ALT for faster/slower edit.\nDouble-click or CTRL+click to input value.");
 
 
-                ImGui::DragInt("drag int 0..100", &i2, 1, 0, 100, "%.0f%%");
+                ImGui::DragInt("drag int 0..100", &i2, 1, 0, 100, "%d%%");
 
 
                 static float f1=1.00f, f2=0.0067f;
                 static float f1=1.00f, f2=0.0067f;
                 ImGui::DragFloat("drag float", &f1, 0.005f);
                 ImGui::DragFloat("drag float", &f1, 0.005f);
@@ -996,7 +996,7 @@ void ImGui::ShowDemoWindow(bool* p_open)
             static float begin = 10, end = 90;
             static float begin = 10, end = 90;
             static int begin_i = 100, end_i = 1000;
             static int begin_i = 100, end_i = 1000;
             ImGui::DragFloatRange2("range", &begin, &end, 0.25f, 0.0f, 100.0f, "Min: %.1f %%", "Max: %.1f %%");
             ImGui::DragFloatRange2("range", &begin, &end, 0.25f, 0.0f, 100.0f, "Min: %.1f %%", "Max: %.1f %%");
-            ImGui::DragIntRange2("range int (no bounds)", &begin_i, &end_i, 5, 0, 0, "Min: %.0f units", "Max: %.0f units");
+            ImGui::DragIntRange2("range int (no bounds)", &begin_i, &end_i, 5, 0, 0, "Min: %d units", "Max: %d units");
             ImGui::TreePop();
             ImGui::TreePop();
         }
         }
 
 
@@ -1371,9 +1371,9 @@ void ImGui::ShowDemoWindow(bool* p_open)
             static int track_line = 50, scroll_to_px = 200;
             static int track_line = 50, scroll_to_px = 200;
             ImGui::Checkbox("Track", &track);
             ImGui::Checkbox("Track", &track);
             ImGui::PushItemWidth(100);
             ImGui::PushItemWidth(100);
-            ImGui::SameLine(130); track |= ImGui::DragInt("##line", &track_line, 0.25f, 0, 99, "Line = %.0f");
+            ImGui::SameLine(130); track |= ImGui::DragInt("##line", &track_line, 0.25f, 0, 99, "Line = %d");
             bool scroll_to = ImGui::Button("Scroll To Pos");
             bool scroll_to = ImGui::Button("Scroll To Pos");
-            ImGui::SameLine(130); scroll_to |= ImGui::DragInt("##pos_y", &scroll_to_px, 1.00f, 0, 9999, "Y = %.0f px");
+            ImGui::SameLine(130); scroll_to |= ImGui::DragInt("##pos_y", &scroll_to_px, 1.00f, 0, 9999, "Y = %d px");
             ImGui::PopItemWidth();
             ImGui::PopItemWidth();
             if (scroll_to) track = false;
             if (scroll_to) track = false;