Jump to content

New Gui in Babylon


Dad72
 Share

Recommended Posts

Thank you Adam, I had not seen it, I was looking in the controls. and I have not seen this in the doc.

Maybe this could be added in the doc to destroy a control or destroy the full GUISysteme.

Link to comment
Share on other sites

1. I was curious why the decision for .alpha property instead of .visibility - seems like visibility is more consistent with rest of BabylonJS.
2. docs have 2 options for units px and %, but just number (ie: 0.2 as in demo) is valid, so might be good to add to docs.

If you add a way to change an image source would be nice.  I want to change one child image and I see only addControl(), but almost like we need something like addControlAfter(..) or addControlBefore(..), because addControl(..) does a .push, so we can't control ordering.  It looks like currently we would need to remove all existing controls and readd in the order we wanted.  Other option of directly swapping button.children[0] would not mark the control as dirty, if needed?

Looks really good! :)

Link to comment
Share on other sites

7 hours ago, Deltakosh said:

I would say: this is in the doc :)

I completely missed "CreateImageOnlyButton" for some reason, was it there all along or did you just add it?

 

The button's dimensions are not set according to the image's original size, which is what I need.

 

The only way I managed to do it was to literally set the button's dimensions according to the image:

http://www.babylonjs-playground.com/#XCPP9Y#37

This solution is problematic since it's fixed and won't be resized along with the stage, although I guess I could take into account both original image size and stage size manually.

 

Is there a better solution in the docs? If so can you please give me a hint regarding what I should read? :)

Link to comment
Share on other sites

Regardless, I have a suggestion / request for Babylon.GUI:

Have an option to set ideal dimensions for elements and for stage, and have each element resized in proportions to the ideal stage dimensions.

Element ideal dimensions will be defined for each element separately.

 

For instance:

Element ideal dimensions: 100x100

Stage ideal dimensions: 600x600

When stage dimensions are 300x300, element dimensions would be 50x50.

 

It's an extremely useful feature from my experience when developing any game/app for multiple resolutions. What do you think?

 

Link to comment
Share on other sites

My end goal is to have images original dimensions resized according to ideal stage size, same goes for text blocks which "original" dimensions would be calculated according to their text and font size.

Perhaps an option to automatically calculate the width and height percentage based on what I said? Or otherwise some util functions?

Link to comment
Share on other sites

Regarding your ideal stage size. If you consider that 100 is ideal for a stage of 600 then you can do:

image.width = (advancedDynamicTexture.getSize().width *  100 / 600) + "px"

and just set image.stretch = extend

 

Other idea: we could define a global "ideal" size on the advancedDynamicTexture. And then use it to scale all values that can have pixel or percentage.

In this case, we could set:

myAdvancedDynamicTexture.idealWidth = 600;

 

so if you set button.width = "25%", internally I could translate it to button.renderingWidth = (advancedDynamicTexture.width * 25 / 600) %

 

Thoughts?

Link to comment
Share on other sites

advancedDynamicTexture.idealWidth sounds good.

Calculating it manually for each element is an option as you said, but it'd be great to have such a thing internal as well, since this behavior could be repeating for all / most elements.

For instance have a function image.originalAutoScale() that sets image.width = image.texture.domImage.width / advancedDynamicTexture.idealWidth

Link to comment
Share on other sites

I've found an interesting bug.  If you click down on a button and mouse out (while holding down mouse) and release outside of button then it will continually scale down 0.05.  Do that a few times and the button becomes continually smaller.

I think you will need to maintain more state internally - ie: in Button.ts add private buttonDown : boolean.  On the pointerOutAnimation you would then check if (buttonDown === true) and increase the scale and set buttonDown  false. I could try to submit a PR, if you want. 

Link to comment
Share on other sites

2 hours ago, Deltakosh said:

Thanks :) I'm starting to test BABYLON.GUI within my project.

 

1) babylon.gui.d.ts has a reference path for each exported class

Quote

/// <reference path="../../dist/preview release/babylon.d.ts" />

a. Different people have different project structures, perhaps changing the path to "babylon.d.ts" would be more convenient for everyone?

b. Perhaps make it only 1 reference tag instead of that many so that they could be edited more easily?

It's not critical AT ALL, just a suggestion.

 

2) 

Quote

static CreateFullscreenUI(name: string, foreground: boolean, scene: Scene): AdvancedDynamicTexture;

foreground and scene should be set to optional parameters?

Quote

var advancedTexture = BABYLON.GUI.AdvancedDynamicTexture.CreateFullscreenUI("myUI");

 

The same goes for BABYLON.GUI.Rectangle constructors and probably other functions - parameters that to the best of my understanding should be optional are not set as optional in TypeScript.

 

Control width and height should be defined as number | string instead of just string.

 

3) Another suggestion - What do you think about being able to pass texture to image constructor and other image related functions such as Button.CreateImageButton?

There could be function overloading to allow both image url and BABYLON.Texture.

 

4) This is one of the reasons behind my suggestion in (3):

It seems that another img element is created whenever creating a new image, so when specifying a url of a texture that was already loaded using BABYLON.AssetsLoader, its properties are not available until it is loaded.

Well, it was already loaded, so it's fetched from the cache, but that means an already loaded texture is not available immediately.

Lines 43-45 in this PG:

http://www.babylonjs-playground.com/#XCPP9Y#41

 

5) What do you think about adding a TextureAtlas feature? It could help reduce draw calls drastically. (unless there are no draw calls since BABYLON.GUI is cpu-based?)

 

6) Another feature request - Mask.

 

 

Link to comment
Share on other sites

3. yup I know, I guess my question was - does the AssetLoader save references to images and expose them somewhere or do I need to save them myself from ImageAssetTask.image?

6. scrollable container - display the content only within the masked area.

7. image.domImage is undefined after I set it to an existing image element:

image.domImage = myImage;

console.log(image.domImage, myImage); //undefined, image element

 

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.

Guest
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.

Loading...
 Share

  • Recently Browsing   0 members

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