getFontHeight deprecated or no longer supported?

I was trying to use the newer SDKs to compile a watch face and found out Graphics.DC.getFontHeight no longer works. I get this error message:

Cannot find symbol ':getFontHeight' on class definition '$.Toybox.Graphics.Dc'.

Does anyone have any good work arounds? I am going to dig more into this later probably.

Thanks.

  • I was using Graphics.Dc.getFontHeight() before, But you're right you can use Graphics.getFontHeight().

    Also to note Graphics.Dc.getFontHeight() was working in some SDKs before versions 6.*

    Thanks.

  • Graphics.Dc.getFontHeight() is still in the docs for sure (with no deprecation notice), so something is wrong there. Maybe worth filing a bug report, if only to get the docs fixed.

  • I use dc.getFontHeight() in pretty much every one of my apps. but only in a function that is passed the dc. like onLayout() or onUpdate().  Not sure why you'd use Graphics.Dc.  Just use dc.

  • Oh, were you literally using Graphics.Dc.getFontHeight() as opposed to dc.getFontHeight() (where dc is an instance of Graphics.Dc)?

    That would explain it. Technically the former usage is incorrect (as getFontHeight() is a class instance method as opposed to a static method), but IIRC prior to type checking, that kind of incorrect usage would've worked as long as it was a function which doesn't access anything in the class instance (which is probably the case for getFontHeight().)

    I take back what I said about filing a bug report.

    The reason you're getting an error now is because the type checker is able to detect that kind of invalid usage at compile-time.

    Not sure why you'd use Graphics.Dc.  Just use dc.

    Maybe because it (incorrectly) worked before, plus the docs are unclear and lack examples? This isn't the first time that kind of error has been mentioned in the forums since type checking was introduced.

    Not sure why you have to talk down to people. Just give a straightforward non-judgmental answer.

    The problem I saw with the docs is that methods under a module are referred to as "instance methods", the same way that instance methods under a class are documented, but the usage is completely different. Obviously when you're dealing with a module, you don't have an "instance" in the same way that you have an "instance" of a class.

    i.e. Graphics is a module, so any methods documented under the "Instance Method Summary/Details" can be called with a reference to the Graphics module.

    e.g.

    Graphics.getFontHeight();

    OTOH, Graphics.Dc is a class, so any non-static methods documented under the "Instance Method Summary/Details" require an object that is an instance of the class, not a direct reference to the class.

    e.g.

    Does not work:

    Graphics.Dc.getFontHeight(); // Graphics.Dc is not an *instance* of the Graphics.Dc class

    Does work:

    function onUpdate(dc as Graphics.Dc) {
      var fontHeight = dc.getFontHeight(); // dc is an instance of Graphics.Dc
    }

    If I were writing the docs, I would at least get rid of the word "Instance" for methods that exist under a module.