noob: drawing vertical text

Can someone help me figure out how to draw vertical text like the "mi" does on the existing speed data field?
  • I'm assuming you're talking about a complex DF.

    Using the proper justification, it could be as simple as using "m\ni" (the \n is a new line). You could also just display the "m" and "i" on different "y's" too.
  • Some of the built-in data fields in the Edge product line display the unit by vertically stacking the unit values next to the value, like this...

    ____ _ ____
    | ___| / | |___ \ m
    |___ \ | | __) | /
    ___) | _ | | / __/ h
    |____/ (_) |_| |_____|


    Devices in the Forerunner, Vivoactive, and Fenix line don't do this. If you still want to do it, you must draw each of the letters for the units to the right of the value. I can provide some code later to do this.

    Travis
  • Actually, it may make sense to use the layout system to do this. With the edge devices you have enough memory available to do this without too much trouble.
  • Yes Travis your ascii representation is exactly what I'm trying to emulate. Basically trying to emulate the built-in speed field. the "newline" char I don't think would work here as it would not keep a large font on the number value. The docs aren't super helpful on how I might use the layout system for this so if you've got some sample that would help thanks!
  • There are sample programs that show how to use layouts. The Layout sample would be a good place to start.

    Personally, I'd just use a layout until I couldn't do it because of memory constraints. This is by far the easiest to get right and to tweak, but you pay in terms of memory use. Once I ran into memory issues, I'd try to programmatically create a layout (a list of Ui.Text in this case), and I'd place each drawable once in onLayout(). I would avoid re-calculating the text position on every onUpdate() call as it is unnecessary.

    If you are going to do this without layouts, you need to make one dc.drawText() call to draw the text, and then at least one more dc.drawText() call to draw the units. If you do that, when you do the draw for the units, you could use the \n trick.

    Travis
  • How about


    function drawVerticalText(dc, x, y, font, text) {
    for (var i = 0; i < text.length(); i++) {
    dc.drawText( x, y + (i*12), font, text.substring(i, i+1), CENTER);
    }
    }

    from https://gitlab.com/nz_brian/HiVisRunField/blob/master/source/HiVisRunField.mc
  • Instead of i*12, you'd probably want to do something like

    var fontH=dc.getFontHeight(font);

    outside the loop, and then use

    i*fontH

    instead, so the spacing is based on the font itself.

    And Gfx.TEXT_JUSTIFY_CENTER instead of CENTER