Zoom via external slider (as a poor mans replacement for multi touch pinch to zoom)
Hi Evan,
First of all, I have to say a big THANK YOU for this excellent library. Whenever I wanted another extra "bells and whistles" it was already covered and just a simple look at the demo, and "lift some code" from there.
The last major item I still need to tackle for my project is an easy way to zoom the diagram. The final version should run on a Raspberry PI with its own (multi) touch screen (panning already works with the normal touch to mouse translation from the OS). I know this problem has been brought up a few times before (here and in the ImGui project itself), but somehow I really need to find a solution or workaround.
I've already had an extensive look at SDL_MultiGesture(), but I'm having a hard time running even a simple SDL test on my particular hardware (not to mention multiple platform support...).
So my idea was to just add a horizontal and vertical slider next to the plot area and try to use them to zoom. That kinda worked, but for some reason I never figured out how to use the axis limits / links / ... (I tried many things) properly to make it work and feel "normal".
I think that ImPlot's public API is just not sufficient to achieve this.
Do you have any suggestions or ideas on how to achieve this?
Thanks in advance,
Maik
You can do it like this with buttons, should be easy to adapt to sliders.
// out of the draw loop
auto cond = ImPlotCond_Once;
...
if (ImGui::Button("Shift to the left")) {
cond = ImPlotCond_Always;
xMin = xMin - 10;
xMax = xMax - 10;
}
if (ImGui::Button("Zoom in")) {
cond = ImPlotCond_Always;
xMin = xMin + 10;
xMax = xMax - 10;
yMin = yMin + 10;
yMax = yMax - 10;
}
if (ImPlot::BeginPlot("##myplot", ImVec2(200,200), ImPlotFlags_None)) {
ImPlot::SetupAxesLimits(xMin, xMax, yMin, yMax, cond);
// your plot lines here
}
if (cond != ImPlotCond_Once) {
cond = ImPlotCond_Once;
}