-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathComponent.mc
81 lines (70 loc) · 2.19 KB
/
Component.mc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using Toybox.WatchUi;
/**
* Base class for components. All components should extend from this class.
*/
class Component extends WatchUi.Drawable {
protected var xPercent = 0;
protected var yPercent = 0;
protected var screenDiameter = 0;
/**
* Loads the relative positioning that components should utilize.
*/
function initialize(params) {
Drawable.initialize(params);
xPercent = getParam(params, :xPercent, 0);
yPercent = getParam(params, :yPercent, 0);
}
/**
* Override this and return true if the component will support partial updates.
*/
function getDoesSupportPartialUpdate() {
return false;
}
/**
* When the layout is loaded, set the pixel position of the component based on the screen size.
*/
function onLayout(dc) {
screenDiameter = dc.getWidth();
locX = screenDiameter * xPercent / 100;
locY = screenDiameter * yPercent / 100;
}
/**
* Called when the app state is changed.
*/
function updateAppState(appState) {
}
/**
* Called when the settings are updated.
*/
function updateSettings(settings) {
printWarning("updateSettings(settings)");
}
/**
* Called when the watchface onUpdate occurs.
*/
function onUpdate(dc) {
printWarning("onUpdate(dc)");
}
/**
* Called when the watchface onPartialUpdate occurs for components that support partial updates.
*/
function onPartialUpdate(dc) {
printWarning("onPartialUpdate(dc)");
}
/**
* Helper function for loading parameters from the layout.
*/
protected function getParam(params, key, defaultValue) {
return params.hasKey(key) ? params[key] : defaultValue;
}
/**
* Helper function for printing a warning that a function hasn't been overriden
* when it is expected that the component will be required to do so.
*
* If a component does not need the function, override with an empty function to
* avoid the overhead of this warning being printed!
*/
private function printWarning(name) {
System.println("Warning: " + name + " not implemented!");
}
}