mirror of
				https://github.com/Drezil/imgui.git
				synced 2025-10-31 21:21:06 +01:00 
			
		
		
		
	PlotHistogram: Fixed zero-line position when manually specifying min<0 and max>0. (#4349)
+ amended demo tweaks by ocornut
This commit is contained in:
		
				
					committed by
					
						 ocornut
						ocornut
					
				
			
			
				
	
			
			
			
						parent
						
							03ce17f0a5
						
					
				
				
					commit
					eb6c16d3dd
				
			| @@ -47,6 +47,7 @@ Other Changes: | ||||
|   the whole widget is clipped. | ||||
| - TextUnformatted: Accept null ranges including (NULL,NULL) without asserting, in order to conform | ||||
|   to common idioms (e.g. passing .data(), .data() + .size() from a null string). (#3615) | ||||
| - PlotHistogram: Fixed zero-line position when manually specifying min<0 and max>0. (#4349) [@filippocrocchini] | ||||
| - IO: Added 'io.WantCaptureMouseUnlessPopupClose' alternative to `io.WantCaptureMouse'. (#4480) | ||||
|   This allows apps to receive the click on void when that click is used to close popup (by default, | ||||
|   clicking on a void when a popup is open will close the popup but not release io.WantCaptureMouse). | ||||
|   | ||||
| @@ -1561,16 +1561,17 @@ static void ShowDemoWindowWidgets() | ||||
|     } | ||||
|  | ||||
|     // Plot/Graph widgets are not very good. | ||||
|     // Consider writing your own, or using a third-party one, see: | ||||
|     // - ImPlot https://github.com/epezent/implot | ||||
|     // - others https://github.com/ocornut/imgui/wiki/Useful-Extensions | ||||
|     // Consider using a third-party library such as ImPlot: https://github.com/epezent/implot | ||||
|     // (see others https://github.com/ocornut/imgui/wiki/Useful-Extensions) | ||||
|     if (ImGui::TreeNode("Plots Widgets")) | ||||
|     { | ||||
|         static bool animate = true; | ||||
|         ImGui::Checkbox("Animate", &animate); | ||||
|  | ||||
|         // Plot as lines and plot as histogram | ||||
|         static float arr[] = { 0.6f, 0.1f, 1.0f, 0.5f, 0.92f, 0.1f, 0.2f }; | ||||
|         ImGui::PlotLines("Frame Times", arr, IM_ARRAYSIZE(arr)); | ||||
|         ImGui::PlotHistogram("Histogram", arr, IM_ARRAYSIZE(arr), 0, NULL, 0.0f, 1.0f, ImVec2(0, 80.0f)); | ||||
|  | ||||
|         // Fill an array of contiguous float values to plot | ||||
|         // Tip: If your float aren't contiguous but part of a structure, you can pass a pointer to your first float | ||||
| @@ -1600,7 +1601,6 @@ static void ShowDemoWindowWidgets() | ||||
|             sprintf(overlay, "avg %f", average); | ||||
|             ImGui::PlotLines("Lines", values, IM_ARRAYSIZE(values), values_offset, overlay, -1.0f, 1.0f, ImVec2(0, 80.0f)); | ||||
|         } | ||||
|         ImGui::PlotHistogram("Histogram", arr, IM_ARRAYSIZE(arr), 0, NULL, 0.0f, 1.0f, ImVec2(0, 80.0f)); | ||||
|  | ||||
|         // Use functions to generate output | ||||
|         // FIXME: This is rather awkward because current plot API only pass in indices. | ||||
|   | ||||
| @@ -6471,7 +6471,7 @@ int ImGui::PlotEx(ImGuiPlotType plot_type, const char* label, float (*values_get | ||||
|         float v0 = values_getter(data, (0 + values_offset) % values_count); | ||||
|         float t0 = 0.0f; | ||||
|         ImVec2 tp0 = ImVec2( t0, 1.0f - ImSaturate((v0 - scale_min) * inv_scale) );                       // Point in the normalized space of our target rectangle | ||||
|         float histogram_zero_line_t = (scale_min * scale_max < 0.0f) ? (-scale_min * inv_scale) : (scale_min < 0.0f ? 0.0f : 1.0f);   // Where does the zero line stands | ||||
|         float histogram_zero_line_t = (scale_min * scale_max < 0.0f) ? (1 + scale_min * inv_scale) : (scale_min < 0.0f ? 0.0f : 1.0f);   // Where does the zero line stands | ||||
|  | ||||
|         const ImU32 col_base = GetColorU32((plot_type == ImGuiPlotType_Lines) ? ImGuiCol_PlotLines : ImGuiCol_PlotHistogram); | ||||
|         const ImU32 col_hovered = GetColorU32((plot_type == ImGuiPlotType_Lines) ? ImGuiCol_PlotLinesHovered : ImGuiCol_PlotHistogramHovered); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user