-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
GeneratorRecentResultView.mc
114 lines (99 loc) · 3.65 KB
/
GeneratorRecentResultView.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
using Toybox.WatchUi as Ui;
using Toybox.Graphics as Gfx;
using Generator as Gen;
using Mathx;
class GeneratorRecentResultView extends SlidableView {
private const RESULT_FONT = Gfx.FONT_TINY;
private var resultHeight;
private var currentResult;
function initialize(params as Dictionary) {
var horizontalBias = params.get(:horizontalBias);
var verticalBias = params.get(:verticalBias);
var width = System.getDeviceSettings().screenWidth;
var height = System.getDeviceSettings().screenHeight;
SlidableView.initialize(
params.get(:identifier),
width * horizontalBias,
height * verticalBias
);
resultHeight = Gfx.getFontHeight(RESULT_FONT);
}
function pushRecentResult(result as GeneratorResult) {
if (currentResult != null && currentResult.equals(result)) {
return;
}
currentResult = result;
if (result != null) {
var resultText = new Ui.Text(
{
:text => result.data,
:font => RESULT_FONT,
:justification => Gfx.TEXT_JUSTIFY_CENTER,
:height => resultHeight
}
);
var recentResult = new RecentResultDrawable();
recentResult.setup(resultText, resolveIndicator(result.type));
pushDrawable(recentResult, SlidableView.SLIDE_DOWN);
} else {
pushDrawable(null, SlidableView.SLIDE_DOWN);
}
}
private function resolveIndicator(generatorMode as Gen.GeneratorType) {
var resource;
switch (generatorMode) {
case Gen.GENERATOR_NUM:
resource = Rez.Drawables.ic_num;
break;
case Gen.GENERATOR_RANGE:
resource = Rez.Drawables.ic_range;
break;
case Gen.GENERATOR_NUM_FIXED:
resource = Rez.Drawables.ic_num_fixed;
break;
case Gen.GENERATOR_ALPHANUM:
resource = Rez.Drawables.ic_alphanum;
break;
case Gen.GENARATOR_HEX:
resource = Rez.Drawables.ic_hex;
break;
default:
resource = Rez.Drawables.ic_unknown;
}
return Application.loadResource(resource);
}
class RecentResultDrawable extends Ui.Drawable {
private var resultType as Drawable = null;
private var resultText as Drawable = null;
private var hSpacing = 7;
private var padding = 5;
private var headlineHeight;
function initialize() {
Drawable.initialize({});
}
function draw(dc) {
resultText.setLocation(
me.locX + (resultType.getWidth() / 2f) + (hSpacing / 2f),
getHeadlineLocY(resultText.height)
);
resultText.draw(dc);
dc.drawBitmap(
resultText.locX - resultType.getWidth() - (resultText.width / 2f) - hSpacing,
getHeadlineLocY(resultType.getHeight()),
resultType
);
}
private function getHeadlineLocY(baseHeight) {
return me.locY + ((headlineHeight - baseHeight) / 2f) + padding;
}
function setColor(color) {
resultText.setColor(color);
}
function setup(text as Drawable, icon as Ui.BitmapResource) {
resultText = text;
resultType = icon;
headlineHeight = Mathx.max(resultText.height, icon.getHeight());
setSize(width, headlineHeight + (padding * 2));
}
}
}