Extending Existing Components

Dear Creator,
I’m new to HaxeUI and now trying to build some custom component to fit my needs. Just wonder how to do it.

If I extends a component let say “TabBar”, can I still use @:composite metadata to add my own implementation? Will this replaced TabBar’s Builder/Events/Layout or will they all work under some order of inheritance structure just like I extends a class?

Also, if I extends a component, can I still use @:behavior to add new attributes, or modify existing ones?

As I read through the source code, I found that the whole system works under complex use of macros, which I still not fully understand…

Hi,

Welcome! :slight_smile:

So for the most part yes, you can add your own @:composite bits… usually though, if you wanted the previous behaviour you would need to extend your composite class from the parents, for example, say you wanted to create a new tabbar with some different layout using @:composite:

@:composite(MyTabBarLayout)
class MyTabBar extends TabBar {
    ...
}

class MyTabBarLayout extends TabBarLayout {
    ...
}

This way you inherit the code of the parents layout. Of course, you dont have to do that… if you are rewriting a layout completely then you dont need to inherit the previous layout code. The same concept applies to Builders and Events.

Behaviours are much simpler, you can use just them in any “Component” derived class, if they already exist they should just be overloaded.

I appreciate that the way things are structured initially in haxeui can be confusing / daunting but its exactly because of these behaviours that haxeui can work with so many different backends / frameworks including creating 100% native UIs.

Also, keep in mind that, depending on your usage you may not care about any of this stuff… the @:composite / @:behaviour stuff is generally to abstract code away so that native UIs will work (and not try to use composite code - which will likely crash)

Hope that helps a little, let me know if you have any other questions, or i wasnt clear enough.

Cheers!
Ian

Thanks for the quick reply :smile:

I have tried extending TabBar.Layout, but it was a private class I cannot reference to it even with @:access, any hint?

Also, may I ask for more explanation about the scope and responsibilities of Layout and Builder? I found that there are some overlap in this area.

Thanks for help~~

Hmm, you are right… Ideally id like to not have to make them all public, but i guess if i have to i have to.

Ill have a play and see if i can come up with something.

There may be overlap in the Layout and the Builder, but generally the builder is responsible for creating / managing children and the layout is responsible positioning sizing them… thats the basic idea anyway.

Cheers,
Ian

Out of interest, what are you trying to do with the tabbarlayout?

I am working on a vertical tab bar. I can do a customized one from sketch but I also like to know if I can make it extends tab bar as it functions almost the same as original tab bar except the layout.

Right, so yeah, i think ill just have to make these layout classes public… its the most sensible thing to do

EDIT: ok, thats public now: class TabBarLayout extends DefaultLayout