I'd like to dc.drawText() a degree symbol in my app. How can I do that in Monkey C?
I've tried:
°C => nothing is printed
°C => literal "°C" is printed
\u00B0C => compiler error "Unknown string sequence"
Thanks
using Toybox.WatchUi as Ui;
using Toybox.Application as App;
using Toybox.System as Sys;
using Toybox.Graphics as Gfx;
class DataField extends Ui.DataField
{
var fonts;
var index;
//! Constructor
function initialize()
{
index = 0;
fonts = [
Gfx.FONT_LARGE,
Ui.loadResource(Rez.Fonts.id_font_arial_30),
Ui.loadResource(Rez.Fonts.id_font_blackdiamond),
Ui.loadResource(Rez.Fonts.id_font_tahoma_30),
Ui.loadResource(Rez.Fonts.id_font_veranda_30)
];
}
function compute(info)
{
}
//! Handle the update event
function onUpdate(dc)
{
if (index == 0) {
dc.setColor(Gfx.COLOR_WHITE, Gfx.COLOR_BLACK);
}
else {
dc.setColor(Gfx.COLOR_YELLOW, Gfx.COLOR_BLACK);
}
dc.clear();
var font = fonts[index];
index += 1;
index %= fonts.size();
var text = "01234";
var height = dc.getFontHeight(font);
var width = dc.getTextWidthInPixels(text, font);
var x = 4;
var y = 4;
// when rendering built-in fonts, the y coordinate is always the base
// of the text, so we have to add the text height to our offset
dc.drawText(x, y + height, font, text, Gfx.TEXT_JUSTIFY_LEFT);
// draw a rectangle where we expect the text to appear
dc.drawRectangle(x, y, width, height);
}
}