Просмотр исходного кода

Fixed InputScalar, InputScalarN, SliderScalarN, DragScalarN with non-visible label from inserting style.ItemInnerSpacing.x worth of trailing spacing.

omar 6 лет назад
Родитель
Сommit
3fda90d6a7
2 измененных файлов с 36 добавлено и 8 удалено
  1. 2 0
      docs/CHANGELOG.txt
  2. 34 8
      imgui_widgets.cpp

+ 2 - 0
docs/CHANGELOG.txt

@@ -41,6 +41,8 @@ Other Changes:
 - Columns: Fixed Selectable with SpanAllColumns flag from creating an extraneous draw command. (#125)
 - Columns: Fixed Selectable with SpanAllColumns flag from creating an extraneous draw command. (#125)
 - Separator: Revert 1.70 "Declare its thickness (1.0f) to the layout" change. It's not incorrect
 - Separator: Revert 1.70 "Declare its thickness (1.0f) to the layout" change. It's not incorrect
   but it breaks existing some layout patterns. Will return back to it when we expose Separator flags.
   but it breaks existing some layout patterns. Will return back to it when we expose Separator flags.
+- Fixed InputScalar, InputScalarN, SliderScalarN, DragScalarN with non-visible label from inserting
+  style.ItemInnerSpacing.x worth of trailing spacing.
 - Fixed InputFloatX, SliderFloatX, DragFloatX functions erroneously reporting IsItemEdited() multiple
 - Fixed InputFloatX, SliderFloatX, DragFloatX functions erroneously reporting IsItemEdited() multiple
   times when the text input doesn't match the formatted output value (e.g. input "1" shows "1.000").
   times when the text input doesn't match the formatted output value (e.g. input "1" shows "1.000").
   It wasn't much of a problem because we typically use the return value instead of IsItemEdited() here.
   It wasn't much of a problem because we typically use the return value instead of IsItemEdited() here.

+ 34 - 8
imgui_widgets.cpp

@@ -2068,15 +2068,22 @@ bool ImGui::DragScalarN(const char* label, ImGuiDataType data_type, void* v, int
     for (int i = 0; i < components; i++)
     for (int i = 0; i < components; i++)
     {
     {
         PushID(i);
         PushID(i);
+        if (i > 0)
+            SameLine(0, g.Style.ItemInnerSpacing.x);
         value_changed |= DragScalar("", data_type, v, v_speed, v_min, v_max, format, power);
         value_changed |= DragScalar("", data_type, v, v_speed, v_min, v_max, format, power);
-        SameLine(0, g.Style.ItemInnerSpacing.x);
         PopID();
         PopID();
         PopItemWidth();
         PopItemWidth();
         v = (void*)((char*)v + type_size);
         v = (void*)((char*)v + type_size);
     }
     }
     PopID();
     PopID();
 
 
-    TextEx(label, FindRenderedTextEnd(label));
+    const char* label_end = FindRenderedTextEnd(label);
+    if (label != label_end)
+    {
+        SameLine(0, g.Style.ItemInnerSpacing.x);
+        TextEx(label, label_end);
+    }
+
     EndGroup();
     EndGroup();
     return value_changed;
     return value_changed;
 }
 }
@@ -2516,15 +2523,22 @@ bool ImGui::SliderScalarN(const char* label, ImGuiDataType data_type, void* v, i
     for (int i = 0; i < components; i++)
     for (int i = 0; i < components; i++)
     {
     {
         PushID(i);
         PushID(i);
+        if (i > 0)
+            SameLine(0, g.Style.ItemInnerSpacing.x);
         value_changed |= SliderScalar("", data_type, v, v_min, v_max, format, power);
         value_changed |= SliderScalar("", data_type, v, v_min, v_max, format, power);
-        SameLine(0, g.Style.ItemInnerSpacing.x);
         PopID();
         PopID();
         PopItemWidth();
         PopItemWidth();
         v = (void*)((char*)v + type_size);
         v = (void*)((char*)v + type_size);
     }
     }
     PopID();
     PopID();
 
 
-    TextEx(label, FindRenderedTextEnd(label));
+    const char* label_end = FindRenderedTextEnd(label);
+    if (label != label_end)
+    {
+        SameLine(0, g.Style.ItemInnerSpacing.x);
+        TextEx(label, label_end);
+    }
+
     EndGroup();
     EndGroup();
     return value_changed;
     return value_changed;
 }
 }
@@ -2827,8 +2841,13 @@ bool ImGui::InputScalar(const char* label, ImGuiDataType data_type, void* data_p
             DataTypeApplyOp(data_type, '+', data_ptr, data_ptr, g.IO.KeyCtrl && step_fast ? step_fast : step);
             DataTypeApplyOp(data_type, '+', data_ptr, data_ptr, g.IO.KeyCtrl && step_fast ? step_fast : step);
             value_changed = true;
             value_changed = true;
         }
         }
-        SameLine(0, style.ItemInnerSpacing.x);
-        TextEx(label, FindRenderedTextEnd(label));
+
+        const char* label_end = FindRenderedTextEnd(label);
+        if (label != label_end)
+        {
+            SameLine(0, style.ItemInnerSpacing.x);
+            TextEx(label, label_end);
+        }
         style.FramePadding = backup_frame_padding;
         style.FramePadding = backup_frame_padding;
 
 
         PopID();
         PopID();
@@ -2860,15 +2879,22 @@ bool ImGui::InputScalarN(const char* label, ImGuiDataType data_type, void* v, in
     for (int i = 0; i < components; i++)
     for (int i = 0; i < components; i++)
     {
     {
         PushID(i);
         PushID(i);
+        if (i > 0)
+            SameLine(0, g.Style.ItemInnerSpacing.x);
         value_changed |= InputScalar("", data_type, v, step, step_fast, format, flags);
         value_changed |= InputScalar("", data_type, v, step, step_fast, format, flags);
-        SameLine(0, g.Style.ItemInnerSpacing.x);
         PopID();
         PopID();
         PopItemWidth();
         PopItemWidth();
         v = (void*)((char*)v + type_size);
         v = (void*)((char*)v + type_size);
     }
     }
     PopID();
     PopID();
 
 
-    TextEx(label, FindRenderedTextEnd(label));
+    const char* label_end = FindRenderedTextEnd(label);
+    if (label != label_end)
+    {
+        SameLine(0.0f, g.Style.ItemInnerSpacing.x);
+        TextEx(label, label_end);
+    }
+
     EndGroup();
     EndGroup();
     return value_changed;
     return value_changed;
 }
 }