mirror of
				https://github.com/Drezil/imgui.git
				synced 2025-10-31 21:21:06 +01:00 
			
		
		
		
	Internals: InputScalarEx: Tweak internals so there is a fast path for the simple case.
(in particular because it makes it clear what the extra code is for, so people tempted to create their own InputText data transform/handler understand how little is actually needed)
This commit is contained in:
		
							
								
								
									
										40
									
								
								imgui.cpp
									
									
									
									
									
								
							
							
						
						
									
										40
									
								
								imgui.cpp
									
									
									
									
									
								
							| @@ -10578,13 +10578,6 @@ bool ImGui::InputScalarEx(const char* label, ImGuiDataType data_type, void* data | ||||
|  | ||||
|     ImGuiContext& g = *GImGui; | ||||
|     const ImGuiStyle& style = g.Style; | ||||
|     const ImVec2 label_size = CalcTextSize(label, NULL, true); | ||||
|     const ImVec2 button_size = ImVec2(GetFrameHeight(), GetFrameHeight()); | ||||
|  | ||||
|     BeginGroup(); | ||||
|     PushID(label); | ||||
|     if (step_ptr) | ||||
|         PushItemWidth(ImMax(1.0f, CalcItemWidth() - (button_size.x + style.ItemInnerSpacing.x)*2)); | ||||
|  | ||||
|     char buf[64]; | ||||
|     DataTypeFormatString(buf, IM_ARRAYSIZE(buf), data_type, data_ptr, scalar_format); | ||||
| @@ -10593,35 +10586,42 @@ bool ImGui::InputScalarEx(const char* label, ImGuiDataType data_type, void* data | ||||
|     if ((extra_flags & (ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsScientific)) == 0) | ||||
|         extra_flags |= ImGuiInputTextFlags_CharsDecimal; | ||||
|     extra_flags |= ImGuiInputTextFlags_AutoSelectAll; | ||||
|     if (InputText("", buf, IM_ARRAYSIZE(buf), extra_flags)) // PushId(label) + "" gives us the expected ID from outside point of view | ||||
|         value_changed = DataTypeApplyOpFromText(buf, GImGui->InputTextState.InitialText.begin(), data_type, data_ptr, scalar_format); | ||||
|  | ||||
|     // Step buttons | ||||
|     if (step_ptr) | ||||
|     { | ||||
|         const float button_size = GetFrameHeight(); | ||||
|  | ||||
|         BeginGroup(); // The only purpose of the group here is to allow the caller to query item data e.g. IsItemActive() | ||||
|         PushID(label); | ||||
|         PushItemWidth(ImMax(1.0f, CalcItemWidth() - (button_size + style.ItemInnerSpacing.x) * 2)); | ||||
|         if (InputText("", buf, IM_ARRAYSIZE(buf), extra_flags)) // PushId(label) + "" gives us the expected ID from outside point of view | ||||
|             value_changed = DataTypeApplyOpFromText(buf, g.InputTextState.InitialText.Data, data_type, data_ptr, scalar_format); | ||||
|         PopItemWidth(); | ||||
|  | ||||
|         // Step buttons | ||||
|         SameLine(0, style.ItemInnerSpacing.x); | ||||
|         if (ButtonEx("-", button_size, ImGuiButtonFlags_Repeat | ImGuiButtonFlags_DontClosePopups)) | ||||
|         if (ButtonEx("-", ImVec2(button_size, button_size), ImGuiButtonFlags_Repeat | ImGuiButtonFlags_DontClosePopups)) | ||||
|         { | ||||
|             DataTypeApplyOp(data_type, '-', data_ptr, data_ptr, g.IO.KeyCtrl && step_fast_ptr ? step_fast_ptr : step_ptr); | ||||
|             value_changed = true; | ||||
|         } | ||||
|         SameLine(0, style.ItemInnerSpacing.x); | ||||
|         if (ButtonEx("+", button_size, ImGuiButtonFlags_Repeat | ImGuiButtonFlags_DontClosePopups)) | ||||
|         if (ButtonEx("+", ImVec2(button_size, button_size), ImGuiButtonFlags_Repeat | ImGuiButtonFlags_DontClosePopups)) | ||||
|         { | ||||
|             DataTypeApplyOp(data_type, '+', data_ptr, data_ptr, g.IO.KeyCtrl && step_fast_ptr ? step_fast_ptr : step_ptr); | ||||
|             value_changed = true; | ||||
|         } | ||||
|     } | ||||
|     PopID(); | ||||
|  | ||||
|     if (label_size.x > 0) | ||||
|     { | ||||
|         SameLine(0, style.ItemInnerSpacing.x); | ||||
|         RenderText(ImVec2(window->DC.CursorPos.x, window->DC.CursorPos.y + style.FramePadding.y), label); | ||||
|         ItemSize(label_size, style.FramePadding.y); | ||||
|         TextUnformatted(label, FindRenderedTextEnd(label)); | ||||
|  | ||||
|         PopID(); | ||||
|         EndGroup(); | ||||
|     } | ||||
|     else | ||||
|     { | ||||
|         if (InputText(label, buf, IM_ARRAYSIZE(buf), extra_flags)) | ||||
|             value_changed = DataTypeApplyOpFromText(buf, g.InputTextState.InitialText.Data, data_type, data_ptr, scalar_format); | ||||
|     } | ||||
|     EndGroup(); | ||||
|  | ||||
|     return value_changed; | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user