onPartialUpdate(): drawText does not erase previous value of the clip area. (Fenix 5)

onPartialUpdate() is called every second.
Between the calls, there is no dc.clearClip or dc.clear in my code, as it is in onUpdate which is called only every minute.

Flow:
First "99" is written with drawText(), the second after "--" is written.
At this point in time you can see "--" with a rest of the previos "9" on the reight side of the "clip".
(same would be, if a write nothing "" to the clip, I would see the old value!(?)

Do I have to erase the clipped region before I write to it?
How can I set "Background" color to the clip? (dc.drawRectangle(x-10, y-10, 20, 20); ??) but with what color?
(

function onPartialUpdate( dc )
{
var textAsString = getText();
dc.setClip(212, 100, 40, 50);
dc.drawText(212, 100, Gfx.FONT_SYSTEM_MEDIUM, textAsString, Gfx.TEXT_JUSTIFY_LEFT);


  • What I do is this. I set the width to the clip region to be the max width of the value. (I save off dc.getWidthInPixels for a string like "8888" for the font in onLayout. I also use dc.getFontHeight() for the height of the clip region).

    After you set the clip region, you can use dc.clear() with the background color, as that will clear the clip region, or you try using setColor with the foreground and background colors. I tend to do the dc.clear() myself.

    In onPartialUpdate() you'll likely want to set the colors, as otherwise, the last color you set in onUpdate() will be used. If you don't do the clear and use COLOR_TRANSPARENT for the background, what was there before will show though what you are writing.
  • Oh, a trick I use when sizing the clip region, is before I do the dc.clear(), I set the colors to be different than the background and foreground, and in the sim, it's really easy to see your clip region in case you need to do a bit of resizing.