-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
Custom widget - How to properly set hoverID for overlapping widgets? #4055
Comments
I'm working around for now by checking if the bottom bar was hovered after the code for rendering the knobs i.e. after the for loop by using |
I do not quite understand what you are trying to achieve, but it seem knobs should be part of |
That's how the original slider works. I want to differentiate when I'm hovering over the slider (the actual background frame or rect) and the actual knob ( the grab rect or circle in my case). I need this because I need to render multiple knobs when clicked on the background rect. So I want a way for the knob or the grab rect to override the hoverID of the background frame rect which I dont know if this should be a thing provided by ImGui or it should be handled by the programmer manually like I did. IF this was handled by ImGui then it'd need to remember that the Knobs are rendered over the background frame (the z order) and that the knobs were being hovered on the previous frame so in the current frame we the background frame rect shouldn't fire the hover event. Which seems quite messy, I admit. Just wanted to share my use case and get some suggestions. |
You know your slider rect, knob location, knob size - you can test if mouse position is within circle of knob. Basically it is all manual work calculating and testing various coordinates. I think you try to optimize it a bit, offloading certain behaviors for imgui to handle. While usually it is a good thing to do, when writing custom widgets this is suboptimal as you already discovered. |
Yes another way is to calculate the hovering of the background rect manually. Imgui already provides |
Not much of a problem i would say. What you should do is first handle all your knobs, and if no knob was hovered - handle hovering widget rect. You can use |
Now this is something I didn't know. I'll try it out. Thanks for the info. |
@rokups - totally diff topic but asking it here since I'd have to make another issue. Do you know how I can cause my custom widgets to get effected by scrolling? Here are 2 simple images to demonstrate the problem Here as you can see the button is rendered beneath my gradient bar. All good. What happens when the window size gets smaller and I have to scroll to the bottom. Apparently my custom gradient bar which is I think it has to do something with clipRects but those are calculated by the window correctly. I tried finding occurrences to |
I can't tell only by looking at that bit of code. Although i do have a small advice: use |
Yeah I already did that :) Thanks for pointing that out tho. That's the core code that draws the multicolor rect. Simply speaking I'm just doing
Any ideas what cause scrolling issues? Btw your |
Okay, I managed to solve the issue. And f me. I forgot to that I had changed the code I posted above. In order to wrap around the mess of absolute coordinates and relative coordinates what I did was pass relative coordinates to all the functions drawing through |
In case it may be useful, have you seen projects such as ImGradient? I haven't understood this whole thread but some TL;DR;
|
Thanks for the tips. I actually had seen that but I didn't got to see the pics of a gradient editor on his github, though the code does exist. Since this was for a very specific usecase (transfer functions in volume rendering) I decided to make my own. I'm also currently working on rendering cubic splines. Someone already did work for the bezier curves but I didn't see any for simple cubic splines. Hopefully will share the results so you can add it to the useful links if anyone needs them. |
Version: 1.80
Branch: master
Back-ends: OpenGL3 + GLFW
Operating System: Win10
Hey ocornut, I've been going through the internal code since the day before yesterday. I'm trying to create gradient bar which is editable. When the user clicks on this multi colored gradient bar a circular knob appears which can then be slided. This can happen multiple times.
Since the use case felt similar to Slider widget I read it's internal and have managed to code it fairly well. The only problem is setting hoveredIDs for overlapping widgets (the gradient bar and the circular knob) since in the slider use case, the background frame or bar and the knob don't need separate hoverIDs. Here's what I've coded currently,
Similar snippet goes for drawing the circular knob, just swap that
AddRectFilled
withAddCircleFilled
. Here's how I'm drawing themSo the problem is, if I don't use
ImGui::SetItemAllowOverlap()
the hoveredID is always set to the bottom gradient bar. This poses problems such as clicking once to get the knob. Then clicking again on the knob renders a second knob when this shouldn't happen. If i useImGui::SetItemAllowOverlap()
the hoveredIDs are set correctly but the hovered event is still fired for the gradient bar since I guess at the start of the new frame, the knob isn't rendered yet so we get the hover first on the bar and then the knob.Any suggestions for this use case? Sorry if I missed a similar issue.
The text was updated successfully, but these errors were encountered: