Create UI factory



  • I don't quite understand the "Create UI factory method form selection" thing

    If I select a panel in ScriptEditor and then call this "Create UI factory method form selection“ function.

    Where do I put this then again?????

    What do I do with it then????



  • @MikeB more info here:
    https://docs.hise.audio/scripting/scripting-in-hise/scriptpanel.html#use-the-"create-ui-factory-method"-tool

    @Christoph-Hart However dragging the panel doesn't update the function arguments as mentioned in the doc's tips...



  • @ustk Thanks - but that's where I'm coming from - I've read through all this and still can't come up with a working function.
    Function - But if you write that it does not work anyway - then I can try around for a long time.

    @Christoph-Hart:
    Why can't you just copy a button or panel and its code together and put it into another project.
    Or even save it in a library to use it again and again.

    Also it would be conceivable when inserting snippets to ask the user if:
    a. The snippet replaces the existing preset
    b. The snippet should be loaded additionally



  • @MikeB Since you can create widgets with script, you can save this part of the code in an external JS file and use it in any project.
    Select the code you want, right-click, "Move selection to external file". Hise will create a *.js in the Scripts folder and replace the exported part of the script using the include method

    include("myScript.js");
    


  • @MikeB Can you make the doc example working?



  • @ustk said in Create UI factory:

    @MikeB Since you can create widgets with script, you can save this part of the code in an external JS file and use it in any project.
    Select the code you want, right-click, "Move selection to external file". Hise will create a *.js in the Scripts folder and replace the exported part of the script using the include method

    include("myScript.js");
    

    Thank you, I always do it that way.
    It's about the fact that I have added buttons to a project and I want to load them now.
    completely - so button and scripts in a new project - and that is not possible.

    I can export the script but I have to create every single button in the new project and link it to the script.
    And that is cumbersome

    Or is there a way here?



  • @ustk said in Create UI factory:

    @MikeB Can you make the doc example working?

    i dont understand?!



  • @MikeB said in Create UI factory:

    @ustk said in Create UI factory:

    @MikeB Can you make the doc example working?

    i dont understand?!

    Don't bother, it doesn't seem relevant, I was talking about transforming a component script into a factory method...

    But if your widget factory method contains something like

    local widget = Content.addPanel(name, x, y);
    

    then all widgets will be created with the function calls, so you'll never need to copy/paste components, unless there's something I don't understand in your problem...

    It is the same thing if you don't have a factory method, but you use multiple

    Content.addPanel(name, x, y);
    

    you just need to copy-paste the code as components will be automatically added.

    But if you inserted components manually and just use something like

    const var Panel1 = Content.getComponent("Panel1");
    

    then yes you need to insert buttons manually again in other projects.
    In this case if you want them to have the same attributes, you have to copy-paste the JSON info from one project to the other (select the components in the first project, hit "J", copy the JSON, open the new project, select and press "J", paste, hit F5)
    This is why using the factory method is the way. You don't need to bother copying-pasting components, just the script as components will be created by the factory method again...



  • Ok - do you have a codefragment or snippet for this as an example?



  • @MikeB Hmmm... I'd like to make one but it won't give you more than the doc. A video would be better for demonstrating this but I don't know if I can right now

    However if you have a minimal snippet I can probably show you a way to manage it across projects



  • @MikeB If you understand how to make the factory method (from scratch or by right click menu transformation) then you know it all 🙂
    just use the include thing across projects as you know



  • Thank you - this is very simple - see snippet
    A panel with a button and a label.

    I want to use this now 20 times in my project

    HiseSnippet 753.3ocsUssaSCCF1tqdZsPmXR7.TwUaRioTXafDWPomPUrCUjsIthIOG2EqkXGk3rsJDR7RvaDOP7F.+NIsIiUJcQhbU99O94+C1iBULdTjJDgqcxj.NB+Xh8Do1sqKUHQC6gvqSNjFo4gMSE0YR.MJh6fv3UduQ.tVUTx2OeaGpGUx34hPnyTBF+.guPmKcT6OH77FPc3mH7KX8tsGxTxtJOULvmUHVn.J6J5k7inFypPP3U66HzpPaMUyiP3pcTNSrcU2HSs+LQj3BOtAzBYCAJU7.kmigwFonttBOmQSO2QHHJixqBqjVEdJ4PgiXl77pwSRTzL2ih0CbkEQuV+a5YMO5gKPupozaChMKTDny0X31iHCkPiZLEZAEoUpsH7OHcUfAR8N9zq3CBAvLG1beKqsatmk0VuoQ8F0GGKYZgR1TIORo4GK2bq5eods5esdy+T03wyUmIUgJOOd3bUa57gKxwMkw9WvC2t40TuX9LCgRvcqwqtb0XV5IufgJ4PoPeb.OCu3gDTVoyzOxXHXpNoardV2nSrVqjHADjZjTPKTB8KtQfNcXOplNMPPLg7DvC0BywA2ieMrwj1lqQ5witRqBRr0OPIML.uZZZaLcHfJ4dIYcMRx+sP2hvD7oPtlX9oM7yMBGsqA7c.3xEW5pMnOCHbkBwlrDG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KYcF1VlEcFOoLETNQnFvxEYtyMqHCylUpMQkbjTneWLuPd8UIQEoUSAoBBgopyKG8fhxQ18aj.bRSbwlOJG+5sDPebz.plV5HvmPbh4IZgY43Lf+EnkgsNWS7.d54ZUb9bK1KgkrMrsJqBZtQjG06hs2NPeE4fc9HDq4l+zC9yEBecfQ3u.g.tXVf1H8GfjSiZ9FeCVResZ4rWu4UB6zKll.dol6VPD5pwnj+7CeE7aOHdcQ3OGrtHb09DP2JkeVHUubKLSe6BEvQtk5UX5GHSE5406q+SzWy6F218lh6CwiEZVvp4swJ30rgdKyawqDZgGNcJmoqfca7Q+9l9jfeBTduJSKjyNgpSDli5mlEMAJKx3.IR3vPp4ncCykVqrmQ1jYlvk94B+K7UnrqQ1oPY2RknHJKQ8Yl8pt4cH2MeDfIY9ywZBuKDjIKtgiwdc7PQvyi9LiYREOFXe017qafM+1FXyS1.ad5FXyy1.ad9FXyKVqMlWldPFzWzdMAFX7v7JsNNCkT3TV9IRz+AnJAIEA
    


  • @MikeB Let me eat something then I'll do it 😉



  • @MikeB here you go 🙂

    HiseSnippet 1485.3ocsXstaaaCEVJMpnwatXEXO.D9OSYMyUxNocsdEsMNwaoq4Bl65FPQPAsDsEWkIMjnZrQQdM1CwdA16z90dC1NGRYa4DGuX2EAXawCOW93GOjGReRhLfklJSrr230iFvrr+bm1iDpnlQTtv5f8rruqygzTEKgXDs6nAzzTVnks8s9dTf8Fqaoe96msKMlJBXSEYY8FIOf8JdetZpzSd9OxiiaQCYul2uf1a+7CBjhlxXYFfma43YMfF7dZO1QTTs0brru89gbkLoshpXoV1quqLbT6H4YBi9ugmx6DyvF9VsAGYD2RFGhHFkZ0LhGGdx3wcpE3kSlxB2xvBeoyg7P9D4SYiuP2AYpEE4C60VD77KBOu4BOu4AO6BvacC7tmS6fD9.0zdPr8YNGHfIptTXJnHrL5Zs1edamlRPCgpZe56YsRfFSrv8QddaQ1wyayFkKUtzCd.4WXeUbLIKkQhP.ljRRkjyXj.pfPCv3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YAXZc0CJ8N6yDOX22KDOW3kq14Fj33.K3WTftD64ahxebixd9WC1yegrm+Rwd9KG64uxrWMSTdo8MI6U6Zvd0VH6UaoXuZKG6UakYu5ln7W2nrW8qA6UegrW8kh8pubrW8YYuKeSM39hxvL3tQydIR7ly4c.U.m41Z3MxDob0nh2r9S9lkysV20Dt2y4DtJHZ93cs4fWbR9FFu42Sury9c6xBTSA65Ns90+euT9bgh4RU8NjpR3X5xQY8aC2VJfAHQ.IF3oTrWCq.aZ6gsQloMSDpa7OvSdm9Xa67N8G2oUeZPh7cAlR33+DvczR.LIz+gHa3bH1l3OttsiiWUOq97P96BBPp3a.rOeapsB1TeErY6UvlcVAad3JXyiVAa91EZC9eC8hLkruYYBH3j80mex1deAExxzYjV+qq2KyI
    


  • @ustk: Super Thank you
    This is the right approach and helps me a lot to understand.
    But I still have a small problem 🙂

    I have now tried a little bit.
    In the for loop is the number of panels that will be created.

    I would like to move each button to a different position.
    But when I add a new button, all of them will be moved to the
    to the given position.

    Basically, panels that are already created should remain untouched.
    only a new one would have to be added at 0,0 position.

    is this possible?



  • @MikeB That's doable.

    So you need to place them in a non-related fashion regarding the position right?
    In this case, you need to pre-define the positions in an array

    or do you need a new button to be inserted at the first position?

    I'll work out a solution sometime in the afternoon/evening...



  • The problem is
    You make 5 buttons and place them in your FrontInterface

    Now you make a 6.th and click compile

    All five already placed buttons jump back to position e.g. 0.0

    and you have to place all 6 new again

    The creation of a new button must not change the already existing ones - that is the goal.



  • @MikeB That is because they are placed automatically. So yes when you move them manually, the script resets their position at compile.
    As explained in the doc, there should be an automatic update of the positions arguments when using a "createXXX" factory name, but as I said earlier to @Christoph-Hart there's a problem with that, or I don't know how to use it...

    In waiting for a fix, even if not very practical, you'll have to use an array for the positions. So every time you move a panel, you need to update the positions. Every new panel will be created at [0,0], move it, and be sure to add its new position in that array.

    HiseSnippet 1672.3ocsXs0aaaCEVJMpnwatnEX+.H7KyA0yU1NocMtEsMW7V1xEi4t1ATjUPKQawUY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PsDB
    


  • @MikeB this is a very small snippet only for the actually creation of the panels, the script will read if there already is panels created and it will leave them as they are but will create the extra if specified.
    However I didn't know how to make it check properly

    Maybe this way to do it is not recommended, maybe @ustk knows?

    HiseSnippet 822.3ocsV0sSaCCE1tzfnYqSCo8.XwUsCFJk+1jJnwnsLUsATsxP6NjmiC0hD6nDGFUHdq106YZuAaGmz1z1UPzJMeQU74b9r+NG+4iamHEiGGqhP3Rm2OjivO2paeotWidTgD0tIB+BqSnwZdDIyzQ8CowwbWDFuzGMFvkJhRG+98GQ8oRFO2DBcgRv3eVDHz4V6b3mD99GSc4mKBFK5cNrMSIan7UI.eVxxAERYWSuheJ0DVAKDd4VtBsJpqlp4wPLGob62sm5Gxr3uPDK9tO2LoFpKrPYlQM5I7c6LLWiQHbwN4Y9RYY9qrNQ3JFYOuB7xTGjbDiWCvEljREmfR0dHJcrx20r.O.8viQuhYzaUqtrHQnN2igaOypsDNb7nPYebZkEKpvuvVMTPDR8lAzq4GGASFgnxdNNaP10woZ8x1ksERegjS7RjLsPIIrHNjScnRtebEYRP0x12U1l.COUDohfb.woNQP1m.NgOVe8pYtGDkYH7HUFRfq35FpfPkDlTYsPy5t15hpjCNfjHc4dvl6VMG5XqhY3qXTeRJJXiGtlTW2TBludaPpAI0dNjWSDUqOZIt2N626MY5DY1NUqOJkUxSUZ9YxJUsuytjM.ZZWddyzmgOQJeedzLcaD5QOFPS8867nMH2P8S3iBDN8mTds7SSdwxJOiEnR1VJzmExGLOW.VaFBPzf5K70Wa2jpoFM4.aPbg7HsvPGbS9MvE7LEZIql73q0pPf0iNngu0odKOT+Zp5HAr0qXkdl4ftEgsv1vd027QZuf4.esovu+bheqove6bhe6ov+yzdb+y8WnKhxMwmpmr0hoG5.GffXh6vl6oxXgt+38Xmi9MNyreyLOtehzcUqNBMq2r4agYvWP17+luC5dW1pkmGmoyIaQqi+1h1pdNnxWTIZg7pSn5HgQHbZRPW3ALFGXhzzfwnIJXjTYycFpw6xktoS9CLF3rl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