From 51c97a41aae358756421476eee42e4580cfd461a Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 17 Jan 2023 18:32:50 +0100 Subject: [PATCH] PlotHistogram, PlotLines: Passing negative sizes honor alignment like other widgets. --- docs/CHANGELOG.txt | 1 + imgui_internal.h | 2 +- imgui_widgets.cpp | 7 ++----- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index eeed3a62e..f4636d981 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -41,6 +41,7 @@ All changes: is scaled. Scaling wasn't taken into account, leading to ellipsis character straying slightly out of its expected boundaries. (#2775) - Text: Tweaked rendering of three-dots "..." ellipsis variant. (#2775, #4269) +- PlotHistogram, PlotLines: Passing negative sizes honor alignment like other widgets. ----------------------------------------------------------------------- diff --git a/imgui_internal.h b/imgui_internal.h index 987a215b5..09886beeb 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -3130,7 +3130,7 @@ namespace ImGui IMGUI_API void ColorPickerOptionsPopup(const float* ref_col, ImGuiColorEditFlags flags); // Plot - IMGUI_API int PlotEx(ImGuiPlotType plot_type, const char* label, float (*values_getter)(void* data, int idx), void* data, int values_count, int values_offset, const char* overlay_text, float scale_min, float scale_max, ImVec2 frame_size); + IMGUI_API int PlotEx(ImGuiPlotType plot_type, const char* label, float (*values_getter)(void* data, int idx), void* data, int values_count, int values_offset, const char* overlay_text, float scale_min, float scale_max, const ImVec2& size_arg); // Shade functions (write over already created vertices) IMGUI_API void ShadeVertsLinearColorGradientKeepAlpha(ImDrawList* draw_list, int vert_start_idx, int vert_end_idx, ImVec2 gradient_p0, ImVec2 gradient_p1, ImU32 col0, ImU32 col1); diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 0613ef8e0..278ab3c70 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -6546,7 +6546,7 @@ bool ImGui::ListBox(const char* label, int* current_item, bool (*items_getter)(v // - others https://github.com/ocornut/imgui/wiki/Useful-Extensions //------------------------------------------------------------------------- -int ImGui::PlotEx(ImGuiPlotType plot_type, const char* label, float (*values_getter)(void* data, int idx), void* data, int values_count, int values_offset, const char* overlay_text, float scale_min, float scale_max, ImVec2 frame_size) +int ImGui::PlotEx(ImGuiPlotType plot_type, const char* label, float (*values_getter)(void* data, int idx), void* data, int values_count, int values_offset, const char* overlay_text, float scale_min, float scale_max, const ImVec2& size_arg) { ImGuiContext& g = *GImGui; ImGuiWindow* window = GetCurrentWindow(); @@ -6557,10 +6557,7 @@ int ImGui::PlotEx(ImGuiPlotType plot_type, const char* label, float (*values_get const ImGuiID id = window->GetID(label); const ImVec2 label_size = CalcTextSize(label, NULL, true); - if (frame_size.x == 0.0f) - frame_size.x = CalcItemWidth(); - if (frame_size.y == 0.0f) - frame_size.y = label_size.y + (style.FramePadding.y * 2); + const ImVec2 frame_size = CalcItemSize(size_arg, CalcItemWidth(), label_size.y + style.FramePadding.y * 2.0f); const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + frame_size); const ImRect inner_bb(frame_bb.Min + style.FramePadding, frame_bb.Max - style.FramePadding);