HISE Logo Forum
    • Categories
    • Register
    • Login

    Images in a Viewport

    Scheduled Pinned Locked Moved General Questions
    25 Posts 2 Posters 1.1k 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.
    • DanHD
      DanH @d.healey
      last edited by

      @d-healey lol, missed that!

      DHPlugins / DC Breaks | Artist / Producer / DJ / Developer
      https://dhplugins.com/ | https://dcbreaks.com/
      London, UK

      1 Reply Last reply Reply Quote 0
      • DanHD
        DanH @d.healey
        last edited by

        @d-healey why this?

        inline function removeAllChildPanels(panel)
        {
        	for (x in panel.getChildPanelList())
        		x.removeFromParent();
        }
        

        DHPlugins / DC Breaks | Artist / Producer / DJ / Developer
        https://dhplugins.com/ | https://dcbreaks.com/
        London, UK

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

          @DanH Go to where I'm calling that function, there's a comment

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

          DanHD 1 Reply Last reply Reply Quote 1
          • DanHD
            DanH @d.healey
            last edited by

            @d-healey Ok got there with a bit of help from ChatGBT (hate using it but assume as the code is very close to JavaScript it was actually very close)

            Here's the final code which has worked for me:

            const var PresetList = Content.getComponent("PresetList");
            
            Engine.loadImageIntoPool("*");
            
            //! vptList
            const vptList = Content.getComponent("vptList");
            
            //! pnlList
            const pnlList = Content.getComponent("pnlList");
            pnlList.data.rowHeight = 55;
            
            const var columns = 3;
            
            // Define the spacing between the panels (adjust as needed)
            const var panelWidth = 100;
            const var panelHeight = 55;
            const var spacingX = 5;
            const var spacingY = 5;
            
            //! Functions
            inline function populateList(panel)
            {
            	removeAllChildPanels(panel); // Remove old child panels before adding new ones
            
            	for (i = 0; i < 19; i++)
            		addListItem(panel, i);
            	
            	panel.set("height", panel.data.rowHeight * panel.getChildPanelList().length);
            }
            
            inline function addListItem(panel, index)
            {
            
            	local p = panel.addChildPanel();
            	p.data.index = index; // Set the index here so the child panel knows its own index
            	p.loadImage("{PROJECT_FOLDER}img" + index + ".png", "img");
            	p.set("allowCallbacks", "All Callbacks");
            
            	// Calculate the column and row index
            	local columnIndex = index % columns;
            	local rowIndex = Math.floor(index / columns);
            	                    
            	// Calculate the x and y position based on the index
            	local xPos = columnIndex * (panelWidth + spacingX);
            	local yPos = rowIndex * (panelHeight + spacingY);
            	                    
            	// Set the position of the panel
            	p.setPosition(xPos, yPos, panelWidth, panelHeight);
            	                   
            	//p.setPosition(0, panel.data.rowHeight * index, panel.getWidth() / 3, panel.data.rowHeight);
            
            	p.setPaintRoutine(function(g)
            	{
            		var a = this.getLocalBounds(0);
            		g.drawImage("img", a, 0, 0);
            		
            		g.setColour(this.data.hover ? 0xFF01737B : 0x00000000);
            		g.drawRect(a, 1);
            	
            	});	
            	
            	p.setMouseCallback(function(event)
            	{		
            		if (!event.clicked)
            			return;
            	
            		PresetList.setValue(this.data.index);
            		PresetList.changed();
            		Console.print(this.data.index);
            	});	
            }
            
            
            inline function removeAllChildPanels(panel)
            {
            	for (x in panel.getChildPanelList())
            		x.removeFromParent();
            }
            
            //! Calls
            populateList(pnlList);
            

            Please let me know if you spot anything that might cause me issues down the line! :)

            Thanks so much for the help!

            DHPlugins / DC Breaks | Artist / Producer / DJ / Developer
            https://dhplugins.com/ | https://dcbreaks.com/
            London, UK

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

              @DanH Looks fine

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

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

              19

              Online

              1.7k

              Users

              11.8k

              Topics

              102.4k

              Posts