I need a layout algorithm and use it in the GUI, but I can't use existing GUI toolkits at the moment, so I would like to find a layout algorithm.
I only need to do a single row layout, and here is the description of the algorithm.
Input Data
First, there are three sequences. $$\begin{split} A &= x_1,x_2,\cdots,x_n \\ U &= u_1,u_2,\cdots,u_n \\ L &= l_1,l_2,\cdots,l_n \end{split}$$ Where:
- $A$ is the recommended size of each interface element known from measurements (this is a row layout, so it may be $x$ or $y$ axis).
- $U$ is the maximum size of each interface element.
- $L$ is the minimum size of each interface element.
Obviously, the interface element will be restricted between the maximum and minimum values, and $A$ is also consistent with this restriction.
In addition, there is a value $$g\in \mathbb{R}$$
This is the "remaining space" as I know it. For example, all the measured elements add up to 1000 pixels, and the container has 2000 pixels of space, so $g=1000$. The layout algorithm will allocate this remaining space to all elements. $g$ may be negative number, which means that the container space is too small, and it is time to reduce the size of some elements.
The result of the layout
The return value of the layout algorithm is a sequence $A'=x_1',x_2',\cdots,x_n'$, which is the final displayed interface element size. The values of this sequence element $x_i'$ are described below
If $g > 0$: $$ \forall x_i' \in A' \rightarrow x_i' = \begin{cases} x_i & x_i > \overline{x}\\ u_i & u_i < \overline{x}\\ \overline{x} & \rm{other} \end{cases} $$ If $g < 0$: $$ \forall x_i' \in A' \rightarrow x_i' = \begin{cases} x_i & x_i < \overline{x}\\ l_i & l_i > \overline{x}\\ \overline{x} & \rm{other} \end{cases} $$ And I ignored $g=0$ (is too simple). $\overline{x}$ is also a real number, which means that if no restrictions are triggered the layout tends to adjust the interface elements to be equal. However, when there is space left on the layout axis, we cannot reduce the recommended size of an element larger than $\overline{x}$ and cannot let the element exceed the maximum size limit, similarly when there is not enough space on the layout axis.
Eventually I will use all the space in the container, so $$\sum{x_i'}=\sum{x_i}+g$$
For example, suppose $A=10, 20, 40, 100$, $g=50$, and ignore the maximum and minimum size limits, then the $A'=40,40,40,100$. Note that the elements with recommended sizes $40$ and $100$ are not actually resized. And the other elements are modified to $\overline{x}=40$.
However, the reality is that I need to solve $\overline{x}$ under all the previously mentioned constraints (after which it is easy to calculate the size of each element), and at the moment I don't know how to do that. So is there any good way to do this?