10 ms·
RectCut for dead simple UI layouts
- dstick 5y agoIs this UI so simple that it’s meant to break on mobile?
- rexelhoff 5y agoReactCut
- Varriount 5y agoIdiosyncratically, the website looks better on mobile if you view the page in desktop mode. That is, the content actually fits to the screen size, and the code examples aren't cut off mid-line.
- chrismorgan 5y agoThat’s half of the point of giving a desktop mode switch, that it makes the browser ignore the “no really, I support mobile” <meta name="viewport" content="width=device-width"> tag.
- tobr 5y agoIt’s a good illustration of the need for a simpler layout model than the three-dozen-piled-layers-of-cruft model CSS is based on.
- dahart 5y agoOTOH, CSS can handle a vastly wider array of styles and use cases. I agree it’s crufty, but there are many historical / legacy reasons for it that are still in use today. 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).
- chrismorgan 5y agoGrid is not the successor to flexbox. They’re different layout techniques that were invented at much the same time (though grid took longer to mature) for different situations. Flexbox is one-dimensional plus wrapping, while grid is two-dimensional. Now in practice, most applications of grid could be rewritten to use flexbox, but there are plenty of layouts that can be achieved with one but not with the other, both ways.
- dahart 5y ago> Grid is not the successor to flexbox. 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-flexbox-1/ https://www.w3.org/TR/css-grid-1/ https://www.w3.org/TR/css-grid-1/ https://caniuse.com/?search=grid https://caniuse.com/?search=grid https://caniuse.com/?search=flexbox https://caniuse.com/?search=flexbox
- chrismorgan 5y agoSuccessor indicates that it’s designed to replace it. That’s not the case and never was. They have different purposes. (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.)
- deleted 5y ago[deleted]
- chrismorgan 5y agoIt’s a hopelessly bad illustration of that. 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.)
- tobr 5y agoYes, and this is exactly the type of problem you run into when your layout model is based on three-dozen-piled-layers-of-cruft.
- chrismorgan 5y agoShow me a layout system that doesn’t let you break things in this sort of way, and I’ll show you a useless layout system.
- fouric 5y agoThe code examples are in C and make no mention of any webtech or mobile. I'm pretty sure that this is meant for desktop interfaces.
- altschuler 5y agoThis approach is also used/encouraged by JUCE: https://docs.juce.com/master/tutorial_rectangle_advanced.html https://docs.juce.com/master/tutorial_rectangle_advanced.htm... (see "Layout by subdividing rectangles")
- deleted 5y ago[deleted]
- slver 5y agoI’m unsure what’s the difference between this and hierarchical layouts. And say flexbox
- cwales95 5y agoLooks nice, but unresponsive on small screens.
- _448 5y agoThis is interesting! I had implemented a similar system a while back for a mobile OS company. It was used for optimisation of the rendering of the UI scenegraph. The rectangles were cut(taking into account alpha blending) before feeding it to the renderer to improve performance. This was all post-layout though. Didn't realise that it can be used for layout as well!
- wruza 5y agoIt is tAlign layout from Delphi. Alignments were cutting a parent surface in order of children appearance. It allowed to solve 95% of desktop ui without complicating things. 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?
- helltone 5y agoHow does layout in say LaTeX compare? Is text/font layout different fundamentally?
- iainmerrick 5y agoI would call that “flow layout”. 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).
- dahart 5y agoYes text layout is fundamentally different in the sense that text layout is about placing lines of text inside a rectangle, where RectCut is about placing the rectangles and doesn’t help much with text. It would be possible to use RectCut for text flow, but you probably wouldn’t want to, it’s more designed for a small number of on-screen panels in an application. Core 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 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 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.
- HelloNurse 5y agoTrees of "dumb" rectangles don't seem very suitable for responsive or adaptive layouts in which the hierarchical structure is built before deciding rectangle sizes. For a retained mode GUI traditional container widgets and layout managers negotiating sizes with child widgets seem a more general technique; for an immediate mode GUI there is no obvious advantage over explicit and more general size computations at the same abstraction level.
- nine_k 5y agoFrom screenshots, this looks like a game console or an embedded controller screen. For that purpose, simplicity and low footprint may trump flexibility.
- maskros 5y agoThis is also how the Tcl/Tk pack layout works.
- cmacleod4 5y ago... and has done for at least 25 years :-)
- Sharlin 5y agoAs they say, everything old is new again.
- blacktriangle 5y agoThat was my first thought as well. 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.
- no_time 5y ago>rect->minx = min(rect->max.x, rect->minx + a); Did you mean maxx instead of max.x?
- jakelazaroff 5y agoThis may be good if you know all your rect sizes in advance. But it seems like it will quickly fall apart if you have rectangles that need to change their size based on content, especially if that content is multiple levels deep. 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.
- hsn915 5y agoYou will generally know the rough content of the text and allocate a size that looks good enough. 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.