As some of you might already know I'm writing a UI library, for personal esteem of course, nothing official or public yet.
It will be Windows only library and not cross platform primarily because it takes much less work.
All my work so far was not too hard, it all boils down to finding the right API's and design patterns to achieve some goal, there are of course gray areas which are more difficult than others but everything is achievable with enough effort.
But eventually I've hit a wall, and that wall is called UI layout.
When I started I thought it would be as simple as declaring few enums which would specify alignment, orientation, sizing etc., for ex.
Alignment: Left
Orientation: Horizontal
Sizing: Optimal
etc..
And then simply a for loop that would reposition controls according to those options.
But no man, it's far more difficult that few enums!
What if there is no horizontal space left?
What if not all controls are same size?
If you resize for excess space this might make some controls look ugly.
What if a portion of controls should be vertically positioned and another portion horizontally?
What if alignment for a group of controls should be left, for other group right and yet another centered?
What if an element is a picture control which requires aspect ratio to not be violated?
What if a control can not be resized beyond some limit due to MINMAX specification?
What if there is not enough client area space to layout all the controls, what to do with the surplus controls then?
What if, what if, what if, you continue this madness to make it worse.
This madness made me googling out about UI layout and I've learned that there is a whole research branch going around UI layout, there is a thing called linear programming and a bunch or complex math and algorithms which one should understand to get anywhere.
Here is one such research paper useful to get a grasp of theory:
https://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.127.7519
It become obvious to me that I've opened up a can of worms lol.
Sadly all those research papers are difficult in theory which one should transform into a code somehow to make use of them.
I've also learned that every UI library or framework provides the so called "layout engine" and there are many ways to implement a layout engine.
I started to write my layout manager class like 5 days ago but I'm still struggling because one algorithm can not solve every possible desired layout result.
My only invention so far is splitting window client area into virtual regions, where each region is managed by a separate layout manager instance assigned with a portion of controls.
This way it's possible to move, resize and scale regions and reposition controls within region independently of other virtual regions or controls.
Each region thus can run it's own layout style and algorithm.
I would like to hear your experience with UI layout, and if you have any useful research papers, algorithms, or anything useful about UI layout to please share here.
If you have any hints about UI layout that would be great because every bit of information can be useful.
edit:
Also if you know of any good tutorials it would be great, I've found this one to be useful although not really advanced:
https://www.codeproject.com/Articles/11316/Control-Positioning-and-Sizing-using-a-C-Helper-Cl
This MS resource for XAML is also useful to convert into C++ and to get some basic understanding of what should layout engine do:
https://learn.microsoft.com/en-us/dotnet/desktop/wpf/advanced/alignment-margins-and-padding-overview?view=netframeworkdesktop-4.8