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

Function DragLineY

Source/3rdParty/implot/implot.cpp:4070–4124  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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");
4072 ImPlotContext& gp = *GImPlot;
4073 IM_ASSERT_USER_ERROR(gp.CurrentPlot != nullptr, "DragLineY() needs to be called between BeginPlot() and EndPlot()!");
4074 SetupLock();
4075
4076 if (!ImHasFlag(flags,ImPlotDragToolFlags_NoFit) && FitThisFrame()) {
4077 FitPointY(*value);
4078 }
4079
4080 const bool input = !ImHasFlag(flags, ImPlotDragToolFlags_NoInputs);
4081 const bool show_curs = !ImHasFlag(flags, ImPlotDragToolFlags_NoCursors);
4082 const bool no_delay = !ImHasFlag(flags, ImPlotDragToolFlags_Delayed);
4083 const float grab_half_size = ImMax(DRAG_GRAB_HALF_SIZE, thickness/2);
4084 float xl = gp.CurrentPlot->PlotRect.Min.x;
4085 float xr = gp.CurrentPlot->PlotRect.Max.x;
4086 float y = IM_ROUND(PlotToPixels(0, *value,IMPLOT_AUTO,IMPLOT_AUTO).y);
4087
4088 const ImGuiID id = ImGui::GetCurrentWindow()->GetID(n_id);
4089 ImRect rect(xl,y-grab_half_size,xr,y+grab_half_size);
4090 bool hovered = false, held = false;
4091
4092 ImGui::KeepAliveID(id);
4093 if (input) {
4094 bool clicked = ImGui::ButtonBehavior(rect,id,&hovered,&held);
4095 if (out_clicked) *out_clicked = clicked;
4096 if (out_hovered) *out_hovered = hovered;
4097 if (out_held) *out_held = held;
4098 }
4099
4100 if ((hovered || held) && show_curs)
4101 ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeNS);
4102
4103 float len = gp.Style.MajorTickLen.y;
4104 ImVec4 color = IsColorAuto(col) ? ImGui::GetStyleColorVec4(ImGuiCol_Text) : col;
4105 ImU32 col32 = ImGui::ColorConvertFloat4ToU32(color);
4106
4107 bool modified = false;
4108 if (held && ImGui::IsMouseDragging(0)) {
4109 *value = ImPlot::GetPlotMousePos(IMPLOT_AUTO,IMPLOT_AUTO).y;
4110 modified = true;
4111 }
4112
4113 PushPlotClipRect();
4114 ImDrawList& DrawList = *GetPlotDrawList();
4115 if (modified && no_delay)
4116 y = IM_ROUND(PlotToPixels(0, *value,IMPLOT_AUTO,IMPLOT_AUTO).y);
4117 DrawList.AddLine(ImVec2(xl,y), ImVec2(xr,y), col32, thickness);
4118 DrawList.AddLine(ImVec2(xl,y), ImVec2(xl+len,y), col32, 3*thickness);
4119 DrawList.AddLine(ImVec2(xr,y), ImVec2(xr-len,y), col32, 3*thickness);
4120 PopPlotClipRect();
4121
4122 ImGui::PopID();
4123 return modified;
4124}
4125
4126bool DragRect(int n_id, double* x_min, double* y_min, double* x_max, double* y_max, const ImVec4& col, ImPlotDragToolFlags flags, bool* out_clicked, bool* out_hovered, bool* out_held) {
4127 ImGui::PushID("#IMPLOT_DRAG_RECT");

Callers 2

Demo_DragLinesFunction · 0.85
Demo_TagsFunction · 0.85

Calls 15

PushIDFunction · 0.85
SetupLockFunction · 0.85
ImHasFlagFunction · 0.85
FitThisFrameFunction · 0.85
FitPointYFunction · 0.85
ImMaxFunction · 0.85
PlotToPixelsFunction · 0.85
GetCurrentWindowFunction · 0.85
IsColorAutoFunction · 0.85
GetStyleColorVec4Function · 0.85
GetPlotMousePosFunction · 0.85
PushPlotClipRectFunction · 0.85

Tested by

no test coverage detected