
Show HN: Stretch – A high-performance cross-platform layout engine in Rust - emilsjolander
https://vislyhq.github.io/stretch/
======
dmitriid
> Stretch is tested against Chrome to ensure 100% web compatibility

Erm, no. That’s testing Chrome compatibility (though it’s probably the only
one easy enough to test).

Chrome is often rushing ahead to implement features that are either not
standardized yet, or will not be standardized, or break exisiting standards
and compatibility.

~~~
Twirrim
It's the "IE6 Only" of the modern web. I really hoped we (as an industry)
would have learned enough from that pain, but I guess not. Institutional
Knowledge seems to suffer from serious memory loss.

~~~
TylerE
It really isn't. Chrome is pretty good. IE6 was incredibly awful.

~~~
spinningslate
That's not the point gp is making. You're right of course: Chrome is
competent, IE6 definitely wasn't.

Chrome is, however, proprietary and driving further that way. IE6 showed that
a single, dominant browser is not good for consumers or progress. Especially
when it originates from one of the two leading surveillance tech firms.

[As an aside, I was disappointed to see MS admit defeat with Edge and jump
into bed with G. Still seems a bit suspicious tbh].

~~~
TylerE
Competence compensates for a monoculture.

You don't see people complaining that GHC is de facto the only Haskell
compiler.

~~~
spinningslate
> Competence compensates for a monoculture.

Sometimes. But motivation matters. The motivation behind ghc is clearly and
unequivocally to advance the Haskell ecosystem. The motivation behind Chrome's
dominance is another thing entirely.

~~~
jfk13
In addition, the Haskell ecosystem is only one among many programming
ecosystems that we can choose among for any given task. If the Haskell
ecosystem is a monoculture, and isn't headed in a direction that suits your
needs, you can choose another environment.

There's (pretty much) only one Web that needs to serve us all.

------
Klonoar
I've been using Stretch lately for a project I'm planning to open source in a
week or two (a cross platform GUI engine...). Pretty happy so far.

~~~
emilsjolander
Author here. Super excited to see what you are building! We are more than
happy to feature it on the Stretch landing page :) Shoot me an email and let's
chat!

~~~
mamcx
This is great.

As I put on
[https://www.reddit.com/r/rust/comments/9bapwt/thoughts_on_wh...](https://www.reddit.com/r/rust/comments/9bapwt/thoughts_on_what_a_good_gui_system_would_need/e51o6mw/)
this could enable the build of a different kind of cross-platform UI, where
the logic (backend) is on rust and the UI render (front-end) in a native lang.

~~~
emilsjolander
Super exciting. Interested to see how we can help.

------
jarjoura
Interesting! It seems this is a rewrite of Yoga, by the same author, seen by
another comment in this thread. So why start again using flex box as a layout
engine? For example, there isn't really a good, equally as rich, grid layout
engine yet. Also curious what the intended goal with conformance is, as the
README states this project has a secondary intent to be more in line with the
CSS spec? Personally for me any layout system that can avoid Apple's
constraint based system is already a win. I guess, what kind of layout would
this enable that Yoga doesn't already?

~~~
emilsjolander
Stretch doesn't really enable any new kind of layouts that yoga doesn't but it
fixes some fundamental problems in Yoga where Yoga was not compatible with the
web implementations.

Long term goal of Stretch is to support multiple layout systems including Grid
layout I just started with Flexbox because I know that so well :) Look forward
to tackling grid layout soonish (contributions / help very welcome).

~~~
nicoburns
Super-excited to hear that Grid layout will be coming soonish. Yoga has been
fantastic in making Flexbox available "everywhere", but Grid is wonderful for
UI layout in a way that Flexbox isn't.

~~~
emilsjolander
Just to be clear, we are not working on it. However it is something I would
like to start looking into sometime soon :) This is a huge area for
contributions as I myself am not a grid expert (as apposed to having worked on
flexbox engines past 3 years).

~~~
nicoburns
> Just to be clear, we are not working on it. However it is something I would
> like to start looking into sometime soon :)

I hear you, but this is very different to "we're never going to implement
this". I might look into contributing, but I've never implemented any layout
engine, so I'm not sure how much help I would be!

~~~
emilsjolander
I would love to help talk through how to start and the process i used for the
flexbox implementation :) start a PR / Issue and we can discuss :)

~~~
kjsthree
As someone else who knows nothing about how layout engines work, kudos to this
response. I understand time and attention don’t scale well and I hope you
don’t get overwhelmed but this kind of attitude in open source is the
greatest.

------
roca
It would be a very good idea to run the tests against Firefox as well as
Chrome to avoid replicating Chrome bugs that the Chrome team might later fix.

------
emmanueloga_
Layout is a subject that feels a little bit like a mystic art. There are
really no books or _accessible_ material about it, that I know off.

No, the TeX book doesn't count. Looking at the source of Chrome or Firefox
doesn't count. Stretch source doesn't count. W3C CSS specs definitely do not
count :-p.

I know that there are some papers floating (pun not intended) but I wish
somebody wrote a serious book about layout algorithms! Even splitting the
words of a paragraph into an optimal shape is something that is surprisingly
more complicated and rich topic than one would imagine [1].

Do you know of any resources/docs/papers/implementation-notes that you would
recommend?

1: [https://xxyxyz.org/line-breaking/](https://xxyxyz.org/line-breaking/)

~~~
emilsjolander
Hey! I'm actually in the process of writing up a high level overview of
Flexbox and how it works. Won't cover all aspects but would make it easier to
understand hopefully. Can't promise when I'll post it but hopefully soon at
medium.com/visly.

~~~
emmanueloga_
cool! I look forward your write up :-)

------
asdkhadsj
I'm not a UI guy, and I'm definitely not seasoned or have even had the chance
to personally test this assertion.... but..

I thought a lot of people disliked Flexbox and preferred CSSGrid? I watched a
talk a while back that made it seem like CSSGrid was better in many ways.
Primarily being far more inline with peoples natural mental patterns _(ie,
what they expect)_. That talk basically had me thinking that the next frontend
I write I'm not touching flex box and instead writing it in CSS Grids.

So am I mistaken? Why would people base a framework around Flexbox? Thoughts?

------
iBelieve
This looks great! I've been using Yoga in my Rust UI framework via the yoga-rs
bindings, and this looks like a nice pure-rust alternative to try using
instead.

~~~
emilsjolander
I'm the author of both Yoga and Stretch :) After leaving Facebook I created
Stretch to fix some core issues which would be hard to address in Yoga, mainly
some web compatibility issues. Would love to know more about what you are
building and let me know if I can help in any way with the migration! Adding
any missing APIs etc should be very easy.

my email is in profile if you want to chat :)

~~~
mkl
I'm guessing one of those "Yoga"s in the second sentence should be "Stretch"?

~~~
emilsjolander
haha yes. Edited

------
whytaka
As a web guy wanting to break out into mobile development, I’m very intrigued
by what it says but I have no idea how to make use of this. Can someone give
me a light overview?

------
_bxg1
I wonder what it would look like to put this in wasm and draw it to a full
screen canvas, circumventing the dom entirely. I wonder if there would be any
benefits.

~~~
codedokode
Of course there are: user cannot block ads, cannot copy text, cannot change
scale, robots cannot index the page, it will take more time to load and will
work slower.

------
openbasic
How does this compare to Yoga?

[https://yogalayout.com/](https://yogalayout.com/)

~~~
emilsjolander
Hey there! Author of both Yoga and Stretch. I built stretch after leaving
facebook because of some fundamental flaws in Yoga which made it not 100%
compatible with web browsers. Also I wanted something written in a modern
language that was easier to debug, maintain, and innovate on.

