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

    user

    06/03/2020, 9:15 PM
    @User when add a custom component, how do you handle a new xml prop ?
  • u

    user

    06/03/2020, 9:15 PM
    for ex
  • u

    user

    06/03/2020, 9:15 PM
  • u

    user

    06/03/2020, 9:16 PM
    how to you handle myattrib on MyComponent.hx ?
  • u

    user

    06/03/2020, 9:16 PM
    I see you use "behavior" but is there any doc about it ?
  • b

    bright-gpu-74537

    06/03/2020, 9:17 PM
    depends if you want to make your component "compatible with everything" or you are happy targeting a specific backend
  • u

    user

    06/03/2020, 9:17 PM
    with everything of course 😉
  • u

    user

    06/03/2020, 9:18 PM
    it's only an integer or text value, nothing more
  • b

    bright-gpu-74537

    06/03/2020, 9:18 PM
    if you want full compatibility, then yeah, behaviours, otherwise just a property on the class
  • b

    bright-gpu-74537

    06/03/2020, 9:19 PM
    if it doesnt do anything to the UI (ie, the native element, the component component, the dom element, etc) then just a "var myattr:Int" will work
  • b

    bright-gpu-74537

    06/03/2020, 9:20 PM
    but if you want it to actually do something to the UI, ie, lets say change the text, then, as i mentioned, you have two options... a setter that does something to the underlying native widget (which would only work on haxeui-hxwidgets) or by using a
    @:behaviour(DefaultBehaviour) var attr:Int
  • b

    bright-gpu-74537

    06/03/2020, 9:22 PM
    i guess i should probably write something about behaviours
  • u

    user

    06/03/2020, 9:26 PM
    so I'm doomed 😦
  • u

    user

    06/03/2020, 9:26 PM
    I want to create a component made of 3 labels
  • u

    user

    06/03/2020, 9:26 PM
    and set there values by xml
  • u

    user

    06/03/2020, 9:27 PM
  • u

    user

    06/03/2020, 9:27 PM
    so I need behaviors...and potentially code for any backend I want to support 😦
  • b

    bright-gpu-74537

    06/03/2020, 9:30 PM
    thats not so bad, in fact, i would say, you wouldnt need to have a native component for that... that could be a "composite component" (ie, another component made of other components) with no issue
  • b

    bright-gpu-74537

    06/03/2020, 9:31 PM
    you arent adding any new components there, just Label and they are already setup with a native counter part, so:
  • b

    bright-gpu-74537

    06/03/2020, 9:33 PM
    Copy code
    haxe
    class MyComponent extends VBox {
        public function new() {
            _label1  = new Label();
            addComponent(_label1);
            _label2  = new Label();
            addComponent(_label2);
        }
        public var text1(get, set):String;
        private function get_text1():String {
            return _label1.text;
        }
        private function set_text1(value:String):String {
            _labe1.text = value;
            return value;
        }
        // repeat for 100 labels
    }
  • b

    bright-gpu-74537

    06/03/2020, 9:33 PM
    (untested code just written, not run)
  • u

    user

    06/03/2020, 9:34 PM
    ho...it was my first idea but then I saw behaviors 😉
  • u

    user

    06/03/2020, 9:34 PM
    perfect
  • b

    bright-gpu-74537

    06/03/2020, 9:35 PM
    the behaviours are different, take for example a button.... well, for a composite backend (html5, openfl, etc), that is a "Button" component, with a "Label" component
  • b

    bright-gpu-74537

    06/03/2020, 9:35 PM
    then there is a button layout that does all the positioning etc
  • b

    bright-gpu-74537

    06/03/2020, 9:35 PM
    so thats all fine
  • b

    bright-gpu-74537

    06/03/2020, 9:36 PM
    well, then if you use that for a native backend (like wx) well, that would turn into a panel with a label in it... which isnt a button :), so haxeui lets "replace" classes, so a haxeui button then becomes a wrapper for a native widget (.widget i think in haxeui-hxwidgets)
  • b

    bright-gpu-74537

    06/03/2020, 9:37 PM
    so thats all fine, now we have a correct class (hx.Button) and a thin wrapper around it.. ... however! The next issue is properties... say you say ".text" on that button, well, if its a composite it will try to create that label and add it to a the hx.Button
  • b

    bright-gpu-74537

    06/03/2020, 9:38 PM
    at best it will do weird stuff, and worst it will totally break and segfault
  • b

    bright-gpu-74537

    06/03/2020, 9:38 PM
    so the way haxeui handles this is a behaviour
1...255256257...1687Latest