Jump to content

How to correctly position elements inside Babylon.GUI Stackpanel?


Recommended Posts


I want to position two (or more) elements inside a Babylon GUI Stackpanel. For two elements, both should use up 50% (three elements -> each 33.33% etc.) of the height of the parent stack panel.

But this only seems to work if I directly set the height of the element in pixels, if I set height = 0.5 for each element, it doesn't work as I expected.

Here is a playground example:


As you can see there, the second box doesn't fit in correctly in the parent container. If you use the direct pixel settings for the frameHeight variable (line 40-41), the result is how I would want it to be, but calculating it this way isn't a very comfortable way :).

What I am doing wrong here?

Thanks :)


Link to comment
Share on other sites

yeah, and remember the other option.  Instead of adding and removing controls from a stack panel, perhaps... destroy the old one and build a new one.

Don't destroy the controls, of course.  But, if you had a killOldStackPanelAndGenerateNewStackPanel(panel, arrayOfControls) function, then it would be EASY to APPEAR-TO add and remove controls... when actually... you are doing a complete rebuild with each addition or removal.  Whatever controls are reffed inside-of arrayOfControls, that's what controls are included in the new SP.

So now... you can have various pre-made arrayOfControls... each ready to send to killOldStackPanelAndGenerateNewStackPanel(here) whenever you wish.

This is another way of thinking... about stackPanels.  IF your project can use this method, then the stackPanel will ALWAYS perfectly-fit the controls it contains.  *shrug*

In BABYLON GUI, this seems to be a wise general theme.  In certain cases, instead of modifying something, dispose and re-create it... with the changes.  This is because BJS GUI does most of its measuring.... at creation time.  It is not good-at changing already-created things... due to its nature.  (at least that's my theory).  :)  Party on!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...