1
0
Fork 0
mirror of https://github.com/gwm17/implot.git synced 2024-11-22 18:28:53 -05:00

fix selection over guides

This commit is contained in:
epezent 2020-09-18 08:22:06 -05:00
parent 0e9ceb6bc0
commit 297c69dae8
3 changed files with 41 additions and 30 deletions

View File

@ -2503,6 +2503,11 @@ bool HorizontalGuide(const char* id, double* value, const ImVec4& col, float thi
DrawList.AddLine(ImVec2(xl,y), ImVec2(xr,y), col32, thickness);
DrawList.AddLine(ImVec2(xl,y), ImVec2(xl+len,y), col32, 3*thickness);
DrawList.AddLine(ImVec2(xr,y), ImVec2(xr-len,y), col32, 3*thickness);
PopPlotClipRect();
if (gp.CurrentPlot->Selecting || gp.CurrentPlot->Querying)
return false;
ImVec2 old_cursor_pos = ImGui::GetCursorScreenPos();
ImVec2 new_cursor_pos = ImVec2(xl, y - grab_size / 2.0f);
ImGui::SetItemAllowOverlap();
@ -2517,6 +2522,7 @@ bool HorizontalGuide(const char* id, double* value, const ImVec4& col, float thi
snprintf(buf, 32, "%s = %.*f", id, Precision(range_y), *value);
ImVec2 size = ImGui::CalcTextSize(buf);
const int pad = 2;
PushPlotClipRect();
if (yax == 0) {
DrawList.AddRectFilled(ImVec2(xl,y-pad-size.y/2), ImVec2(xl + size.x + 2 * pad, y+pad+size.y/2), col32);
DrawList.AddText(ImVec2(xl+pad,y-size.y/2),CalcTextColor(color),buf);
@ -2525,8 +2531,8 @@ bool HorizontalGuide(const char* id, double* value, const ImVec4& col, float thi
DrawList.AddRectFilled(ImVec2(xr-size.x-2*pad,y-pad-size.y/2), ImVec2(xr, y+pad+size.y/2), col32);
DrawList.AddText(ImVec2(xr-size.x-pad,y-size.y/2),CalcTextColor(color),buf);
}
PopPlotClipRect();
}
PopPlotClipRect();
bool dragging = false;
if (ImGui::IsItemActive() && ImGui::IsMouseDragging(0)) {
@ -2557,6 +2563,11 @@ bool VerticalGuide(const char* id, double* value, const ImVec4& col, float thick
DrawList.AddLine(ImVec2(x,yt), ImVec2(x,yb), col32, thickness);
DrawList.AddLine(ImVec2(x,yt), ImVec2(x,yt+len), col32, 3*thickness);
DrawList.AddLine(ImVec2(x,yb), ImVec2(x,yb-len), col32, 3*thickness);
PopPlotClipRect();
if (gp.CurrentPlot->Selecting || gp.CurrentPlot->Querying)
return false;
ImVec2 old_cursor_pos = ImGui::GetCursorScreenPos();
ImVec2 new_cursor_pos = ImVec2(x - grab_size / 2.0f, yt);
ImGui::SetItemAllowOverlap();
@ -2570,10 +2581,11 @@ bool VerticalGuide(const char* id, double* value, const ImVec4& col, float thick
snprintf(buf, 32, "%s = %.*f", id, Precision(range_x), *value);
ImVec2 size = ImGui::CalcTextSize(buf);
const int pad = 2;
PushPlotClipRect();
DrawList.AddRectFilled(ImVec2(x - size.x/2 - pad, yb - size.y - 2*pad), ImVec2(x + pad + size.x/2, yb), col32);
DrawList.AddText(ImVec2(x - size.x/2, yb - size.y - pad), CalcTextColor(color), buf);
PopPlotClipRect();
}
PopPlotClipRect();
bool dragging = false;
if (ImGui::IsItemActive() && ImGui::IsMouseDragging(0)) {

View File

@ -404,6 +404,8 @@ IMPLOT_API void PlotText(const char* text, double x, double y, bool vertical=fal
// Plot Utils
//-----------------------------------------------------------------------------
// The following functions MUST be called before BeginPlot!
// Set the axes range limits of the next plot. Call right before BeginPlot(). If ImGuiCond_Always is used, the axes limits will be locked.
IMPLOT_API void SetNextPlotLimits(double xmin, double xmax, double ymin, double ymax, ImGuiCond cond = ImGuiCond_Once);
// Set the X axis range limits of the next plot. Call right before BeginPlot(). If ImGuiCond_Always is used, the X axis limits will be locked.
@ -423,27 +425,19 @@ IMPLOT_API void SetNextPlotTicksX(double x_min, double x_max, int n_ticks, const
IMPLOT_API void SetNextPlotTicksY(const double* values, int n_ticks, const char* const labels[] = NULL, bool show_default = false, int y_axis = 0);
IMPLOT_API void SetNextPlotTicksY(double y_min, double y_max, int n_ticks, const char* const labels[] = NULL, bool show_default = false, int y_axis = 0);
// The following functions MUST be called between Begin/EndPlot!
// Select which Y axis will be used for subsequent plot elements. The default is '0', or the first (left) Y axis. Enable 2nd and 3rd axes with ImPlotFlags_YAxisX.
IMPLOT_API void SetPlotYAxis(int y_axis);
// Hides or shows the next plot item (i.e. as if it were toggled from the legend). Use ImGuiCond_Always if you need to change this every frame.
IMPLOT_API void HideNextItem(bool hidden = true, ImGuiCond cond = ImGuiCond_Once);
// Convert pixels to a position in the current plot's coordinate system. A negative y_axis uses the current value of SetPlotYAxis (0 initially).
IMPLOT_API ImPlotPoint PixelsToPlot(const ImVec2& pix, int y_axis = IMPLOT_AUTO);
IMPLOT_API ImPlotPoint PixelsToPlot(float x, float y, int y_axis = IMPLOT_AUTO);
// Convert a position in the current plot's coordinate system to pixels. A negative y_axis uses the current value of SetPlotYAxis (0 initially).
IMPLOT_API ImVec2 PlotToPixels(const ImPlotPoint& plt, int y_axis = IMPLOT_AUTO);
IMPLOT_API ImVec2 PlotToPixels(double x, double y, int y_axis = IMPLOT_AUTO);
// Hides or shows the next plot item (i.e. as if it were toggled from the legend). Use ImGuiCond_Always if you need to change this every frame.
IMPLOT_API void HideNextItem(bool hidden = true, ImGuiCond cond = ImGuiCond_Once);
//-----------------------------------------------------------------------------
// Plot Queries
//-----------------------------------------------------------------------------
// Use these functions to retrieve information about the current plot. They
// MUST be called between BeginPlot and EndPlot!
// Get the current Plot position (top-left) in pixels.
IMPLOT_API ImVec2 GetPlotPos();
// Get the curent Plot size in pixels.
@ -458,16 +452,36 @@ IMPLOT_API bool IsPlotYAxisHovered(int y_axis = 0);
IMPLOT_API ImPlotPoint GetPlotMousePos(int y_axis = IMPLOT_AUTO);
// Returns the current plot axis range. A negative y_axis uses the current value of SetPlotYAxis (0 initially).
IMPLOT_API ImPlotLimits GetPlotLimits(int y_axis = IMPLOT_AUTO);
// Returns true if the current plot is being queried.
IMPLOT_API bool IsPlotQueried();
// Returns the current plot query bounds.
IMPLOT_API ImPlotLimits GetPlotQuery(int y_axis = IMPLOT_AUTO);
//-----------------------------------------------------------------------------
// Plot Tools
//-----------------------------------------------------------------------------
// Shows a draggable horizontal guide line. #col defaults to ImGuiCol_Text.
IMPLOT_API bool HorizontalGuide(const char* id, double* y_value, const ImVec4& col = IMPLOT_AUTO_COL, float thickness = 1);
// Shows a draggable vertical guide line. #col defaults to ImGuiCol_Text.
IMPLOT_API bool VerticalGuide(const char* id, double* x_value, const ImVec4& col = IMPLOT_AUTO_COL, float thickness = 1);
//-----------------------------------------------------------------------------
// Legend Utils and Tools
//-----------------------------------------------------------------------------
// Returns true if a plot item legend entry is hovered.
IMPLOT_API bool IsLegendEntryHovered(const char* label_id);
// Begin a drag and drop source from a legend entry. The only supported flag is SourceNoPreviewTooltip
IMPLOT_API bool BeginLegendDragDropSource(const char* label_id, ImGuiDragDropFlags flags = 0);
// End legend drag and drop source.
IMPLOT_API void EndLegendDragDropSource();
// Begin a popup for a legend entry.
IMPLOT_API bool BeginLegendPopup(const char* label_id, ImGuiMouseButton mouse_button = 1);
// End a popup for a legend entry.
IMPLOT_API void EndLegendPopup();
//-----------------------------------------------------------------------------
// Plot and Item Styling
//-----------------------------------------------------------------------------
@ -562,21 +576,6 @@ IMPLOT_API void ShowColormapScale(double scale_min, double scale_max, float heig
// Returns a null terminated string name for a built-in colormap.
IMPLOT_API const char* GetColormapName(ImPlotColormap colormap);
//-----------------------------------------------------------------------------
// Legend Utils
//-----------------------------------------------------------------------------
// Returns true if a plot item legend entry is hovered.
IMPLOT_API bool IsLegendEntryHovered(const char* label_id);
// Begin a drag and drop source from a legend entry. The only supported flag is SourceNoPreviewTooltip
IMPLOT_API bool BeginLegendDragDropSource(const char* label_id, ImGuiDragDropFlags flags = 0);
// End legend drag and drop source.
IMPLOT_API void EndLegendDragDropSource();
// Begin a popup for a legend entry.
IMPLOT_API bool BeginLegendPopup(const char* label_id, ImGuiMouseButton mouse_button = 1);
// End a popup for a legend entry.
IMPLOT_API void EndLegendPopup();
//-----------------------------------------------------------------------------
// Miscellaneous
//-----------------------------------------------------------------------------

View File

@ -823,7 +823,7 @@ void ShowDemoWindow(bool* p_open) {
ImPlot::SetPlotYAxis(0);
double xs[1000], ys[1000];
for (int i = 0; i < 1000; ++i) {
xs[i] = (x2+x1)/2+abs(x2-x1)*(i/990.0f - 0.5f);
xs[i] = (x2+x1)/2+abs(x2-x1)*(i/1000.0f - 0.5f);
ys[i] = (y1+y2)/2+abs(y2-y1)/2*sin(f*i/10);
}
ImPlot::PlotLine("Why Not?", xs, ys, 1000);