I've been trying to search for this problem all around, but all I find is related to a high level thing, like "how to know which HTML is being clicked". That's not the kind of thing I'm looking for. I'm looking for a more low level detail.
Let's suppose someone is trying to write a GUI library for a given system. Also, let's say this programmer has already managed to display graphics, text, buttons, etc on screen. Now they want to implement ways for the user to interact with that interface, more specifically, using mouse clicks (or maybe touch input).
The system on which their GUI engine runs is capable of telling them when a click happens, and in what (x, y) point on the screen it occurs. To find which elements on the screen are being clicked, a simple approach would be to just loop through every element and test each of them. But is this how it is usually done in existing GUIs? For example, is this what browsers do when they display HTML pages? Is this what operating systems do with their GUIs and windows? Do they use more complex data structures like R-Trees? How do they handle moving elements?
This question is not specific to any software, I'm just wondering how this problem is usually adressed in this context of GUI development.