DataFields in app

Former Member
Former Member
I have a simple app I am trying to put together, to learn how this works. Want to display some data and trying different ways to achieve it.

The natural way, for simpel custom data, I guess is to create a number of SimpleDataFields and populate the apps view with those but I fail to find out how to.
Writing text to the screen I manage but using data fields elude me.

A simple app, three custom datafields.

Please, a simple guide, a simple how-to or, perhaps, should-to.
  • Former Member
    Former Member
    You can't use a SimpleDataField like that in an app, but you can create your own version of a simple data field. For that you create a class that extends drawable:

    using Toybox.WatchUi as Ui;

    class MySimpleDataFied extends Ui.Drawable
    {
    function initialize(options) {
    Ui.Drawable.initialize();
    .... // write initialization code. If you want to use the layout system, options must be a library. Use it to set the x and y position and the labeltext.
    //locX = options[:locX];
    //locY = options[:locY];
    }

    function compute(info) {
    // Use a compute or setValue function to calculate or set the value of your datafield
    }

    function draw(dc) {
    .... //write code to draw the data field
    }
    }


    Then all you have to do is make sure your app updates the value and draws your data field every second.
  • Former Member
    Former Member
    Thank you for the reply.

    Since I found no info not so ever on the subject, your reply was in line with what I expected.
    A shame you can't, that you have to re-invent the wheel once again, but not so hard to implement it the way you describe it.


    Yours
  • You don't necessarily need to make the data field as heavyweight as that. Typically all a data field would need to know is the value and the label. The value could be a fixed string, and the value could be retrieved by an overridden function or via a callback. Something like this should be sufficient.

    class DataField
    {
    function getLabel() {
    return null;
    }

    function getValue(info) {
    return null;
    }
    }

    class DistanceDataField extends DataField
    {
    function getLabel() {
    return "Distance";
    }

    function getValue(info) {
    return info.elapsedDistance.format("%d");
    }
    }
  • And for even a lower weight solution:

    dc.drawtext(x,y,font,"cals="+ActInfo.calories.toString(),justifcation)

    :)
  • Former Member
    Former Member
    And for even a lower weight solution:

    dc.drawtext(x,y,font,"cals="+ActInfo.calories.toString(),justifcation)

    :)


    This is more or less like the solution I have now :)
    A brute but simple solution..