瀏覽代碼

Split SliderBehaviorCalcRatioFromValue() out of SliderBehavior(), fix + Not using fabsf() anymore

ocornut 9 年之前
父節點
當前提交
0a483379af
共有 1 個文件被更改,包括 2 次插入2 次删除
  1. 2 2
      imgui.cpp

+ 2 - 2
imgui.cpp

@@ -6448,7 +6448,7 @@ float ImGui::RoundScalar(float value, int decimal_precision)
 
 
 static inline float SliderBehaviorCalcRatioFromValue(float v, float v_min, float v_max, float power, float linear_zero_pos)
 static inline float SliderBehaviorCalcRatioFromValue(float v, float v_min, float v_max, float power, float linear_zero_pos)
 {
 {
-    const bool is_non_linear = (power < 1.0f-0.00001f) && (power > 1.0f-0.00001f);
+    const bool is_non_linear = (power < 1.0f-0.00001f) || (power > 1.0f+0.00001f);
     const float v_clamped = (v_min < v_max) ? ImClamp(v, v_min, v_max) : ImClamp(v, v_max, v_min);
     const float v_clamped = (v_min < v_max) ? ImClamp(v, v_min, v_max) : ImClamp(v, v_max, v_min);
     if (is_non_linear)
     if (is_non_linear)
     {
     {
@@ -6477,7 +6477,7 @@ bool ImGui::SliderBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v
     // Draw frame
     // Draw frame
     RenderFrame(frame_bb.Min, frame_bb.Max, GetColorU32(ImGuiCol_FrameBg), true, style.FrameRounding);
     RenderFrame(frame_bb.Min, frame_bb.Max, GetColorU32(ImGuiCol_FrameBg), true, style.FrameRounding);
 
 
-    const bool is_non_linear = fabsf(power - 1.0f) > 0.0001f;
+    const bool is_non_linear = (power < 1.0f-0.00001f) || (power > 1.0f+0.00001f);
     const bool is_horizontal = (flags & ImGuiSliderFlags_Vertical) == 0;
     const bool is_horizontal = (flags & ImGuiSliderFlags_Vertical) == 0;
 
 
     const float grab_padding = 2.0f;
     const float grab_padding = 2.0f;