If you have a large list of custom structs that needs an "outside world" connection, there two solutions that use no more memory than is least required:
It would be easier to answer if you would provide an example of when knowledge of the outside world needs to be known.
If hovering requires special changes to the graphics of the widget, then the widget needs to know it is hovering or not hovering.
If there can be only one widget that can hover at a time, then the manager of the whole set of widgets needs to tell the previously hovering widget that it is no longer hovering (change a state flag) and tell the new one it is. Fairly trivial if the manager simply keeps a pointer to the one widget that is hovering.
Here is the problem.
Let’s assume both of the above rules are necessary, and that is what you tried to explain.
But when you explained it you stated it as a single rule.
It isn’t one rule. It is 2 separate rules localized to the objects that made those rules exist.
If a widget needs to do special rendering for a hover state, then all widgets need a flag for that, since it is their own job to live inside their own little box (with no knowledge of the outside world
) and handle the functionality they were meant to handle.
And if only one widget can be hovering, or have focus, or whatever else, then you need to think about who actually made that rule. It certainly wasn’t the widgets themselves.
They live in a box, with no connection to the outside world.
It was the widget manager who decided it could only keep track of one widget having focus or hovering.
It should obviously be the widget manager who tracks that data.
Data about past clicks?
Considering that users could drag from one control and into another, it probably makes the widget manager a good candidate for the task of keeping track of the mouse history.
Basically, if you ever need to ask how to make widgets aware of the outside world, you are doing it wrong, because there is
no reason. It should never
happen under any circumstances.
So next time you feel the urge to ask that question, consider that it means you have not properly separated the rules for objects and what should handle those rules, and rethink your design.