Skip to content

Commit

Permalink
feat(date): Add date
Browse files Browse the repository at this point in the history
  • Loading branch information
Antti Viitala authored and Antvirf committed Oct 6, 2022
1 parent b06bb10 commit 3b248a4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions resources/layouts/layout.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<layout id="WatchFace">
<drawable class="Background" />
<label id="TimeLabel" x="center" y="center" font="Graphics.FONT_SYSTEM_NUMBER_THAI_HOT" justification="Graphics.TEXT_JUSTIFY_CENTER"/>
<label id="DateLabel" x="center" y="20%" font="Graphics.FONT_TINY" justification="Graphics.TEXT_JUSTIFY_CENTER"/>
</layout>
18 changes: 13 additions & 5 deletions source/mattermetricsView.mc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Toybox.Graphics;
import Toybox.Lang;
import Toybox.System;
import Toybox.WatchUi;
import Toybox.Time.Gregorian;

class mattermetricsView extends WatchUi.WatchFace {

Expand Down Expand Up @@ -37,14 +38,21 @@ class mattermetricsView extends WatchUi.WatchFace {
hours = hours.format("%02d");
}
}

// Draw and update time and date
var timeString = Lang.format(timeFormat, [hours, clockTime.min.format("%02d")]);
var timeView = View.findDrawableById("TimeLabel") as Text;
timeView.setColor(getApp().getProperty("ForegroundColor") as Number);
timeView.setText(timeString);

// Update the view
var view = View.findDrawableById("TimeLabel") as Text;
view.setColor(getApp().getProperty("ForegroundColor") as Number);
view.setText(timeString);
// Draw date
var info = Gregorian.info(Time.now(), Time.FORMAT_SHORT);
var dateString = Lang.format("$1$-$2$", [info.day, info.month]);
var dateView = View.findDrawableById("DateLabel") as Text;
dateView.setColor(getApp().getProperty("ForegroundColor") as Number);
dateView.setText(dateString);

// Call the parent onUpdate function to redraw the layout
// Call the parent onUpdate function to redraw the layout level
View.onUpdate(dc);
}

Expand Down

0 comments on commit 3b248a4

Please sign in to comment.