Although this isn’t exactly what I was asking about, I think I’m starting to understand. So you are trying to make some structure around SDL events for your application (i.e. you just want to know a good way to read the messages as opposed to just rolling your own message pool)
The second comment I’d like to make is that I don’t really know the rules by which these diagrams works and at least for me these diagrams are unreadable and would probably require some text describing what it means. That said I’ll try to interpret it to the best of my ability.
Judging by the fact that you have layout and Widgets and your Renderer is connected to the Main Loop I presume you are making a retained-mode GUI application, where the events from SDL (user input, window resizes) dictate when the application should be re-rendered. In which case consider this - if the window size changes you need to re-compute the layout of widgets. This means the layout widget doesn’t only need to know the size of the window but also when it changes. If the size of the layout changes it would change the location of other widgets and layouts and those might need to be recomputed as well.
This means what you want to do is – rather than storing the window size, you could actually write your own messaging system with callbacks. Your window would have a “root layout” that would have the size of the entire window. When window resizes, the SDL callback function can call into root layout’s event function telling it “hey you need to resize”, which would resize everything. After root layout finished re-computing everything you can run the renderer.
In pseudocode it’s something like this:
Window :: struct {
/* ... */
layout: Layout,
}
Layout :: struct {
cur_width: int,
cur_height: int,
widgets: []Widget,
// A generic event procedure, would be called with up to two parameters depending on the type
// of the event.
event_proc :: #type proc(l: ^Layout, event_type: Event_Type, param1: int, param2: rawptr),
}
Inside your SDL event loop you’d call the event_proc
function with parameters window_width
and window_height
, which would start the process of recomputing the layout for that window size.
tbh this is a hard question because it asks about architecture and you can think infinitely long about this sort of stuff. I’m getting a lil tired so I hope whatever I’ve written above helps