WatchUi.Text doesn't seem to have protected instance attributes?

Former Member
Former Member
Last night, I was trying to extend the Text class, but I couldn't find any way to get the text and font in the Text base-class.

Here is a simplified example of what I was trying to do: [FONT=courier new]class UnderlineText extends WatchUi.Text
{[/FONT]
[INDENT=2][FONT=courier new]function draw(dc)
{
// fields text and font should be inherited from class Text
// and accessible as protected instance attributes
var dims = dc.getTextDimensions( text, font );

// Draw an Underline below the text.
dc.drawLine( locX, locY + dims[1], locX + dims[0], locY + dims[1]);
// locX and locY are available from the base-class.
// text and font (and maybe justification) should be as well.

}[/FONT][/INDENT]
[FONT=courier new]}[/FONT]




Basically, without access to the text and font attributes, its difficult to measure the text.
Eventually, my class ended up keeping a separate text and font variable, and trying hard to keep them synchronized with the base-class in all cases.
But I shouldn't need to jump through that in a language that has inheritance.

Its already clear that the Drawable-attributes locX, locY, width and height are inherited and accessible.
(although they seem to be "public", and I think text & font only need to be "protected")
  • These should be documented or we should provide accessors. They are there, just not visible without a little sleuthing. If you open up $SDKROOT/bin/api.debug.xml and look for Toybox_WatchUi_Text, you'll find the following entries..

    <protectedSymbolEntry class="Toybox_WatchUi_Text" symbol="mText" xtendsClass="!Toybox!Toybox_WatchUi!Toybox_WatchUi_Drawable"/>
    <protectedSymbolEntry class="Toybox_WatchUi_Text" symbol="mFont" xtendsClass="!Toybox!Toybox_WatchUi!Toybox_WatchUi_Drawable"/>
    <protectedSymbolEntry class="Toybox_WatchUi_Text" symbol="mJustification" xtendsClass="!Toybox!Toybox_WatchUi!Toybox_WatchUi_Drawable"/>
    <protectedSymbolEntry class="Toybox_WatchUi_Text" symbol="mColor" xtendsClass="!Toybox!Toybox_WatchUi!Toybox_WatchUi_Drawable"/>
    <protectedSymbolEntry class="Toybox_WatchUi_Text" symbol="mBackgroundColor" xtendsClass="!Toybox!Toybox_WatchUi!Toybox_WatchUi_Drawable"/>
  • Former Member
    Former Member
    That is awesome Travis.ConnectIQ ! Thank you very much.

    I will try that tonight, and if it works, it will save me a lot of effort!
  • I've filed a bug to consider adding documentation for these protected members or add public accessors for them.