Solved Adding components to Interface dynamically after onInit()
-
Hey, I am working on a feature where you can list all samples that are located on your hard drive.
I want to add a new panel for every file (sample) the user has installed, however these samples will be served by an API so the samples are not known
onInit()
I am getting this error:
Tried to add a component after onInit()
One possible solution I was thinking off was adding all the necessary panels on the
onInit()
and just render them empty. Then once they are needed I can fill them with the sample names. I could also add pagination if needed, however I was wondering if there is a better solution for my problem? I will also need to register callback listeners for mouse events for each panel.Is there a good solution to dynamically add panels?
-
The only controls that can be added outside of on init are child panels.
A better solution is probably just to have one panel and make its content dynamic.
-
@d-healey Thanks for the help! Really appreciate that. I will be using child panels.
When using only one Panel with dynamic content I would need to deal with getting the click position, mapping that to a file name also stuff like hover states get more tedious. In terms of performance wise however one panel would be better but since I am not rendering anything other than that file browser it should be fine.
-
-
-
@oskarsh Try using a viewport in table mode, this is exactly the intended use case for it.
Start reading here:
https://docs.hise.audio/scripting/scripting-api/scriptedviewport/index.html#settablecallback
until here:
https://docs.hise.audio/scripting/scripting-api/scriptedviewport/index.html#settablerowdata
-
@Christoph-Hart Amazing exactly what I was looking for, much cleaner than handling all the child panels! Thank you.
I've created a snippet for everyone who is interested using some minor custom LAF.
HiseSnippet 1196.3ocsV01SabDDdOfCU69hZp5OfU9CIGRtVlDZZTQzBXvMnvaESRqTUUzxciOuk810Zu0.VQHUo9Wo+.6+.5L2c19L3R.KU+A31YmmYelYmYm4XqIDRSMVlWkSG1GXdelemgZWuV8DRMaucXdeg+ohyTvtWIR5q.11C6KRSgHlm2h+DoiWkkXY+9mebagRnCgIhXr2Yjgv9xDoahzi27MRkpsHBNUlTR601buPitkQYFf7YQ+lr9hvyEwvgBRsE7YdKuajzYrcbBGjh5rsIZXmdlK045+NYpD4JsXUVGzP4hYs5IUQGOxWSYLukNdhmuXtm+09GHijikOIB7kYavmfnbLvag6iRq9HnjWIJsTNkdhemPqruaxNDe9T+8zNv1UDN80QttrE9Ke+VFTCsqQh3bnsEWLFQvKa1rNG+yJqWsJFtSc7KDV96jvk8MV2p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