Have the "data" object from ScriptPanel on any ScriptComponent.
-
@jonhallur You only need to change the icon right, so put the icon name in the button's text property and now you can use the same local LAF function for all your icon buttons (this is what I do). https://github.com/davidhealey/LibreWaveBoilerplate/blob/master/LookAndFeel.js
-
@d-healey That is clever, thanks for this.
I still think the
data
thing is valid :) -
@jonhallur Sure it's valid, but I don't see a use case for it yet that isn't already covered in an elegant way.
-
Here's an example. All the buttons share a single local LAF function, assigned in a loop.
They all have different icons, can have different colours, etc. All a designer would need to do is edit values in the property editor, they would never need to edit the script. It's also possible to have icons and text in the same button, but that's a little more complicated.
HiseSnippet 2477.3ocsXstihibEFlYXz18lDkUJO.n4W8Hl3f4lgrJZG6xXv.FWcigF5nnUtsMfMFaiuBrZe2xaPdUxaPxorc2Pm4dmD9A7UUcN041WU3iw9tZFAAt9EJdgxAOiBE+MklbvIbMZspoSAQdxD1p5c2qt0y1n.2AO0f.C8BEK9xdDIJdwqJj94e9Sbp1pNZFmlpPgYtlZFiL2ZFdZV76GZZaKnpanXt8Loa7dQMWGjqsaD3MurT0BdpZaTWYLVkH1KJUn3q6paF55OITMzH.jgyU+vj0tINYxOyLv7dvIgAzEl.aT1zEPqMs0wODoAEJT7U3Sw8Kyh6+PIIScyGm+T7+6SWn7IMNOGT7EeNWh9avkJdlK8pLW5GJMQy2zK7zJD+46KI5DZ3uTU6okiLYK7h+w2WB4BR3DRsUcigfOL3QMtpU0puqL70a+wKuzARrAPR1nLVMbcvk+xkW3arpbP7Jd0P0e7xKf5QPXYSxOk+Kk+ke8GKCet7hKu3O8mJypqe4E4hBK9lZsaQEVcln.VEuYNkGWxLAdm4OAud17sbhY38zss4zZ6vKX4z0yEueIkAq3cqtaf076uwWMGOpOdVlrhHNqtfrztX+TrhnvRuTLlOCuNQLgKGawxxPM07V2A7KvTxfeD6wIJjhmVevNtoC2mJacOhs4YmtlMb.uJfW7D7JuU0AeJC6Nr4.kf9slgctqdHwmX5x6IDtCuNMVxvKvKWmKaZr5bW+vS4ik6.bddBv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t9zD7uesg4p0gmOCguWnXoRviiW3zoGPhW+ufO44fuA2g9S5NK95cmWWh7.a+Owep8o7m+98e89ykkd3tzOkO8gcPC8t6pGYqF9zF5Iu4h7EfSfOoKZRmxNAlgGN+Ma7Mzke0OaW9est3OTBaFps9i6iu3i3i.69+G9X96F42Vp6xkFZgmbvWURX9y8Eg7EL+MtQjprjZnuIPaJMNZ6DnRqY.V2wwvF17REeAgBlMtJYLICLwvQOc.gPjuHMYbw7EoeXwBaU07c+Ysr6UHu8kuKcFvmbReYSWTRhLt7i2FUpTUppE1Zpa9yZZjv+OBWY9w0o1yPm5OCcZ7Lzo4yPmVOCcXdF5z9ypC4cvwFE5tM63.LAta505EK10QEXVorvB+a.9NdTH
-
@d-healey I already agreed with you, no need to take me to school. :)
In my case I would just need to have object one level deeper with a list of on and off state.
g.fillPath(Paths.icons[obj.text][obj.value], obj.area);
And I agree, it is an elegant solution.
My mind is just already committed on thedata
object. -
@jonhallur said in Have the "data" object from ScriptPanel on any ScriptComponent.:
In my case I would just need to have object one level deeper with a list of on and off state.
This isn't necessary, let's keep our designers out of the code :)
You can use the text property for all kinds of magic. For example you could put
on icon,off icon
and in your laf function you can check if,
appears in the text and if it does you convert the text to an array usingjoin
and now you can use the button's value to get the correct icon name.My mind is just already committed on the data object.
Sometimes it's easier to change the way the system works instead of changing the way the programmer works :p
Edit: Oh I just noticed I have some implementation of that in the link I posted before (it's not as nice as the solution I just suggested though) - https://github.com/davidhealey/LibreWaveBoilerplate/blob/master/LookAndFeel.js#L293
-
You can use the text property for all kinds of magic. For example you could put
on icon,off icon
and in your laf function you can check if,
appears in the text and if it does you convert the text to an array usingjoin
and now you can use the button's value to get the correct icon name.String parsing in every draw call ?
Now you are just asking for bugs :) -
This isn't necessary, let's keep our designers out of the code :)
@lalalandsynth straight from the horses mouth
-
String parsing in every draw call ?
Now you are just asking for bugsThere shouldn't be any issue with this, it's all happening on the UI thread (and I've been using it in a lot of projects :) ). There was a post a while ago from Christoph that warned against using external data in LAF functions, not sure if this also applied to local LAF. I'll see if I can find the thread.
Edit: Here it is - https://forum.hise.audio/topic/3228/look-and-feel-toggle-buttons-and-the-midi-sources-panel/26?_=1671280536688
-
@jonhallur I would have to agree :)
-
There shouldn't be any issue with this, it's all happening on the UI thread (and I've been using it in a lot of projects :) ). There was a post a while ago from Christoph that warned against using external data in LAF functions, not sure if this also applied to local LAF. I'll see if I can find the thread.
Edit: Here it is - https://forum.hise.audio/topic/3228/look-and-feel-toggle-buttons-and-the-midi-sources-panel/26?_=1671280536688
I know I am confusing the LAF for buttons draw functions and the
setPaintRoutine()
for panels, I know local LAF functions would not have access to thedata
object andthis
like theScriptPanel
functions have.If I could access the data object in a LAF call that would also mean I wouldn't have to use external data, like he warns in this post.
-
@jonhallur I’m currently using external paths inside LAF, so I imagine this falls into the forbidden zone… What about colour constants ? (like Coulours.red) aren’t they considered external too ?
So perhaps in this case populating a data object prior to the LAF would make it more stable, if any of the above can create instabilities of course.
As for the relevance of a data object regarding the programming workflow, I can understand the importance of it though I don’t feel personally concerned (at least for today)
-
@ustk I'm using some external data too in my LAF functions and haven't noticed any issues. I wonder if it was just Christoph being cautious or if the issue was fixed.
-
It's still a good advice to avoid using external data if possible, but I did in fact work on some multithreading issues since I posted the warning so yes by now it's safe enough to use static preallocated path objects in a LAF function.