I’ve been working on some custom buttons for a UI I’m building. The buttons use custom SVG images for the background and another SVG image for the primary content inside the button. Its essentially an icon-button.
I found the various button pointer animation properties (pointerEnterAnimation, pointerDownAnimation, pointerUpAnimation, pointerOutAnimation) available which has enabled me to easily create a unique style for the button’s normal, hover, and focus states.
The isEnabled does a nice job preventing interaction when the button is not enabled. Now I’m trying to figure out the best way to handle the button’s when they are in a disabled state.
For my case, I want to change the background image and foreground image when the button enters a disabled state. But generally speaking, each element in a button (background, images, text) may need changed for a disabled state. I don’t see this being any different than the pointer animations. Also, this same question comes into play again when I start building my Toggle Buttons.
Is there a recommended way to define and animate a unique state for a button, but specifically for when the button is disabled?
@Deltakosh My project officially required a toggle button yesterday, so I extended the Button class into a new Toggle class. I’ve never contributed code to a project of this scale before, but if you don’t mind helping me with the process, I’d be happy to try putting together a pull request.
I’ve created a gitpod from the master repo, added a new script called Toggle.ts to the folder gui/src/2D/controls. This is my first time using gitpod and I’ve never had a simpler experience getting started in a project!
That said, I think I’m missing a step somewhere. When I save the new script, I don’t see webpack recompile. I even saved the script with a syntax error and restarted the compiler with npm run start and no error is produced.
Do I need to add the new script to an index, config, or something?
EDIT: Okay, I got a compiler error with npm run build, so I’m guessing npm run start is only serving the build folder. But please let me know if I should be auto-build on save is possible.
Blast! Thanks @sebavan, my eyes just didn’t want to see that index file.
I’m still struggling to figure out how to test my work locally though. I’d like to use a local playground with the files in the preview release folder. However, I can’t seem to get it to work.
I tried a few different files with no luck and eventually resorted to creating a playground.html file in the localDev folder. I copied the contents of Playground/index.html into this new file and then updated all the babylon urls to point to the /dist/preview release files.
While I can see the files are loaded in locally when viewing the network inspector, the file ‘babylon.gui.d.ts’ still pulls in from the preview domain. I think that might be why I can’t get the new class to be recognized. I know it’s in the build because I can see the new class name in the newly built files.
Can anyone suggest way to use the playground with my local build?
Hmm… well if that’s true then I must have missed a step in my dev environment. I’ve have read through the entire ‘Develop with Babylon.js’ section of the docs including the ‘Contributing Guide’ multiple times now and I’m familiar with webpack projects.
If the dev environment is setup correctly, should Playground/index-local.html utilize the local version of my files? Or a different playground file?
I checked out a freshly forked repo and took these steps to test this issue with `babylon.gui.js:
From Clean Master
Fork repo and checkout master locally
Open project in VSCode
cd Tools/Gulp
npm install
npm run start
In chrome with the network panel open and cacheing disable, loaded http://localhost:1338/Playground/index-local.html
Fwiw, I can recreate this issue when using a fresh GitPod as well.
Open new GitPod from Master and let it load
Created new ToggleButton class in gui/src/2D/controls/toggleButton.ts Class is exported and the type is registered.
Exported toggleButton in gui/src/2D/controls/index.ts
Saved all files, the project sees a new babylon.gui.js
Open Playground/index-local.html on port 1338
I confirmed the ToggleButton class is in the source file using the network inspector. I can also confirm the d.ts file is coming from preview.babylonjs.com.
In the playground, a type error is thrown when trying to use the new ToggleButton class.
Well, I’m never using typescript in the local playground, only javascript…
Even in javascript the completion will not show you the new things you created but they do work (try to create your new button in Playground javascript, it should work). Maybe @RaananW or @sebavan will be able to shed some lights on the possibility to have the completion/typescript version of the PG works with the new code added locally.
Also, in your steps described above, you don’t have to rebuild everything to test in the Playground: just do your changes as in steps 1/2/3/4 and you can test them in the local PG.
Thanks for clarifying this. I got confused because I wasn’t seeing any of my new properties/classes so didn’t know it was actually serving a dev build. This is working exactly as expected now that I understand the cause of this problem.
This suggestion worked! I simply updated the declaration for the GUI to use the file in the preview release and the Playground is now utilizing the type definitions. This makes testing and creating examples so much easier. Especially considering I prefer Typescript.
Thank you for your support! I look forward to creating a pull request for this new feature next week.