3 ms·
That sounds reasonable to me. I remember game loops being split into one draw() and one update() function and would expect UI frameworks to be the same. I thin
by zogrodea 3y ago
That sounds reasonable to me. I remember game loops being split into one draw() and one update() function and would expect UI frameworks to be the same.
I think, in games, it's usual to traverse twice through each object in a graph on each loop, once for drawing and once for updating/handling interactions.
Am I right guessing that UI frameworks do something similar? One update function traversing through each widget to check for interactions. Then two drawing-related functions, with one checking for each object whether it changed and needs to be redrawn, and the second drawing just those widgets that changed?
I'm trying to think in terms of Big O, and it doesn't sound unreasonable to drop the change-calcylation function and redraw from scratch because that way you would have two O(n) functions instead of three. Maybe the constant factor of drawing pixels to the screen is high enough to outweigh that additional change-detection loop.
- fxtentacle 3y ago"Am I right guessing that UI frameworks do something similar?" most of them try to avoid the update() loop because UI elements usually only change if the application state changes (and then you call paint() or invalidate()) or if the window moves or gets dis-occluded (then the OS calls invalidate()) or if the mouse cursor moves. So typically, the UI framework will have a "dirty" rectangle flag which represents the pixel area that needs to be redrawn.