Device Width

Hi,

Is it possible to get the device's width from the initialize() function? I have tried Graphics.Dc.getHeight(), but I am getting the following error:

Could not find symbol mHeight.
Symbol Not Found Error
in getHeight (T:\mbsimulator\submodules\technology\monkeybrains\virtual-machine\api\Graphics.mb:434)

Thanks
  • Former Member
    Former Member
    You can get this information from Toybox.System.getDeviceSettings().screenWidth.

    The code you posted is looking at the base class definition of Dc, which would not have any data. The data in the Dc object is only valid when the system has created the object and properly initialized the members, which is done when this object is passed to View.onUpdate() and other such methods.
  • Thanks Brian! Exactly what I was looking for!
  • I generally just do width=dc.getWith() in onLayout (same with dc.getHeight()), and then set what I need for the display there.

    One thing with getting the height, Toybox.System.getDeviceSettings().screenHeight on non-wearables with a screen based button bar, it's the height of the screen, and not the dc, and therefore includes the area covered by the button bar.