vislyhq / stretch

High performance flexbox implementation written in rust
https://vislyhq.github.io/stretch/
MIT License
1.99k stars 107 forks source link

Dimensions with percentages not working in JavaScript port #47

Open zamotany opened 5 years ago

zamotany commented 5 years ago

First of all, this is an awesome project and I really appreciate everyone putting their effort into it.

While working on react-slate (a React renderer for terminal in Node JS), which is based on Stretch, I noticed that, when setting width/height, basically any Dimension property as a percentage, it is converted to plain Points:

setting width to 100% will result in Points(100) being used in layout calculations.

I've done some digging and found one line of code, which might be causing that in get_dimension function in bindings/js: https://github.com/vislyhq/stretch/blob/a7e2c07bc343a1f16e1d651ea9f0c17fb0fbd098/bindings/js/src/lib.rs#L608-L613

Shouldn't this if let return return stretch::style::Dimension::Percent(number / 100);?

I'm happy to do a PR to fix that, but wanted a feedback before doing so.

emilsjolander commented 5 years ago

@zamotany You are totally right. My bad. Yeah if you would like to make a PR (and add a test for it so I don't mess up again ^^) that would be awesome. Let me know, otherwise I'll write a fix for it when I have some downtime.

btw react-slate looks awesome! Congrats on a successful project 💯

Also sorry for the delay in getting back to you on this.

zamotany commented 5 years ago

@emilsjolander Sure, I'll make a PR

heswell commented 4 years ago

Any chance we can get this fix merged ? I'm looking into replacing yoga-layout in my own project with stretch-layout but the broken percentage dimensions is a showstopper.