HISE Logo Forum
    • Categories
    • Register
    • Login

    Issue with Panels. Need to turn off self toggle for some panels but not others.

    Scheduled Pinned Locked Moved Scripting
    2 Posts 2 Posters 155 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • P
      plugmakr
      last edited by

      Hello,
      I am working on project that has multiple panels. Right now there are 21 panels. The issue is I want only two panels to be able to self toggle. The Preset Browser and the Settings panel are the only ones that should be able to turn of and off with their buttons. The rest should not be able to. Right now they are all in radio group 1. Where it becomes a headache is Panel1-16 share a space with Panel18. Panel0, Panel17, Panel19 and Panel20 share a space. This is my first deep dive into creating more complex panels. Any help is much appreciated.

      I am using the following code to manage this.

      //Panels
      const var NUM_BUTTONS = 21;
      const var buttons = [];
      const var panels = [];

      for (i = 0; i < NUM_BUTTONS; i++)
      {
      buttons[i] = Content.getComponent("Button" + (i));
      panels[i] = Content.getComponent("Panel" + (i));
      buttons[i].setControlCallback(onButtonControl);
      }

      var lastActivePanel = -1; // Track the last active panel

      inline function onButtonControl(component, value)
      {
      local idx = buttons.indexOf(component);

      // If the clicked button corresponds to Panel19 or Panel20, toggle each other
      if (idx == 19 || idx == 20)
      {
          panels[19].showControl(idx == 19 && value);
          panels[20].showControl(idx == 20 && value);
          buttons[19].setValue(idx == 19 && value);
          buttons[20].setValue(idx == 20 && value);
      
          // Toggle off Panel0 and Panel17 when Panel19 or Panel20 is active
          panels[0].showControl(!value && idx != 0);
          panels[17].showControl(!value && idx != 17);
          buttons[0].setValue(!value && idx != 0);
          buttons[17].setValue(!value && idx != 17);
      
          // Hide Panel1-16 when transitioning from Panel18 to Panel19 or Panel20
          if (lastActivePanel == 18 && idx != 18)
          {
              for (i = 1; i <= 16; i++)
              {
                  panels[i].showControl(false);
                  buttons[i].setValue(false);
              }
          }
      }
      // If the clicked button corresponds to Panel18, show only Panel18
      else if (idx == 18)
      {
          panels[18].showControl(value);
          buttons[18].setValue(value);
      
          // Toggle off Panel1-16, Panel0, Panel17, Panel19, and Panel20 when Panel18 is active
          for (i = 1; i <= 20; i++)
          {
              panels[i].showControl(i == 18 && value);
              buttons[i].setValue(i == 18 && value);
          }
      }
      else
      {
          // Iterate through all panels except Panel1-16
          for (i = 0; i < panels.length; i++)
          {
              if (i != 19 && i != 20)
              {
                  // Toggle the visibility of the clicked button's panel and turn off others
                  panels[i].showControl(i == idx && value);
                  buttons[i].setValue(i == idx && value);
              }
          }
      }
      
      lastActivePanel = idx; // Update the last active panel
      

      }

      // Initialize the state by simulating a press on Button0
      onButtonControl(buttons[0], true);

      ustkU 1 Reply Last reply Reply Quote 0
      • ustkU
        ustk @plugmakr
        last edited by ustk

        @plugmakr At this point a snippet might help us to help you better than a code block...

        Can't help pressing F5 in the forum...

        1 Reply Last reply Reply Quote 0
        • First post
          Last post

        32

        Online

        1.8k

        Users

        12.0k

        Topics

        104.4k

        Posts