Fix a few bugs and add automatic sizing for layout containers.

This commit is contained in:
Signal 2026-03-07 16:30:53 -05:00
parent be73993547
commit 969030a026
2 changed files with 153 additions and 48 deletions

View file

@ -71,6 +71,10 @@ Besides these basic containers, however, imfs also provides several layouting co
* `imfs.row`: A flex row. This automatically positions elements within it based on the provided gap and alignment. Child elements may specify their width as a grow ratio like `"1x"` to dynamically resize to fill any empty space in the row. Higher grow ratios will cause the element to take up a larger portion of the available space compared to other dynamically sized elements.
* `imfs.column`: The same as `imfs.row`, but in the vertical direction.
Inside all containers (including the window), it is possible to specify properties of an element in terms of its parent's size, rather than with absolute formspec units. This is done by passing a percent string (like `"100%"`) instead of a number to the element's constructor. Percentage units may also optionally include a fixed offset to be applied to the computed percentage by following the percent with `+` or `-` and a number (like `"100% - 0.5"`).
Groups and flex containers may specify their width or height as `"auto"` to automatically compute their width or height based on the accumulated size of their children (note that for flex containers this only works on the secondary axis). Using percentage units relative to such a computed dimension, while technically possible, will likely cause problems, as doing so results in a circular dpendency (which is broken internally by having the container interpret relative sizes as zero for the purposes of `"auto"`).
To create a custom layouting container, the procedure is essentially as follows:
1. Create a Lua class for the container.
2. In the class constructor, call `imfs.container_start(container)` with the newly created container instance.