Coding a round progress bar

Hi,

I want to design a new watchface and did some research in the app store first regarding the layout. I have seen a lot of watchfaces with a round progress bar, some of the progress bars are even interrupted in severeal segments.

In the API I can only find the class progress bar which has a very limited number of attributes and not intended to be shown rounded. Furthermore I can find very basic elements like drawCircle() and drawEllipse() but with those elements I have to code the progress completely new - futhermore I can't split the bar in several segments and would have to interrupt the bar by overlaying a line.

Is there another method which is more convenient? Do you have a code snippet?

Thanks for your help.
  • I use drawArc() in this watchface: https://apps.garmin.com/en-US/apps/b7ec043e-c144-4260-b2d0-a5b911dadddb

    Here's the basics of how I draw an arc from the 12 o'clock position to the current hour. (12 o'clock is "top" and is 90 degrees in the arc, 3 o'clock is 0 degrees, pen is how wide the arc is, hour is the current hour, and hours is the degrees for the hour relative to top and rLocal is the radius.. If it's 9 o'clock, this will draw a clockwise arc from 12 to 9.

    var hour=((clockTime.hour%12)*60.0+clockTime.min)/60.0; //include a decimal component for minutes
    var top=90;
    dc.setPenWidth(pen);
    rLocal=width/2-10;
    var hours=top+(360-(hour*30));
    if(hours>360) {hours=hours-360;}
    dc.drawArc(x, y, rLocal, Gfx.ARC_CLOCKWISE , top,hours);

    In this case each hour is 30 degrees (I only do 12 hr time here), so if you wanted to do something like 0-100%, change the "hour*30" to something like "percent*3.6".

    As far as the breaks, you can draw the full arc and then overlay a line where you want a break, or draw separate arcs, with a with a small gap (a couple of degrees) between each one.
  • Jim,

    could you please review this code snippet? The simulator shows no problems with this snippet, but on the real watch I get an IQ error.

    in compute(info):
    var bat = Sys.getSystemStats().battery;
    batteryField = (120 - 60 * bat/100).toNumber();


    in onUpdate():

    dc.setPenWidth(3);
    dc.setColor(Gfx.COLOR_DK_GRAY, Gfx.COLOR_TRANSPARENT);
    dc.drawArc(109, 109, 109, Gfx.ARC_COUNTER_CLOCKWISE, 60, 120);
    dc.setColor(batteryColor, Gfx.COLOR_TRANSPARENT);
    //dc.drawArc(109, 109, 109, Gfx.ARC_COUNTER_CLOCKWISE, batteryField, 120);
    dc.setPenWidth(1);


    The commented red line makes the problems: without this line: no problem, if I include this line I get on the physical device an IQ-Error. The IQ-Error shows:

    ERROR: Unhandled Exception
    DETAILS: Failed invoking <symbol>
    STORE_ID: 460161941fdf4f9bae8b16ceba51a548
    CALLSTACK:

    WARNING: Unfreed memory on exit
    STORE_ID: 460161941fdf4f9bae8b16ceba51a548


    I currently have the version online with this line commented so that the user can use the datafield anyway.

    Thanks for your help.
  • OK, got it: I missed to define the field in the constructor :-(
  • How did you do this? I have the same problem..

  • Are you looking for the basics, or have you run into a specific problem?