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

    handsome-television-62908

    06/19/2020, 4:55 PM
    Anyone else notice that something like
    component.findComponent('').onClick = ..
    breaks on compile? Looks like the compiler code for type inference might be broken in this specific case. . . Since it doesn't seem to be able to recognize that
    Component
    can be used as
    { onClick: (e)->Void}
    I am using whatever Kha version is on VSCode right now - but I'm going to take a wild guess this is just a compiler problem. Is anyone not getting that sort of problem?
  • b

    bright-gpu-74537

    06/19/2020, 4:59 PM
    you need:
  • b

    bright-gpu-74537

    06/19/2020, 4:59 PM
    findComponent(..., Button).onClick
  • b

    bright-gpu-74537

    06/19/2020, 5:00 PM
    i still dont understand why everyone is using findComponent and not just using macros / custom components
  • b

    bright-gpu-74537

    06/19/2020, 5:00 PM
    ¯\_(ツ)_/¯
  • h

    handsome-television-62908

    06/19/2020, 5:03 PM
    Oh - that does make sense! I was able to do
    var name:Button
    to the same effect so I imagine it's nearly the same result... But I'm curious - you mentioned
    macros
    . What macros are you referring to? all I know are the custom component ones
  • b

    bright-gpu-74537

    06/19/2020, 5:03 PM
    yeah,
    var button:Button = findComponent(...)
    has the same effect
  • b

    bright-gpu-74537

    06/19/2020, 5:05 PM
    well, i just mean, create your views with the build macro and everything is member var plus event binding, and var binding, two secs, ill knock up an example - there is nothing wrong with findComponent, its just laborious
  • b

    bright-gpu-74537

    06/19/2020, 5:05 PM
    in fact, there is a guide i wrote, or thought i wrote
  • b

    bright-gpu-74537

    06/19/2020, 5:05 PM
    two secs
  • b

    bright-gpu-74537

    06/19/2020, 5:06 PM
    https://github.com/haxeui/haxeui-guides/blob/master/custom-components.md
  • b

    bright-gpu-74537

    06/19/2020, 5:06 PM
    Copy code
    haxe
    @:build(haxe.ui.macros.ComponentMacros.build("assets/my-component.xml")
    class MyComponent extends HBox {
        @:bind(textfield.text)
        public var textfieldText:String = "10";
        
        @:bind(deinc, MouseEvent.CLICK)
        function onDeinc(e) {
            var n = Std.parseInt(textfieldText) - 1;
            textfieldText = Std.string(n);
        }    
        
        @:bind(inc, MouseEvent.CLICK)
        function onInc(e) {
            var n = Std.parseInt(textfieldText) + 1;
            textfieldText = Std.string(n);
        }    
    }
  • b

    bright-gpu-74537

    06/19/2020, 5:07 PM
    so basically, the macro turns everything in the xml (with an id) into a correctly typed member var
  • b

    bright-gpu-74537

    06/19/2020, 5:08 PM
    so you dont need to do findComponent anymore, just "myButton.onClick", but then you can also using binding to not need that even and just use
    @:bind(myButton, MouseEvent.CLICK)
  • h

    handsome-television-62908

    06/19/2020, 5:13 PM
    Oh, yeah! I'm aware of this feature - I thought you were referring to something different. But yeah - I should take advantage of custom components, I suppose I ran into the problem as I was quickly running my memory through the API again . . . But what I think I'm looking for is what the module file offers it seems!
  • h

    handsome-television-62908

    06/19/2020, 5:13 PM
    Thanks Ian 😃
  • b

    bright-gpu-74537

    06/19/2020, 5:14 PM
    you can defo do it all with just plain code, the macros just make your life a hell of alot easier (imo)...
  • c

    clever-oil-61353

    06/19/2020, 5:15 PM
    i agree with that lol
  • h

    handsome-television-62908

    06/19/2020, 5:22 PM
    Indeed it does depend on the case for me, though! I like closures . . . and a simple
    (new MyComponent()).button.onClick = this.performAction;
    removes all the boilerplate I'd otherwise have to do for a new class... But I know there's definitely a number of tricks you can do with built components to also make pretty nice and composable - which I'll definitely use with time!
  • b

    bright-gpu-74537

    06/19/2020, 5:23 PM
    (new MyComponent()).button.onClick
    will work with custom components, in fact, think its the only way that would work, otherwise you need a
    (new MyComponent()).findComponent(..., Button).onClick
  • b

    bright-gpu-74537

    06/19/2020, 5:24 PM
    (the member vars the macro creates are public and typed)
  • b

    bright-gpu-74537

    06/19/2020, 5:25 PM
    dialogs are the best use case (for me, but in reality i rarely dont use custom components)
  • b

    bright-gpu-74537

    06/19/2020, 5:27 PM
    Copy code
    haxe
    @:build(...)
    class MyDialog extends Dialog { // thats it!
        @:bind(something.text) public var something;
    }
    
    ---
    
    var d = new MyDialog();
    d.title = "My Title";
    d.something = "bob";
    d.somethingElse.text = "tim";
    d.show();
  • b

    bright-gpu-74537

    06/19/2020, 5:28 PM
    thats a dialog example, but the same applies to all haxeui custom components (as i mentioned before dialog is just a component with a special overridden "show" which you wouldnt generally call on normal components)
  • h

    handsome-television-62908

    06/19/2020, 5:29 PM
    This isn't possible using modules.xml? I can't see it myself anymore atm - not on my project
  • b

    bright-gpu-74537

    06/19/2020, 5:30 PM
    none of that above uses modules, thats just if you want to use custom components from xml
  • b

    bright-gpu-74537

    06/19/2020, 5:31 PM
    in this context (custom components) all the module does is allows you to register components or packages (that will be scanned) for classes extending from Component to be able to use in xml
  • b

    bright-gpu-74537

    06/19/2020, 5:31 PM
    so,
    class MyButton extends Button
    wont work with
    <mybutton>
    in xml without the module entry exposing it
  • b

    bright-gpu-74537

    06/19/2020, 5:32 PM
    but you can still create "new MyButton" all you want
  • b

    bright-gpu-74537

    06/19/2020, 5:32 PM
    and how you build MyButton (via code, via xml, using macros) is irrelevant
1...283284285...1687Latest