RectCut for dead simple UI layouts
halt.software
halt.software
I’m aware of four main layout models: fixed (x,y), alignment model, boxing model (gtk, qt, html), and constraints model (apple ui). Can anyone list more?
In this regime, centering a 100px*50px element would be to make TopLeft=(50%-50px, 50%-25px) BottomRight=(50%+50px, 50%+25px)
All the rules are of the form:
A.side {follows|proportional} B.side
By default *.side follows Form.left (or top)
And few shorthands, e.g. “A expands hotizontally” means A.right follows Parent.right, etc.It is actually a dumbed down version of a constraints model and is a subset of it, though it looks and feels more like boxing or alignment models. It was used in pre-constraints apple toolkits and few other products. The main difference is that these follow/proportional constraints are tree-like (cycles forbidden), when true constraint-based layout is a linear problem that requires a special solver optimized for ui-related [in]equality patterns to update in realtime.
Constraints-based:
https://blog.gtk.org/2019/07/02/constraint-layouts/
https://ebassi.github.io/emeus/
https://developer.apple.com/library/archive/documentation/UserExperience/Conceptual/AutolayoutPG/AnatomyofaConstraint.html
https://developer.apple.com/library/archive/documentation/UserExperience/Conceptual/AutolayoutPG/VisualFormatLanguage.html
Boxing: https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/The_box_model#examples_of_different_display_types
Alignment/anchor-based: $subj
https://wiki.lazarus.freepascal.org/Autosize_/_LayoutCore LaTeX is concerned with the flow of text in printed articles, and Knuth published the text layout algorithm “Breaking Paragraphs into Lines” http://www.eprg.org/G53DOC/pdfs/knuth-plass-breaking.pdf
Originally, HTML did the same thing, it was used to emulate the written page and layout text into a box. But not everyone wanted their site to look like a printed article, so CSS and new layout modes sprouted over the years. Today there are seven of them: https://developer.mozilla.org/en-US/docs/Web/CSS/Layout_mode
RectCut is fundamentally most similar in spirit to CSS flexbox, and fundamentally similar to a bunch of other box layout managers in other languages and UI toolkits, as you can see from the comments.
HTML includes a version of it, TeX and DTP apps use various versions of it.
Edit to add: I don’t know the details of TeX except that it uses a hierarchical “box model”. I suspect it’s fairly similar to HTML before flex-box. HTML flex feels like a refined version of Java AWT layout managers (a more successful evolution than Android’s painful variant).
Once you start adding constraints like min/max size and relative sizes it becomes more complex but still manageable. You’re still only reasoning about rectangles and their constraints.
Adding rendered text in the mix increases complexity immensely. Determining the size of rendered text is a very complex problem space in itself involving fonts, dpi, text flow, code points, LTR/RTL, ligatures and more. It’s not just rectangles anymore.
For that purpose, simplicity and low footprint may trump flexibility.
The web does a singularly excellent job of supporting varying viewport sizes out of the box, but this page actively sabotaged that by claiming to support mobile:
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
While applying CSS rules that ruin it: .article-card, article h1, article ul, article p, article ol {
width: 600px;
}
pre {
overflow-x: hidden;
}
These rules are obviously bad. width should be max-width, and, well, what would you expect to happen if you tell it to hide the overflow?(It would have been OK even with these rules if the page hadn’t claimed to support mobile sizes, as the mobile browser would have rendered the page on a larger viewport and scaled it down, more or less.)
If used in practice for anything substantial, RectCut will start to acquire cruft too. First thing to get added would be resizeable / dynamic layouts. Next would be something akin to the CSS grid layout, which is already the successor to flexbox (closest CSS layout mode to RectCut).
Yes, it literally is. Grid came after flexbox in W3C drafts, in W3C recommendations, in broad browser support, and in widespread use. Several years ago, flexbox was being used widely while grid support was nonexistent, and today grid is still lagging behind flexbox a little.
https://www.w3.org/TR/css-flexbox-1/
https://www.w3.org/TR/css-grid-1/
(For the rest, my recollection was definitely off on the timing, and most significantly I forgot the proto-flexbox stuff that Gecko and WebKit had long before grid was proposed. Beyond that, grid certainly took longer to mature, as I remarked, being more complex and needing to interact with more features to be optimally useful. Incidentally, IE got both flexbox and grid (earlier drafts) at the same time, in IE10, Microsoft leading the way on grid by several years, five by the most common way of reckoning.)
I found Tk was really great for simple layouts, but I worked on a Tk project that had some very complicated control panels. Ultimately it became unwieldy and difficult to refactor the UI as moving code around would have breaking consequences.
Say you have a floating toolbar the width of two buttons, which themselves are the width of their text contents. You're back to square one — you have to measure the text of each button, then measure both buttons and finally you have the size of the toolbar.
A lot of people do this anyway even with css: specify the button width in pixels. Because a toolbar with buttons that have varying widths depending on their content is not always a very good looking toolbar.
Did you mean maxx instead of max.x?