Hello,
I would like to create my own UIElement inherited from Button, but when I try to do that I can not properly set the Style (XML style). It still remains white. I also tried to copy paste the whole Button code into my class (I just replaced the word Button with name MyElement) but it didnt work. Can someone please help me with this ?
BTW the code I used for testing MyElement should be correct because when I replace the word MyElement with the word Button, everything works ok.
Most probably thatâs because you have not created your own âstylesheetâ that defines the auto style of your new UI-element class. Either that or you can just modify the existing âDefaultStyle.xmlâ stylesheet to define your new UI-element auto style. Alternatively, donât use SetStyleAuto() or any APIs that rely on it, instead set ALL the attributes of your new UI-element instance explicitly from scratch. The latter is not recommended if you have many of such instances.
I tried it using the first method by adding MyWidget to the DefaultStyle.xml but it does not work. I still get white widget. I also tried assigning working styles to it like widget->SetStyle(âButtonâ). I really dont know whats wrong with it.
I tried it using the first method by adding MyWidget to the DefaultStyle.xml but it does not work. I still get white widget. I also tried assigning working styles to it like widget->SetStyle(âButtonâ). I really dont know whats wrong with it.[/quote]
I would like to create my own UIElement inherited from Button, but when I try to do that I can not properly set the Style (XML style). It still remains white
( disclaimer: this is all assumed on my part as I havenât worked with any uielements so far ) I donât know if this helps as I havenât worked with uielements yet but just on initial looking around in the DefaultStyle.xml I noticed two parameters for every âtypeâ and âstyleâ. It appears as though âtypeâ is the custom name for your and can be Any name you want it to be. Whereas âstyleâ if present represents the âtypeâ of another that you want âyourâ to inherit from. if that has itâs own âstyleâ parameter then that element will inherit from the other âstyleâ parameter it has and so on⌠if there is no âstyleâ parameter then your will not inherit from any other
If that all holds true then I would assume you can fix your by adding this to itâs tag
style="Button"
or
style="ButtonImage"
or you could just add this to the very begining of your DefaultStyle.xml file:
[code]
[/code]
Note that I just copied the attributes from the âButtonâ attributes like weitjong suggested for your new uielement âempirer64CustomUIelementâ.
Also note that I typed all that in by hand so hopefully there arenât any typos
Note that if you want to create a new uielement that would inherit from âempirer64CustomUIelementâ then you would have that new 's style attribute say:
Well, it is hard for me to say whether it is correct or not for the OP because I donât know the reason why he opts to subclass the Button class in the first place. We donât need to subclass the UI-Element if all we want is just a different styling. But otherwise, yes, I think you get the general idea.
I want to create my own Button because I want to add text there. And yes I tried creating my own style in the defaultStyle.xml, I copied the Button Style and just renamed it to MyWidget, so I have there also the elements from which it should inherit the style. And MyWidget is just copied Button code with changed name from Button to MyWidget.
Using hierarchical composition would also be possible and actually used all over the Editor and other examples, ie. you create a Button and add a Text as a child element. When the child element has SetEnabled(false) (this is default for Text) it wonât interfere with button press input.