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

(Javascript) stretch dimension of flex children is zero #59

Open
heswell opened this issue Nov 3, 2019 · 1 comment
Open

(Javascript) stretch dimension of flex children is zero #59

heswell opened this issue Nov 3, 2019 · 1 comment

Comments

@heswell
Copy link
Contributor

heswell commented Nov 3, 2019

I can't seem to get basic flex layout working in Javascript, not sure if I'm missing something.
I would expect the child items in the following to be assigned a height matching the full height of the parent node (per align-items: stretch). In fact they are assigned height 0

import('stretch-layout').then((stretch) => {
  
  const { Allocator, Node, Display, AlignItems } = stretch;
  const allocator = new Allocator();
 
  const rootNode = new Node(allocator, {width: 600, height: 300, display: Display.Flex, alignItems: AlignItems.Stretch});

  const childNodes = [
    new Node(allocator, {flexShrink:1, flexGrow:1, flexBasis: 'auto'}),
    new Node(allocator, {flexShrink:1, flexGrow:1, flexBasis: 'auto'})
  ]
  rootNode.addChild(childNodes[0]);
  rootNode.addChild(childNodes[1]);

  const computedLayout = rootNode.computeLayout();
 
  logLayout(computedLayout)

})

function logLayout(computedLayout){
  const {x, y, width, height, childCount} = computedLayout;
  console.log(`x:${x}, y:${y}, width:${width}, height:${height}`);

  for (let i=0;i<childCount; i++) {
      logLayout(computedLayout.child(i));
  };

};

logs the following:

x:0, y:0, width:600, height:300
x:0, y:0, width:300, height:0
x:300, y:0, width:300, height:0
@heswell
Copy link
Contributor Author

heswell commented Jan 26, 2020

see fix in

#62

This is my first attempt at coding in rust, not sure if it's the optimal solution.

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

1 participant