This question isn't related to any specific language, I'm just asking about different algorithms.
I'm trying to make a custom UI from scratch for a desktop app. It needs to support lots of UI elements without lagging, and most of those elements have hover states. This means there needs to be an efficient way to check what (if anything) is being hovered over every time the mouse moves. I have a few ideas but they're all flawed and I'm not really sure what to do.
The best thing I've come up with so far is storing the bounds of the current hovered element along with all its neighbouring elements. If the mouse leaves the bounds of the element, it would check which neighbouring element it's inside of now and set that to the hovered element (copying its bounds and storing its neighbour elements and so on). Some of the neighbours could just be rectangles of empty space neighboured by other empty spaces and elements. I'm just asking because I'm not sure if this is the best solution.
(Also, if anyone knows the codebases of things like Qt and GTK well, what algorithms do they use?)
One difficulty might be having complex shapes for your elements. But you could just use a box to have a first check and then check if it is really above your element.
What i would do is create a box for each element, make a BSP with these boxes to avoid checking every single on of them. And for all matching boxes check the one element the cursor is really on. And of course only do that for elements that have a hover state.