Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Box selection [Mac] #171

Closed
kivicode opened this issue Jan 19, 2021 · 16 comments
Closed

Box selection [Mac] #171

kivicode opened this issue Jan 19, 2021 · 16 comments

Comments

@kivicode
Copy link

kivicode commented Jan 19, 2021

Hello! I'm a bit confused with the box selection process. Firstly, there is a line that ImPlotFlags_Selection flag was changed to ImPlotFlags_BoxSelect (see implot.cpp), but I can't find neither statement that ImPlotFlags_BoxSelect has been deleted, nor that it's being used in the code. So the main question is how to enable box selection/zooming?

@epezent
Copy link
Owner

epezent commented Jan 19, 2021

@kivicode , all flags including ImPlotFlags_BoxSelect were eventually changed as follows:

- 2020/09/06 (0.7) - Several flags under ImPlotFlags and ImPlotAxisFlags were inverted (e.g. ImPlotFlags_Legend -> ImPlotFlags_NoLegend) so that the default flagset
                     is simply 0. This more closely matches ImGui's style and makes it easier to enable non-default but commonly used flags (e.g. ImPlotAxisFlags_Time).

Thus the flag in question is now ImPlotFlags_NoBoxSelect. Therefore, unless you specifically enable this flag, box selection is enabled by default. Simply right click drag inside of the plot area :)

@epezent
Copy link
Owner

epezent commented Jan 19, 2021

See also: #48 (comment)

@kivicode
Copy link
Author

Thank you! I've just checked but ImPlotFlags_NoBoxSelect is false, but I can't use the box selection. May it be an OSX-related event handling problem or something like that?

@epezent
Copy link
Owner

epezent commented Jan 19, 2021

Hmm, can you post the code you use to create the plot? It might be related to a change I made yesterday #170 but I doubt it. I don't currently have a mac to check on.

@kivicode
Copy link
Author

Sure, I've made a blank project to test it. I've just realized that it actually works, but there is no border or other visual notification. So, now there is another question how to turn it on 😅

@epezent
Copy link
Owner

epezent commented Jan 19, 2021

So the plot resizes when you right-click drag and release, but you cannot see the box drawn like so:

bs

The only thing that comes to mind is that you've set the style variable ImPlotCol_Selection to a fully transparent color. Otherwise, it would seem to be a rendering issue with your backend. If you could, post a GIF of what is happening.

@epezent
Copy link
Owner

epezent commented Jan 19, 2021

I'm wondering if it is related to the selection box adding 25% alpha to desired color. It seems like there have been issues with the OpenGL2 backend in the past ocornut/imgui#3000, which you are using.

@kivicode
Copy link
Author

Hmm, alpha bending seems to be ok everywhere else. The gif was recorded with the latest backend from the original ImGui repo and the code snippet I've posted earlier implot-2

@epezent
Copy link
Owner

epezent commented Jan 19, 2021

That's bizarre. You might try removing the 25% alpha multiplier here and reporting back if this at least makes the box visible. Obviously this is not ideal, but it gets us closer to solving the issue:

implot/implot.cpp

Line 2282 in c73509d

const ImU32 col_bg = ImGui::GetColorU32(col * ImVec4(1,1,1,0.25f));

@kivicode
Copy link
Author

Unfortunately not, it didn't help

@epezent
Copy link
Owner

epezent commented Jan 19, 2021

Ok thanks, then it is probably not a rendering issue. Possibly the code that renders the box is not getting reached for some reason. I am not able to reproduce this issue here, so you'll need to step through this with a debugger or just throw some print statements in there. In particular I'd like to know if any of the DrawList.AddRect... calls are being made.

implot/implot.cpp

Lines 2275 to 2301 in c73509d

if (plot.Selecting) {
const ImRect select_bb(ImMin(IO.MousePos, plot.SelectStart), ImMax(IO.MousePos, plot.SelectStart));
const bool wide_enough = ImFabs(select_bb.GetWidth()) > 2;
const bool tall_enough = ImFabs(select_bb.GetHeight()) > 2;
const bool big_enough = wide_enough && tall_enough;
if (plot.Selecting && !plot.IsLocked() && !ImHasFlag(plot.Flags, ImPlotFlags_NoBoxSelect)) {
const ImVec4 col = GetStyleColorVec4(ImPlotCol_Selection);
const ImU32 col_bg = ImGui::GetColorU32(col * ImVec4(1,1,1,0.25f));
const ImU32 col_bd = ImGui::GetColorU32(col);
if (IO.KeyMods == (gp.InputMap.HorizontalMod | gp.InputMap.VerticalMod) && big_enough) {
DrawList.AddRectFilled(plot.PlotRect.Min, plot.PlotRect.Max, col_bg);
DrawList.AddRect( plot.PlotRect.Min, plot.PlotRect.Max, col_bd);
}
else if ((plot.XAxis.IsLocked() || IO.KeyMods == gp.InputMap.HorizontalMod) && tall_enough) {
DrawList.AddRectFilled(ImVec2(plot.PlotRect.Min.x, select_bb.Min.y), ImVec2(plot.PlotRect.Max.x, select_bb.Max.y), col_bg);
DrawList.AddRect( ImVec2(plot.PlotRect.Min.x, select_bb.Min.y), ImVec2(plot.PlotRect.Max.x, select_bb.Max.y), col_bd);
}
else if ((any_y_locked || IO.KeyMods == gp.InputMap.VerticalMod) && wide_enough) {
DrawList.AddRectFilled(ImVec2(select_bb.Min.x, plot.PlotRect.Min.y), ImVec2(select_bb.Max.x, plot.PlotRect.Max.y), col_bg);
DrawList.AddRect( ImVec2(select_bb.Min.x, plot.PlotRect.Min.y), ImVec2(select_bb.Max.x, plot.PlotRect.Max.y), col_bd);
}
else if (big_enough) {
DrawList.AddRectFilled(select_bb.Min, select_bb.Max, col_bg);
DrawList.AddRect( select_bb.Min, select_bb.Max, col_bd);
}
}
}

@kivicode
Copy link
Author

Okay, it's late at night here, so I'll go through it a bit later.

@epezent
Copy link
Owner

epezent commented Jan 19, 2021

Sounds good. Thanks for your help!

@epezent
Copy link
Owner

epezent commented Jan 19, 2021

I just tested this on a Raspberry Pi 4 (closest thing I have to a Unix type environment) using OpenGL2 and everything is still fine on my end. So confused by this.

Can you try changing the box color by setting or pushing a new value for ImPlotCol_Selection and seeing if anything changes?

@kivicode
Copy link
Author

I've finally found the problem! It turns out to be about ImGui default OSX backed realization rather then ImPlot itself. The problem was that during right mouse button dragging the IO mouse position wasn't updating (so the rect had zero area). I've solved it by simply adding || event.type == NSEventTypeRightMouseDragged here. Now it works as it supposed to and I'm closing the issue.

Thank you!

@epezent
Copy link
Owner

epezent commented Jan 20, 2021

Awesome. Glad it's working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants