Suggestions on custom toggle button

Hello all,

I’m trying my hand at creating custom buttons. I’m wondering what the best way is to create a button that toggles. I’d like to use a Panel Execute DAT to make things more streamlined.

I could feed the Panel Execute DAT script to Constant → Logic CHOP chain within the panel, but I’m wondering if there may be a better way.

What I’ve got so far:

*Edit: I should also add I want to keep things as self-contained within the button as possible as I intend to use this template a couple of times for different applications in the project.

Is there a reason you don’t just use the widgets and customize the visual elements of them?

You can use a Panel CHOP to get the state, select, and hover channels and use math CHOPs to combine those into one channel to control the index parameter of the Switch TOP, that is probably your most efficient route (since I think Logic CHOPs cook all the time regardless) especially if you’re going to be using a lot of these buttons.

If you look inside a regular Button COMP from the Op Create Dialog (press tab) there is an example similar to what I’m describing that you may be able to use.

Yes, I was interested in approaching the buttons a bit more programmatically. Looking through the widgets, they definitely have all the functionality, but I was wondering if I could cut back on the “overhead” of additional nodes.

After some tinkering I was able to come up with this song selector. It’s literally two png’s and some code.

It was this series of tutorials that sent me down this rabbit hole: TouchDesigner - UI Basics: Part 1 - How to make buttons

I figured with this approach would allow some highly customizable buttons without huge node networks.

That does seem to be the most streamlined approach. I ended up going in a slightly different direction and tackled things a bit more on the programming side. Googling “general best python practices” pointed me towards some interesting suggestions. The button executes mostly the same as your suggestion, just with the select state integrated into the Panel Execute DAT a bit more.