Vorion Posted January 16, 2018 Share Posted January 16, 2018 Hi, 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: http://www.babylonjs-playground.com/#0Y52HC 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 Quote Link to comment Share on other sites More sharing options...
brianzinn Posted January 16, 2018 Share Posted January 16, 2018 I don't know if you want to do it this way, but if you make the container the whole screen the math is easier (you only get 1 full screen UI anyway). I'm not sure how to fix the scaling otherwise.http://www.babylonjs-playground.com/#0Y52HC#1 Vorion 1 Quote Link to comment Share on other sites More sharing options...
Vorion Posted January 16, 2018 Author Share Posted January 16, 2018 Thanks, but I would prefer a better solution (if there is one), because I have several gui elements like that, which can contain dynamically added controls. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted January 16, 2018 Share Posted January 16, 2018 Unfortunately this cannot work as the StackPanel is designed to use children heights to evaluate it's own height If you can use a container object then it will work but you will have to set the container height manually Vorion 1 Quote Link to comment Share on other sites More sharing options...
Wingnut Posted January 17, 2018 Share Posted January 17, 2018 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! Vorion and GameMonetize 2 Quote Link to comment Share on other sites More sharing options...
Vorion Posted January 18, 2018 Author Share Posted January 18, 2018 Ok thanks, I will figure something out Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.