MCPcopy Create free account
hub / github.com/IppClub/Dora-SSR / DragLineX

Function DragLineX

Source/3rdParty/implot/implot.cpp:4015–4068  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4013}
4014
4015bool DragLineX(int n_id, double* value, const ImVec4& col, float thickness, ImPlotDragToolFlags flags, bool* out_clicked, bool* out_hovered, bool* out_held) {
4016 // ImGui::PushID("#IMPLOT_DRAG_LINE_X");
4017 ImPlotContext& gp = *GImPlot;
4018 IM_ASSERT_USER_ERROR(gp.CurrentPlot != nullptr, "DragLineX() needs to be called between BeginPlot() and EndPlot()!");
4019 SetupLock();
4020
4021 if (!ImHasFlag(flags,ImPlotDragToolFlags_NoFit) && FitThisFrame()) {
4022 FitPointX(*value);
4023 }
4024
4025 const bool input = !ImHasFlag(flags, ImPlotDragToolFlags_NoInputs);
4026 const bool show_curs = !ImHasFlag(flags, ImPlotDragToolFlags_NoCursors);
4027 const bool no_delay = !ImHasFlag(flags, ImPlotDragToolFlags_Delayed);
4028 const float grab_half_size = ImMax(DRAG_GRAB_HALF_SIZE, thickness/2);
4029 float yt = gp.CurrentPlot->PlotRect.Min.y;
4030 float yb = gp.CurrentPlot->PlotRect.Max.y;
4031 float x = IM_ROUND(PlotToPixels(*value,0,IMPLOT_AUTO,IMPLOT_AUTO).x);
4032 const ImGuiID id = ImGui::GetCurrentWindow()->GetID(n_id);
4033 ImRect rect(x-grab_half_size,yt,x+grab_half_size,yb);
4034 bool hovered = false, held = false;
4035
4036 ImGui::KeepAliveID(id);
4037 if (input) {
4038 bool clicked = ImGui::ButtonBehavior(rect,id,&hovered,&held);
4039 if (out_clicked) *out_clicked = clicked;
4040 if (out_hovered) *out_hovered = hovered;
4041 if (out_held) *out_held = held;
4042 }
4043
4044 if ((hovered || held) && show_curs)
4045 ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeEW);
4046
4047 float len = gp.Style.MajorTickLen.x;
4048 ImVec4 color = IsColorAuto(col) ? ImGui::GetStyleColorVec4(ImGuiCol_Text) : col;
4049 ImU32 col32 = ImGui::ColorConvertFloat4ToU32(color);
4050
4051 bool modified = false;
4052 if (held && ImGui::IsMouseDragging(0)) {
4053 *value = ImPlot::GetPlotMousePos(IMPLOT_AUTO,IMPLOT_AUTO).x;
4054 modified = true;
4055 }
4056
4057 PushPlotClipRect();
4058 ImDrawList& DrawList = *GetPlotDrawList();
4059 if (modified && no_delay)
4060 x = IM_ROUND(PlotToPixels(*value,0,IMPLOT_AUTO,IMPLOT_AUTO).x);
4061 DrawList.AddLine(ImVec2(x,yt), ImVec2(x,yb), col32, thickness);
4062 DrawList.AddLine(ImVec2(x,yt), ImVec2(x,yt+len), col32, 3*thickness);
4063 DrawList.AddLine(ImVec2(x,yb), ImVec2(x,yb-len), col32, 3*thickness);
4064 PopPlotClipRect();
4065
4066 // ImGui::PopID();
4067 return modified;
4068}
4069
4070bool DragLineY(int n_id, double* value, const ImVec4& col, float thickness, ImPlotDragToolFlags flags, bool* out_clicked, bool* out_hovered, bool* out_held) {
4071 ImGui::PushID("#IMPLOT_DRAG_LINE_Y");

Callers 1

Demo_DragLinesFunction · 0.85

Calls 15

SetupLockFunction · 0.85
ImHasFlagFunction · 0.85
FitThisFrameFunction · 0.85
FitPointXFunction · 0.85
ImMaxFunction · 0.85
PlotToPixelsFunction · 0.85
GetCurrentWindowFunction · 0.85
IsColorAutoFunction · 0.85
GetStyleColorVec4Function · 0.85
GetPlotMousePosFunction · 0.85
PushPlotClipRectFunction · 0.85
GetPlotDrawListFunction · 0.85

Tested by

no test coverage detected