https://linen.dev logo
Join Discord
Powered by
# haxe-ui
  • b

    bright-gpu-74537

    07/12/2022, 12:28 PM
    Copy code
    html
        <script src="haxeui.js"></script>
    
        <script>
            haxe.ui.Toolkit.init();
            var button2 = new haxe.ui.components.Button();
            button2.set_text("Button 2");
            button2.set_onClick(function(e) {
                button2.set_text("Thanks!");
            });
            document.body.append(button2.element);
        </script>
    Not exactly the nicest api to work with from vanilla js, but still functional
  • b

    best-agent-85158

    07/12/2022, 12:36 PM
    Just @:expose that API
  • b

    bright-gpu-74537

    07/12/2022, 12:36 PM
    thats what i did
  • b

    best-agent-85158

    07/12/2022, 12:36 PM
    then you could use button.text = "asdf"
  • b

    best-agent-85158

    07/12/2022, 12:37 PM
    wait wat
  • b

    bright-gpu-74537

    07/12/2022, 12:37 PM
    well, id need to @:expose("button") for that
  • b

    best-agent-85158

    07/12/2022, 12:37 PM
    why? i think you could just expose fields with this
  • b

    bright-gpu-74537

    07/12/2022, 12:37 PM
    but thats the easy part, ill just copy the addGlobalMetadata macro and "add some stuff"
  • b

    bright-gpu-74537

    07/12/2022, 12:38 PM
    wel, for me the main issues (apart from the haxe.ui.components.Button part, but thats easy to fix with @:expose) is a) no native setters (even with es6) and b) have to use the
    .element
    part
  • b

    bright-gpu-74537

    07/12/2022, 12:39 PM
    how are you expecting that to work without native es6 setters?
  • b

    bright-gpu-74537

    07/12/2022, 12:39 PM
    .text, without them, isnt a setter, its a variable - so it wont trigger any of the code that is attached to the setter
  • b

    best-agent-85158

    07/12/2022, 12:39 PM
    -js-es="6"
    ?
  • b

    best-agent-85158

    07/12/2022, 12:40 PM
    or i think thats the name of that define
  • b

    bright-gpu-74537

    07/12/2022, 12:40 PM
    doesnt use native es6 setters, as i said above
  • b

    best-agent-85158

    07/12/2022, 12:40 PM
    thats pretty lazy
  • b

    best-agent-85158

    07/12/2022, 12:41 PM
    shouldnt that be an issue tho?
  • b

    bright-gpu-74537

    07/12/2022, 12:41 PM
    https://github.com/HaxeFoundation/haxe/issues/5104
  • b

    bright-gpu-74537

    07/12/2022, 12:42 PM
    i wonder if find and replace "get_" with "get " would work (with some regex to make sure its a function etc)
  • b

    bright-gpu-74537

    07/12/2022, 12:47 PM
    well, manually changing "get_text" to "get text" breaks everything as there are other places in the code that use "get_text"... so i think it would have to be done at the generator level 😦
  • b

    bright-gpu-74537

    07/12/2022, 12:57 PM
    Copy code
    haxe
        static function __init__():Void {
            #if js
            untyped Object.defineProperty(ComponentContainer.prototype, "text", { get: ComponentContainer.prototype.get_text, set: ComponentContainer.prototype.set_text });
            #end
        }
  • b

    bright-gpu-74537

    07/12/2022, 12:57 PM
    this works, as the ticket above described - pretty ugly though
  • b

    bright-gpu-74537

    07/12/2022, 1:06 PM
    Copy code
    html
        <script>
            Toolkit.init();
            var button2 = new Button();
            button2.text = "Button 2";
            button2.onClick = (e) => {
                button2.text += " clicked";
            };
            document.body.append(button2.element);
        </script>
  • b

    bright-gpu-74537

    07/12/2022, 1:06 PM
    defo nicer though
  • b

    best-agent-85158

    07/12/2022, 1:39 PM
    you could make a function for that instead of putting that in the constructor 🤷‍♂️
  • b

    best-agent-85158

    07/12/2022, 1:39 PM
    like in a
    defineJsAccesors()
  • b

    bright-gpu-74537

    07/12/2022, 1:43 PM
    its in the magic
    __init__
    function
  • b

    bright-gpu-74537

    07/12/2022, 1:43 PM
    and realistically, i'd generate all of this at compile time
  • p

    purple-businessperson-14467

    07/12/2022, 3:23 PM
    Nice, would externs reduce file size with app1 and app2 not including HaxeUI? App1 being 2 mb and app2 being 2mb...but with externs App1, App2 are 1mb with haxeui being 1mb?
  • b

    bright-gpu-74537

    07/12/2022, 4:23 PM
    yeah, so app1 and 2 would be built against the externs which means they would be absolutely tiny, well, js size without haxeui
  • p

    purple-businessperson-14467

    07/12/2022, 4:56 PM
    How far off is that? It seems compiling might be quicker....Maybe that could be done with haxe-modular as well
1...116311641165...1687Latest