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

    bright-gpu-74537

    07/30/2020, 5:50 AM
    Copy code
    xml
    <vbox>
        <button text="bob" id="bobButton" />
        <button text="tim" id="timButton" />
    </vbox>
  • b

    bright-gpu-74537

    07/30/2020, 5:50 AM
    Copy code
    haxe
    @:build(haxe.ui.core.ComponentMacros.build("myxmlfile.xml"))
    class Example extends VBox {
        @:bind(timButton.text) public var tim:String;
    
        @:bind(bobButton, MouseEvent.CLICK)
        private function onBob(e) {
            trace("you clicked bob, lets set tim text")
            tim = "clicked"; // timButton.text would also work here
        }
    }
  • b

    bright-gpu-74537

    07/30/2020, 5:51 AM
    this is using the binding, but you certainly dont have to use it, this might shed a little more light: https://github.com/haxeui/haxeui-guides/blob/master/custom-components.md
  • f

    fast-rain-20339

    07/30/2020, 5:51 AM
    Ah, I haven't seen @:bind before.
  • b

    bright-gpu-74537

    07/30/2020, 5:51 AM
    it will only work in conjunction with the @:build
  • k

    kind-policeman-40412

    07/30/2020, 5:52 AM
    So the only way to refer components by id is to create a wrapper component? Can I do the same without wrapper comp? Just build the xml and access the components inside by id?
  • k

    kind-policeman-40412

    07/30/2020, 5:52 AM
    oh i see
  • b

    bright-gpu-74537

    07/30/2020, 5:52 AM
    yeah, the above example will do that
  • b

    bright-gpu-74537

    07/30/2020, 5:53 AM
    the macro will turn everything in the xml into a correctly typed member var (of Example)
  • b

    bright-gpu-74537

    07/30/2020, 5:54 AM
    if you wanted to use only script, you can for sure, but the problem is using external haxe classes, the example above, could certainly be rewritten to only use xml + script
  • b

    bright-gpu-74537

    07/30/2020, 5:54 AM
    Copy code
    xml
    <vbox>
        <button text="bob" id="bobButton" onclick="tim.text='clicked'" />
        <button text="tim" id="timButton" />
    </vbox>
  • b

    bright-gpu-74537

    07/30/2020, 5:55 AM
    but this will only work because tim is in the same xml file
  • b

    bright-gpu-74537

    07/30/2020, 5:56 AM
    so really, the scripting part is NOT meant for writing big important things, though, i do agree, it would be nice to be able to pass a context into an xml component, i just dont know how that would look / work - ie, what interface/api
  • k

    kind-policeman-40412

    07/30/2020, 5:57 AM
    I understand. By scripting you mean it's not Haxe but hscript or something? I just don't know this stuff sorry.
  • b

    bright-gpu-74537

    07/30/2020, 5:57 AM
    exactly
  • k

    kind-policeman-40412

    07/30/2020, 5:57 AM
    so it's interpreted?
  • b

    bright-gpu-74537

    07/30/2020, 5:58 AM
    if script is used in the xml, yeah, its hscript, not haxe code... to be honest, ive been thinking about this and i might change that to make it haxe code if its built at compile time, but the runtime stuff is useful, it means you can have "code" (hscript) in an xml file and run it all dynamically
  • k

    kind-policeman-40412

    07/30/2020, 6:02 AM
    Actually I think it's easier to me to just use the
    code
    way of creating ui for now. As for scripting I can't suggest anything right now as I'm pretty new to Haxe and know too little about HaxeUI internals. But overall I'd like to avoid scripting and somehow generate code at compile time.
  • k

    kind-policeman-40412

    07/30/2020, 6:03 AM
    I don't see a need for scripting if you know your types upfront. I wanted to refer known objects with known types.
  • k

    kind-policeman-40412

    07/30/2020, 6:05 AM
    Of course it might be complicated to support that, I understand )
  • b

    bright-gpu-74537

    07/30/2020, 6:05 AM
    i agree totally, scripting is a "nice" feature, but really you should be using haxe code - though i agree, having the "script" in an xml file turn into haxe code makes sense, just have to think about the benefits / costs as runtime script it can be useful
  • b

    bright-gpu-74537

    07/30/2020, 6:09 AM
    also, its generally better to have your layout and logic seperated, haxeui doesnt force this one you, but it does nudge you into that direction (i think), but making it nice and easy to create an xml file and associate it with a haxe class
  • k

    kind-policeman-40412

    07/30/2020, 6:10 AM
    Without diving into complexity I would like to pass a Map to a builder so it will generate proper code in place of onClick="". It may use slightly modified syntax, something like in React onClick={event -> context.myobject.myMethod()} and contain not script but actual haxe code. Where the context is that Map.
  • k

    kind-policeman-40412

    07/30/2020, 6:12 AM
    Of course I agree about separation of concerns. I would not put any logic into templates.
  • k

    kind-policeman-40412

    07/30/2020, 6:14 AM
    I mean obviously if you support haxe code in callbacks someone could use that to put some logic into ))
  • k

    kind-policeman-40412

    07/30/2020, 6:17 AM
    The way it works now looks pretty much the same as in android where you refer to elements by id. Ok not the same but pretty similar.
  • b

    bright-gpu-74537

    07/30/2020, 6:17 AM
    so yeah, its defo something ill look into - since ill have access to the xml at compile time it should be more than possible to use whatever "script" it contains and use actual haxe code rather than hscript, but currently, it just doesnt support this
  • b

    bright-gpu-74537

    07/30/2020, 6:17 AM
    yeah, its similar to that, if android kinda "autolinked" bits for you
  • b

    bright-gpu-74537

    07/30/2020, 6:18 AM
    this might help out for reading about custom components / views: https://github.com/haxeui/haxeui-guides/blob/master/custom-components.md
  • k

    kind-policeman-40412

    07/30/2020, 6:18 AM
    thanks will look into 🙂
1...326327328...1687Latest