How to use exetnded Ui.Drawable class

I came across such a problem: I want to use the justification of label defined in the <layout>. So I've created my own class TextEx. How can I take advantage of my class in the layout like in example?

class TextEx extends Ui.Text
{
...
}

<layout ...>
<label class="TextEx" id="1" ... />
<label class="TextEx" id="2" ... />
</layout>



I must say that I do not like the solution in the style:
class ExtraSuper1 extends TextEx
{
function initialize ()
{
// All setting I will normally set in resources
...
}
}

class ExtraSuper2 extends TextEx
{
function initialize ()
{
// All setting I will normally set in resources
...
}
}

<layout ...>
<drawable class="ExtraSuper1" />
<drawable class="ExtraSuper2" />
</layout>



It looks like (undocumented in drawable) 'class' attribute has been omitted in 'label' element, which after all is drawable too.

Peter
  • Former Member
    Former Member over 9 years ago
    There is a lack of documentation for this and I've created a Jira to add some.

    In the 1.2.0 release we added the ability to include a custom Drawable object within a layout (the "class" attribute). You can pass parameters to the initialize function from the layout by adding <param> children to the <drawable> tag.

    <layout>
    <drawable class="MyDrawable">
    <param name="param1">a valid symbol within MyDrawable</param>
    <param name="string1">@Strings.MyString</param>
    </drawable>
    </layout>


    These values can then be used withing MyDrawable.

    class MyDrawable extends Ui.Drawable {
    var mParam1, mString1;

    function initialize(params) {
    mParam1 = params.get(:param1);
    mString1 = params.get(:string1);
    }
    }


    There are a few issues which have come up internally during testing. The biggest being if you use the "class" attribute you can't use any of the other attributes ("width", "height", etc) which are standard to <drawable> to define parameters. I'll add a note that sub classes of Drawable cannot define a "class" attribute so it will come up in discussion.
  • Thank you Ken,
    Sounds very good.

    Peter