I’ve implemented a small library that will serve as a building block for the Unison editor. The editor needs to be able to render code and embedded graphics with a responsive layout that adjusts to available width. I had solved this problem in a pretty ad hoc way in the old editor, but it got ugly and I wanted something much better. The new library separates out just the concern of building responsive layouts that can be rendered at different widths (with a few twists on the usual prettyprinting combinators), and is totally general purpose. Here’s a usage of it, the prettyprinter for types. That same description can be rendered at multiple widths, and sent to plain text or HTML! But the output isn’t just an opaque blob—we retain information needed to resolve screen locations to paths into our original syntax tree. This makes adding editability really easy.
I figured out a nice story for doing rich function layout, so for example division can be rendered with a horizontal bar, but that’s really just scratching the surface of what will be a very powerful idea. I’d like to do a design writeup of this soon. A lot of this was sparked by conversations with @int-index who is working on a language-agnostic semantic editor called Source and is interested in adding mixfix operators to Unison. I realized the idea could be generalized much much further.