1
0
Fork 0
mirror of https://github.com/gwm17/implot.git synced 2024-11-23 02:38:53 -05:00

change function names, fix issues with scroll

This commit is contained in:
epezent 2020-09-18 22:05:43 -05:00
parent bbbf4e2a42
commit 9c4ef16696
3 changed files with 29 additions and 33 deletions

View File

@ -1273,6 +1273,7 @@ bool BeginPlot(const char* title, const char* x_label, const char* y_label, cons
gp.Hov_Frame = ImGui::ItemHoverable(gp.BB_Frame, ID);
if (G.HoveredIdPreviousFrame != 0 && G.HoveredIdPreviousFrame != ID)
gp.Hov_Frame = false;
ImGui::SetItemAllowOverlap();
ImGui::RenderFrame(gp.BB_Frame.Min, gp.BB_Frame.Max, GetStyleColorU32(ImPlotCol_FrameBg), true, Style.FrameRounding);
// canvas bb
@ -1722,7 +1723,6 @@ bool BeginPlot(const char* title, const char* x_label, const char* y_label, cons
}
}
ImGui::PopClipRect();
// push plot ID into stack
ImGui::PushID(ID);
return true;
@ -2483,9 +2483,9 @@ ImPlotLimits GetPlotQuery(int y_axis_in) {
return result;
}
bool HorizontalGuide(const char* id, double* value, const ImVec4& col, float thickness) {
bool GrabLineH(const char* id, double* value, const ImVec4& col, float thickness) {
ImPlotContext& gp = *GImPlot;
IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "HorizontalGuide() needs to be called between BeginPlot() and EndPlot()!");
IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "GrabLineH() needs to be called between BeginPlot() and EndPlot()!");
const float grab_size = ImMax(5.0f, thickness);
float xl = gp.BB_Plot.Min.x;
float xr = gp.BB_Plot.Max.x;
@ -2493,7 +2493,6 @@ bool HorizontalGuide(const char* id, double* value, const ImVec4& col, float thi
const bool outside = y < (gp.BB_Plot.Min.y - grab_size / 2) || y > (gp.BB_Plot.Max.y + grab_size / 2);
if (outside)
return false;
float len = gp.Style.MajorTickLen.y;
ImVec4 color = IsColorAuto(col) ? ImGui::GetStyleColorVec4(ImGuiCol_Text) : col;
ImU32 col32 = ImGui::ColorConvertFloat4ToU32(color);
@ -2511,9 +2510,9 @@ bool HorizontalGuide(const char* id, double* value, const ImVec4& col, float thi
ImVec2 old_cursor_pos = ImGui::GetCursorScreenPos();
ImVec2 new_cursor_pos = ImVec2(xl, y - grab_size / 2.0f);
ImGui::SetItemAllowOverlap();
ImGui::SetCursorScreenPos(new_cursor_pos);
ImGui::GetCurrentWindow()->DC.CursorPos = new_cursor_pos;
ImGui::InvisibleButton(id, ImVec2(xr - xl, grab_size));
ImGui::SetCursorScreenPos(old_cursor_pos);
ImGui::GetCurrentWindow()->DC.CursorPos = old_cursor_pos;
int yax = GetCurrentYAxis();
if (ImGui::IsItemHovered() || ImGui::IsItemActive()) {
ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeNS);
@ -2543,9 +2542,9 @@ bool HorizontalGuide(const char* id, double* value, const ImVec4& col, float thi
return dragging;
}
bool VerticalGuide(const char* id, double* value, const ImVec4& col, float thickness) {
bool GrabLineV(const char* id, double* value, const ImVec4& col, float thickness) {
ImPlotContext& gp = *GImPlot;
IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "VerticalGuide() needs to be called between BeginPlot() and EndPlot()!");
IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "GrabLineV() needs to be called between BeginPlot() and EndPlot()!");
const float grab_size = ImMax(5.0f, thickness);
float yt = gp.BB_Plot.Min.y;
float yb = gp.BB_Plot.Max.y;
@ -2553,7 +2552,6 @@ bool VerticalGuide(const char* id, double* value, const ImVec4& col, float thick
const bool outside = x < (gp.BB_Plot.Min.x - grab_size / 2) || x > (gp.BB_Plot.Max.x + grab_size / 2);
if (outside)
return false;
float len = gp.Style.MajorTickLen.x;
ImVec4 color = IsColorAuto(col) ? ImGui::GetStyleColorVec4(ImGuiCol_Text) : col;
ImU32 col32 = ImGui::ColorConvertFloat4ToU32(color);
@ -2570,10 +2568,9 @@ bool VerticalGuide(const char* id, double* value, const ImVec4& col, float thick
ImVec2 old_cursor_pos = ImGui::GetCursorScreenPos();
ImVec2 new_cursor_pos = ImVec2(x - grab_size / 2.0f, yt);
ImGui::SetItemAllowOverlap();
ImGui::SetCursorScreenPos(new_cursor_pos);
ImGui::InvisibleButton(id, ImVec2(grab_size, yb-yt));
ImGui::SetCursorScreenPos(old_cursor_pos);
ImGui::GetCurrentWindow()->DC.CursorPos = new_cursor_pos;
ImGui::InvisibleButton(id, ImVec2(grab_size, yb-yt), ImGuiButtonFlags_DontClosePopups);
ImGui::GetCurrentWindow()->DC.CursorPos = old_cursor_pos;
if (ImGui::IsItemHovered() || ImGui::IsItemActive()) {
ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeEW);
double range_x = gp.XTicks.Size > 1 ? (gp.XTicks.Ticks[1].PlotPos - gp.XTicks.Ticks[0].PlotPos) : gp.CurrentPlot->XAxis.Range.Size();
@ -2596,14 +2593,13 @@ bool VerticalGuide(const char* id, double* value, const ImVec4& col, float thick
return dragging;
}
bool AnchorPoint(const char* id, double* x, double* y, const ImVec4& col, float radius) {
bool GrabPoint(const char* id, double* x, double* y, const ImVec4& col, float radius) {
ImPlotContext& gp = *GImPlot;
IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "AnchorPoint() needs to be called between BeginPlot() and EndPlot()!");
IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "GrabPoint() needs to be called between BeginPlot() and EndPlot()!");
const float grab_size = ImMax(5.0f, 2*radius);
const bool outside = !GetPlotLimits().Contains(*x,*y);
if (outside)
return false;
ImVec4 color = IsColorAuto(col) ? ImGui::GetStyleColorVec4(ImGuiCol_Text) : col;
ImU32 col32 = ImGui::ColorConvertFloat4ToU32(color);
ImDrawList& DrawList = *GetPlotDrawList();
@ -2617,10 +2613,9 @@ bool AnchorPoint(const char* id, double* x, double* y, const ImVec4& col, float
int yax = GetCurrentYAxis();
ImVec2 old_cursor_pos = ImGui::GetCursorScreenPos();
ImVec2 new_cursor_pos = ImVec2(pos - ImVec2(grab_size,grab_size)*0.5f);
ImGui::SetItemAllowOverlap();
ImGui::SetCursorScreenPos(new_cursor_pos);
ImGui::GetCurrentWindow()->DC.CursorPos = new_cursor_pos;
ImGui::InvisibleButton(id, ImVec2(grab_size, grab_size));
ImGui::SetCursorScreenPos(old_cursor_pos);
ImGui::GetCurrentWindow()->DC.CursorPos = old_cursor_pos;
if (ImGui::IsItemHovered() || ImGui::IsItemActive()) {
ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeAll);
// double range_x = gp.XTicks.Size > 1 ? (gp.XTicks.Ticks[1].PlotPos - gp.XTicks.Ticks[0].PlotPos) : gp.CurrentPlot->XAxis.Range.Size();

View File

@ -458,11 +458,11 @@ IMPLOT_API ImPlotLimits GetPlotLimits(int y_axis = IMPLOT_AUTO);
//-----------------------------------------------------------------------------
// 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);
IMPLOT_API bool GrabLineH(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);
IMPLOT_API bool GrabLineV(const char* id, double* x_value, const ImVec4& col = IMPLOT_AUTO_COL, float thickness = 1);
// Shows a draggable anchor point. #col defaults to ImGuiCol_Text.
IMPLOT_API bool AnchorPoint(const char* id, double* x, double* y, const ImVec4& col = IMPLOT_AUTO_COL, float radius = 5);
IMPLOT_API bool GrabPoint(const char* id, double* x, double* y, const ImVec4& col = IMPLOT_AUTO_COL, float radius = 5);
// Returns true if the current plot is being queried. Query must be enabled with ImPlotFlags_Query.
IMPLOT_API bool IsPlotQueried();

View File

@ -805,7 +805,7 @@ void ShowDemoWindow(bool* p_open) {
}
}
//-------------------------------------------------------------------------
if (ImGui::CollapsingHeader("Guides and Anchors")) {
if (ImGui::CollapsingHeader("Grab Lines and Points")) {
ImGui::BulletText("Click and drag the horizontal and vertical guide lines.");
static double x1 = 0.2;
static double x2 = 0.8;
@ -813,12 +813,12 @@ void ShowDemoWindow(bool* p_open) {
static double y2 = 0.75;
static double f = 0.1;
if (ImPlot::BeginPlot("##guides",0,0,ImVec2(-1,0),ImPlotFlags_YAxis2)) {
ImPlot::VerticalGuide("x1",&x1);
ImPlot::VerticalGuide("x2",&x2);
ImPlot::HorizontalGuide("y1",&y1);
ImPlot::HorizontalGuide("y2",&y2);
ImPlot::GrabLineV("x1",&x1);
ImPlot::GrabLineV("x2",&x2);
ImPlot::GrabLineH("y1",&y1);
ImPlot::GrabLineH("y2",&y2);
ImPlot::SetPlotYAxis(1);
ImPlot::HorizontalGuide("f",&f, ImVec4(1,0.5f,1,1));
ImPlot::GrabLineH("f",&f, ImVec4(1,0.5f,1,1));
ImPlot::SetPlotYAxis(0);
double xs[1000], ys[1000];
@ -829,9 +829,10 @@ void ShowDemoWindow(bool* p_open) {
ImPlot::PlotLine("Why Not?", xs, ys, 1000);
ImPlot::EndPlot();
}
ImGui::BulletText("Click and drag the anchor points.");
ImPlotAxisFlags flags = ImPlotAxisFlags_NoTickLabels | ImPlotAxisFlags_NoTickMarks;
ImPlot::SetNextPlotLimits(0,1,0,1,ImGuiCond_Always);
// ImPlot::SetNextPlotLimits(0,1,0,1,ImGuiCond_Always);
if (ImPlot::BeginPlot("##Bezier",0,0,ImVec2(-1,0),ImPlotFlags_CanvasOnly|ImPlotFlags_NoChild,flags,flags)) {
static ImPlotPoint P[] = {ImPlotPoint(0,0), ImPlotPoint(0.2,0.4), ImPlotPoint(0.8,0.6), ImPlotPoint(1,1)};
static ImPlotPoint B[100];
@ -853,10 +854,10 @@ void ShowDemoWindow(bool* p_open) {
ImPlot::PlotLine("##h1",&P[0].x, &P[0].y, 2, 0, sizeof(ImPlotPoint));
ImPlot::SetNextLineStyle(gray, 2);
ImPlot::PlotLine("##h2",&P[2].x, &P[2].y, 2, 0, sizeof(ImPlotPoint));
ImPlot::AnchorPoint("P0",&P[0].x,&P[0].y,gray);
ImPlot::AnchorPoint("P1",&P[1].x,&P[1].y,gray);
ImPlot::AnchorPoint("P2",&P[2].x,&P[2].y,gray);
ImPlot::AnchorPoint("P3",&P[3].x,&P[3].y,gray);
ImPlot::GrabPoint("P0",&P[0].x,&P[0].y,gray);
ImPlot::GrabPoint("P1",&P[1].x,&P[1].y,gray);
ImPlot::GrabPoint("P2",&P[2].x,&P[2].y,gray);
ImPlot::GrabPoint("P3",&P[3].x,&P[3].y,gray);
ImPlot::EndPlot();
}
}