Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dimensions with percentages not working in JavaScript port #47

Open
zamotany opened this issue Aug 21, 2019 · 3 comments
Open

Dimensions with percentages not working in JavaScript port #47

zamotany opened this issue Aug 21, 2019 · 3 comments

Comments

@zamotany
Copy link
Contributor

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:

if string.ends_with('%') {
let len = string.len();
if let Ok(number) = string[..len - 1].parse::<f32>() {
return stretch::style::Dimension::Points(number);
}
}

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
Copy link
Contributor

@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
Copy link
Contributor Author

zamotany commented Sep 9, 2019

@emilsjolander Sure, I'll make a PR

@heswell
Copy link
Contributor

heswell commented Nov 3, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants