Giter Club home page Giter Club logo

Comments (6)

Slluxx avatar Slluxx commented on June 11, 2024

ImPS is enspired by Dear ImGui and i want it to behave just like that. It is easy, fast and one doesnt need to learn any kind of structure of how things work to use it. Given my statement about the similarities in the readme, i dont know why i should use DSL.

from imps.

majkinetor avatar majkinetor commented on June 11, 2024

It was just a suggestion. Current way is not in the spirit of pwsh.

from imps.

Slluxx avatar Slluxx commented on June 11, 2024

I am doing powershell since about a week (general fullstack coding for way longer) and due to your comment, i just looked deeper into DSL. Its an interesting solution although not best practice and definitely not "in the spirit of pwsh". Well, maybe its considered as that now but it definitely wasnt back in the day.

However, again, an interesting solution. There are some problems with it though which require some thinking-ahead to minimize any kind of drawback this might have over MC. I will try to come up with a prototype and maybe, if it proves to be superior, use that instead.

I should have been more open to a "new" concept in the first place, although i stand by my answer that i wanted something that feels like using ImGui.

from imps.

majkinetor avatar majkinetor commented on June 11, 2024

Some well known modules work with DSL, for example pester, invoke-build, pshtml etc.

The DSL is superior for writing GUI's IMO as it is less repetitive, structured in the way you think about GUIs, and you don't mess with the C# syntax. You can still offer the same syntax as before along with it because it may work better in dynamic scenarios.

from imps.

Slluxx avatar Slluxx commented on June 11, 2024

After some messing around, i created a simple script that works like this (the _ because "Label" is already defined)

Window_ "mywindow" 300 150 {
    Label_ "My first Label" 20 20
    Label_ "my bold label" 20 40 {
        Set-Attr "Font" "Verdana,8,style=Bold"
    }
}

However the more i work with it, the less i like this due to multiple reasons. For example:

Set-Attr needs to have access to the created label which, without passing it via pipe or argument, has to check blindly if a variable ($Element in this case) exists based on the parent scope.

function Set-Attr {
    param ( $Attrib, $Value )
    if (Get-Member -inputobject $Element -name $Attrib -Membertype Properties) {
        $Element.$Attrib = $Value
    } else {
        Write-Host "Attribute $Attrib not found in $($Element)"
    }
}

An element might or might not have a clickhandler or other optional arguments and might or might not have its attributes changed in the scriptblock.

Window_ "mywindow" 300 150 {
    Label_ "My first Label" 20 20
    Label_ "my bold label" 20 40 {
        Set-Attr "Font" "Verdana,8,style=Bold"
    }
    Button_ "Btn1" 0 0
    Button_ "Btn2" 0 0 $clickhandler
    Button_ "Btn3" 0 0 {
        Set-Attr "Font" "Verdana,8,style=Bold"
    }
    Button_ "Btn4" 0 0  $clickhandler {
        Set-Attr "Font" "Verdana,8,style=Bold"
    }
}

Accounting for all of this (optional + moving args) doesnt seem like something that should be done. At most, i could define a set-clickHandler function but then we have the same issue as before, where i am relying on the parent scope for variables.

Then again, i could Pipe them - which works but looks horrible or i pass the parent as variable, which sucks too.

from imps.

majkinetor avatar majkinetor commented on June 11, 2024

Set-Attr needs to have access to the created label which

That is internal detail that can be accomplished. You might also want to expose $_ to the user to refer to the "current parent", although that would work just for first level parents (but easily achievable for higher hierarchy with or without explicit support of the module).

Also some DSL changes could accomplish that:

instead of

 Label_ "my bold label" 20 40 {
        Set-Attr "Font" "Verdana,8,style=Bold"
    }

you could

Label_ "my bold label" 20 40 -Font "Verdana,8,style=Bold" {
}

#or 

Label_ "my bold label" 20 40 {
    $_ | Set-Attr "Font" "Verdana,8,style=Bold"
}

Not sure what the problem is with the click handler, you could for example set it inline or use shared one:

    Button_ "Btn2" 0 0 -Handler { 
          Write-Host $_.title
    }
    Button_ "Btn3" 0 0 -Handler $btnHandler
        $_ | Set-Attr "Font" "Verdana,8,style=Bold"   #or it could work on $_ by default if no InputObject is set
    }
    Button_ "Btn4" 0 0   -Handler $btnHandler
        Set-Attr "Font" "Verdana,8,style=Bold"
    }
    function btnHandler {   Write-Host $_.title clicked }

from imps.

Related Issues (1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.