With the creation of a new UI form management system, I went with a doubly linked list to hold the UI form data and pointers to the two adjacent UI forms in the list.
I initially decided I was going to sort the list by rearranging the pointers of the UI forms as I iterated through the list. This sounds easy in theory, but when it comes down to writing the code... well it is a bit more difficult.
I do like a challenge, and I could probably get it to work eventually. But when moving a lot of pointers about just to sort one item in the list, our good friend the segfault is sure to be lingering for those unsuspecting rare instances that only appear months after implementation.
I then decided to take the easy approach, instead of moving all those pointers I would just swap the data for each IU form about. Although this is way easier, I was trying to avoid this approach due to the amount of data I would be moving. But then I realised that I am not sorting the list on every frame, I am actually only sorting the list when the UI manager pushes an event to evoke a UI form sort, which is not very often.
At first glance I noticed that the data was not easily swappable, because of its fragmented nature within the UI form struct, so I made a sub struct in the UI form struct to hold all UI form data. this required around 7000 lines of code to be changed, I am really grateful for the "search and replace" function in Code::BLocks, without which it would have taken a whole day to complete the change.
Basically UI_form->foo now becomes UI_form->data.foo etc...
Having the data in a single struct makes it very easy to swap about, hence the very simple method in the picture above that shows the new list sorting algorithm. Thats like only 20 lines of code. :)
Well now with that piece of of the puzzle in place, it is getting the UI manager to push list sort events when appropriate, and then on to other more visually exciting ideas that are on the todo list.