HISE Logo Forum
    • Categories
    • Register
    • Login

    setPropertiesFromJSON - childComponents

    Scheduled Pinned Locked Moved General Questions
    6 Posts 2 Posters 120 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.
    • LindonL
      Lindon
      last edited by

      Can I not use the childComponents attribute when doing setPropertiesFromJSON, like this:

      	Content.setPropertiesFromJSON( "BckBack",{"x": 190,"y": 210,"width": 650,"height": 500,
      		    "itemColour": "0xFF000000",
      		    "itemColour2": "0xFF000000",
      		    "borderSize": 1.0,
      		    "childComponents": [
      		      {
      		        "type": "ScriptLabel", "id": "LFOBackLabel1","x": 157.0, "y": 73.0,
      		        "parentComponent": "BckBack", "fontName": "Gobold Thin",
      		        "textColour": "0xFFAAAAAA", "text": "Speed", "height": 14.0,"width": 40.0, "editable": "0" },
      		      {
      		        "type": "ScriptLabel","id": "LFOBackLabel2", "x": 211.0,"y": 73.0,
      		        "parentComponent": "BckBack",   "fontName": "Gobold Thin",
      		        "textColour": "0xFFAAAAAA",  "text": "Fade In",  "height": 14.0, "width": 44.0,"editable": "0"  }
      		    ]
      });
      

      I get a component but none of its children show up... or am I just doing it wrong?

      HISE Development for hire.
      www.channelrobot.com

      LindonL 1 Reply Last reply Reply Quote 0
      • LindonL
        Lindon @Lindon
        last edited by

        @Lindon back here again........ any possible answer to this?

        HISE Development for hire.
        www.channelrobot.com

        d.healeyD 1 Reply Last reply Reply Quote 0
        • d.healeyD
          d.healey @Lindon
          last edited by

          @Lindon You can't create children dynamically like this. What's your end goal here?

          Libre Wave - Freedom respecting instruments and effects
          My Patreon - HISE tutorials
          YouTube Channel - Public HISE tutorials

          LindonL 1 Reply Last reply Reply Quote 0
          • LindonL
            Lindon @d.healey
            last edited by Lindon

            @d-healey ... to create components from the JSON - so I can copy and paste my complex panels JSON into a script that I can use in another project.

            Its really about saving the hassel of going through every one of my child components and declaring it then "FromJSONing" it...

            HISE Development for hire.
            www.channelrobot.com

            d.healeyD 1 Reply Last reply Reply Quote 0
            • d.healeyD
              d.healey @Lindon
              last edited by d.healey

              @Lindon said in setPropertiesFromJSON - childComponents:

              so I can copy and paste my complex panels JSON into a script that I can use in another project.

              If you add a panel in your component list of your new project, hit J to open the JSON editor, and paste in your JSON, that might create the child components - I haven't tested.

              If you want to do it from scripting then you will need a function that goes through the JSON and constructs the UI... I happen to have such a script:

              /*
              * Author: David Healey
              * License: CC0
              * Last updated: 08/12/2024
              */
              
              namespace LayoutBuilder
              {
              	const data = [];
              
              	inline function add(arr: Array)
              	{
              		data.concat(arr);
              	}
              
              	inline function process()
              	{
              		if (isDefined(freezeUi) && freezeUi)
              			return;
              
              		local stack = data.clone();
              		
              		while (stack.length > 0)
              		{
              			local node = stack.shift();
              			
              			if (!isDefined(node.type) || !isDefined(node.id))
              				continue;
              
              			addComponent(node.id, node);
              
              			if (!isDefined(node.childComponents))
              				continue;
              
              			for (x in node.childComponents)
              				x.parentComponent = node.id;
              
              			stack.concat(node.childComponents);
              		}
              	}
              	
              	inline function: object addComponent(id: string, properties: JSON)
              	{
              		local c;
              
              		if (!Content.componentExists(id))
              		{
              			local type = properties.type.replace("Scripted").replace("Script");
              
              			switch (type)
              			{
              				case "Slider": c = Content.addKnob(id, properties.x, properties.y); break;
              				case "Button": c = Content.addButton(id, properties.x, properties.y); break;
              				case "Table": c = Content.addTable(id, properties.x, properties.y); break;
              				case "ComboBox": c = Content.addComboBox(id, properties.x, properties.y); break;
              				case "Label": c = Content.addLabel(id, properties.x, properties.y); break;
              				case "Image": c = Content.addImage(id, properties.x, properties.y); break;
              				case "Viewport": c = Content.addViewport(id, properties.x, properties.y); break;
              				case "Panel": c = Content.addPanel(id, properties.x, properties.y); break;
              				case "AudioWaveform": c = Content.addAudioWaveform(id, properties.x, properties.y); break;
              				case "SliderPack": c = Content.addSliderPack(id, properties.x, properties.y); break;
              				case "WebView": c = Content.addWebView(id, properties.x, properties.y); break;
              				case "FloatingTile": c = Content.addFloatingTile(id, properties.x, properties.y); break;
              			}
              		}
                      else
                      {
                          c = Content.getComponent(id)
                      }
              		
              		local allProperties = c.getAllProperties();
              	
              		for (x in properties)
              		{
              			if (!allProperties.contains(x) || ["id"].contains(x))
              				continue;
              
              			c.set(x, properties[x]);
              		}
              
              		return c;
              	}
              }
              

              Call LayoutBuilder.add() and pass in your JSON within square brackets (so it's an array). Then call LayoutBuilder.process()

              Libre Wave - Freedom respecting instruments and effects
              My Patreon - HISE tutorials
              YouTube Channel - Public HISE tutorials

              LindonL 1 Reply Last reply Reply Quote 1
              • LindonL
                Lindon @d.healey
                last edited by

                @d-healey oh, nice... I will give it a go...

                HISE Development for hire.
                www.channelrobot.com

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

                21

                Online

                1.7k

                Users

                11.8k

                Topics

                102.6k

                Posts