Skip to content

Commit fe40a1d

Browse files
authored
Merge pull request #3916 from RKBoss6/modclk
[Modern Clock] Add inline clockInfo
2 parents 5bfb257 + f96bb55 commit fe40a1d

File tree

8 files changed

+61
-27
lines changed

8 files changed

+61
-27
lines changed

apps/modclock/ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
0.01: App created w/ clockInfos, bold font, date and time.
22
0.02: Added text truncation for long ClockInfo strings.
3+
0.03: Added small inline Clock Info next to date

apps/modclock/README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,20 @@
22

33

44

5-
A beautifully simple, modern clock with two Clock Infos, and a clean UI. Fast-Loads.
5+
A beautifully simple, modern clock with three Clock Infos, and a clean UI. Fast-Loads.
66

7-
![](Screenshot1.png)
7+
![](Scr1.png)
88

99

1010

1111
## Features
1212

13-
* Has 2 Clock Infos, that are individually changeable.
13+
* Has 3 Clock Infos, that are individually changeable.
14+
* Has an inline Clock Info, next to the date, for quick, glanceable data.
1415
* Low battery consumption.
1516
* Uses locale for time and date.
1617
* Bold time font, for quicker readability.
18+
* Uses rounded rectangles and a bold font for a simple, clean, modern look.
1719
* Has Fast Loading, for quicker access to launcher.
1820

1921

apps/modclock/Scr1.png

20.2 KB
Loading

apps/modclock/Scr2.png

19.7 KB
Loading

apps/modclock/Screenshot1.png

-20.3 KB
Binary file not shown.

apps/modclock/Screenshot2.png

-19.9 KB
Binary file not shown.

apps/modclock/app.js

Lines changed: 51 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ Graphics.prototype.setFontBold = function(scale) {
99
{ // must be inside our own scope here so that when we are unloaded everything disappears
1010
// we also define functions using 'let fn = function() {..}' for the same reason. function decls are global
1111
let drawTimeout;
12-
13-
let calcStrLength=function(str,limitLength){
12+
let showInlineClkInfo=true;
13+
let calcStrLength=function(str,maxLength){
1414

1515
//too long
1616

1717
// Example maximum length
1818
var truncatedText = str;
1919

20-
if (str.length > limitLength) {
21-
truncatedText = str.substring(0, limitLength - 3) + "...";
20+
if (str.length > maxLength) {
21+
truncatedText = str.substring(0, maxLength - 3) + "...";
2222
}
2323

2424
return truncatedText;
@@ -62,7 +62,6 @@ let bRoundedRectangle= function(x1,y1,x2,y2,r) {
6262
};
6363

6464

65-
6665
//CLOCK INFO
6766
let clockInfoItems = require("clock_info").load();
6867

@@ -84,7 +83,7 @@ let clockInfoMenuLeft = require("clock_info").addInteractive(clockInfoItems, {
8483
// indicate focus - we're using a border, but you could change color?
8584
if (options.focus){
8685
// show if focused
87-
g.setColor(0,15,255);
86+
g.setColor(0,255,15);
8887
bRoundedRectangle(options.x,options.y,options.x+options.w,options.y+options.h,8);
8988
}else{
9089
g.setColor(g.theme.fg);
@@ -117,7 +116,7 @@ let clockInfoMenuRight = require("clock_info").addInteractive(clockInfoItems, {
117116
// indicate focus - we're using a border, but you could change color?
118117
if (options.focus){
119118
// show if focused
120-
g.setColor(0,15,255);
119+
g.setColor(0,255,15);
121120
bRoundedRectangle(options.x,options.y,options.x+options.w,options.y+options.h,8);
122121
}else{
123122
g.setColor(g.theme.fg);
@@ -132,12 +131,39 @@ let clockInfoMenuRight = require("clock_info").addInteractive(clockInfoItems, {
132131
g.setFont("Vector",16).setFontAlign(0,1).drawString(calcStrLength(info.text,8), midx,midy+23); // draw the text
133132
}
134133
});
134+
let clockInfoMenuInline;
135+
136+
if(showInlineClkInfo){
137+
clockInfoMenuInline = require("clock_info").addInteractive(clockInfoItems, {
138+
// Add the dimensions we're rendering to here - these are used to detect taps on the clock info area
139+
x : g.getWidth()/2+6, y: 69, w: 95, h:25,
140+
// You can add other information here you want to be passed into 'options' in 'draw'
141+
// This function draws the info
142+
draw : (itm, info, options) => {
143+
// itm: the item containing name/hasRange/etc
144+
// info: data returned from itm.get() containing text/img/etc
145+
// options: options passed into addInteractive
146+
// Clear the background
147+
g.reset().clearRect(options.x, options.y, options.x+options.w, options.y+options.h);
148+
// indicate focus - we're using a border, but you could change color?
149+
if (options.focus){
150+
// show if focused
151+
g.setColor(0,255,15);
152+
153+
}
154+
// we're drawing center-aligned here
155+
//var midx = options.x+options.w/2;
156+
var midy=options.y+options.h/2;
157+
if (info.img){
158+
g.drawImage(info.img, options.x+4,midy-7.2,{scale: 0.63});
159+
}// draw the image
160+
g.setFont("Vector",15).setFontAlign(-1,0).drawString(calcStrLength(info.text,6), options.x+22,midy+1); // draw the text
161+
}
162+
});
163+
164+
}
135165

136166

137-
138-
139-
140-
141167

142168
// DRAW FACE
143169
let draw = function() {
@@ -150,7 +176,7 @@ let draw = function() {
150176
// draw the current time (4x size 7 segment)
151177

152178
// align bottom right
153-
179+
154180
g.setFontBold();
155181

156182
if(meridian!=""){
@@ -163,13 +189,13 @@ let draw = function() {
163189
var meridianStrWidth=g.stringWidth(meridian);
164190
var totalStrWidth=meridianStrWidth+padding+clkStrWidth;
165191
var startX = ((g.getWidth() - totalStrWidth) / 2)+6;
166-
g.clearRect(0,0,g.getWidth(),90);
192+
g.clearRect(0,0,g.getWidth(),64);
167193
g.setFontBold();
168194
g.setFontAlign(-1,1);
169-
g.drawString(clock, startX, Y+2,true);
195+
g.drawString(clock, startX, Y-2);
170196
g.setFont("Vector",20);
171197
g.setFontAlign(-1,1);
172-
g.drawString(meridian, startX + clkStrWidth + padding, Y-5, true);
198+
g.drawString(meridian, startX + clkStrWidth + padding, Y-9, true);
173199

174200
}else{
175201

@@ -179,15 +205,17 @@ let draw = function() {
179205

180206
}
181207

182-
183208
// draw the date, in a normal font
184-
g.setFont("Vector",18);
185-
g.setFontAlign(0,0); // align center bottom
209+
g.setFont("Vector",16);
210+
g.setFontAlign(1,0); // align center bottom
186211
// pad the date - this clears the background if the date were to change length
187-
var dateStr = require("locale").dow(new Date(), 1)+", "+ require("locale").month(new Date(), true)+" "+new Date().getDate();
188-
g.drawString(" "+dateStr+" ", g.getWidth()/2, Y+9, true /*clear background*/);
212+
var dateStr = require("locale").dow(new Date(), 1)+", " +new Date().getDate();
213+
//print(g.stringHeight(dateStr));
214+
g.drawString(" "+dateStr+" ", g.getWidth()/2+6, Y+9, true /*clear background*/);
189215

190216
Bangle.drawWidgets();
217+
g.setColor("#ffffff");
218+
191219

192220
// queue next draw
193221
if (drawTimeout) clearTimeout(drawTimeout);
@@ -210,11 +238,14 @@ Bangle.setUI({
210238
delete Graphics.prototype.setFontBold;
211239
clockInfoMenuRight.remove();
212240
clockInfoMenuLeft.remove();
241+
if(showInlineClkInfo) clockInfoMenuInline.remove();
213242

214243
}});
215244

216245
g.clear();
217246
// Load widgets
218247
Bangle.loadWidgets();
219248
draw();
249+
250+
220251
}

apps/modclock/metadata.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
"name": "Modern Clock",
44
"shortName":"Modern Clk",
55
"icon": "icon.png",
6-
"version":"0.02",
7-
"description": "A modern, simple clock, with two ClockInfos and Fast Loading",
6+
"version":"0.03",
7+
"description": "A modern, simple clock, with three ClockInfos and Fast Loading",
88
"type":"clock",
99
"tags": "clock,clkinfo",
1010
"supports": ["BANGLEJS2"],
11-
"screenshots" : [ { "url":"Screenshot1.png" },
12-
{ "url":"Screenshot2.png" } ],
11+
"screenshots" : [ { "url":"Scr1.png" },
12+
{ "url":"Scr2.png" } ],
1313
"dependencies" : { "clock_info":"module"},
1414
"allow_emulator":true,
1515
"readme":"README.md",

0 commit comments

Comments
 (0)