lightswitch: masking (espruino/Espruino#2151) + oversize

Update ChangeLog and metadata.json
Update README.md and settings.json
 - add oversize setting + description
Update settings.js
- add oversize setting
Update widget.js
 - add oversize setting
 - add masking touch and drag input by adding own event listeners first and messing up the handler on a widget related event, using espruino/Espruino#2151
master
storm64 2022-04-06 22:29:13 +02:00
parent 6557dd70e3
commit a2002c4841
6 changed files with 44 additions and 15 deletions

View File

@ -1,3 +1,4 @@
0.01: New App! 0.01: New App!
0.02: Add the option to enable touching the widget only on clock and settings. 0.02: Add the option to enable touching the widget only on clock and settings.
0.03: Settings page now uses built-in min/max/wrap (fix #1607) 0.03: Settings page now uses built-in min/max/wrap (fix #1607)
0.04: Add masking widget input to other apps (using espruino/Espruino#2151), add a oversize option to increase the touch area.

View File

@ -1,8 +1,11 @@
# Light Switch Widget # Light Switch Widget
Whis this widget I wanted to create a solution to quickly en-/disable the LCD backlight and even change the brightness. With this widget I wanted to create a solution to quickly en-/disable the LCD backlight and even change the brightness.
In addition it shows the lock status with the option to personalize the lock icon with a tiny image. In addition it shows the lock status with the option to personalize the lock icon with a tiny image.
All touch and drag inputs related to this widget are cached/masked to prevent actions in the active app.
(See [espruino/Espruino#2151](https://github.com/espruino/Espruino/issues/2151) for more information.)
--- ---
### Control ### Control
--- ---
@ -39,6 +42,9 @@ In addition it shows the lock status with the option to personalize the lock ico
* _clk+launch_ -> on all apps of the types _clock_ and _launch_ * _clk+launch_ -> on all apps of the types _clock_ and _launch_
* _except apps_ -> on all apps of the types _clock_ and _launch_ and in the settings * _except apps_ -> on all apps of the types _clock_ and _launch_ and in the settings
* _always on_ -> always enabled when the widget is displayed * _always on_ -> always enabled when the widget is displayed
* __Oversize__
_0px_ / _1px_ / _..._ / __20px__ / _..._ / _50px_
To make it easier to hit the widget, this value extends the touch area of the widget in all directions.
* __Drag Delay__ * __Drag Delay__
_off_ / _50ms_ / _100ms_ / _..._ / __500ms__ / _..._ / _1000ms_ _off_ / _50ms_ / _100ms_ / _..._ / __500ms__ / _..._ / _1000ms_
Change the maximum delay between first touch and re-touch/drag to change the brightness or disable changing the brightness completely. Change the maximum delay between first touch and re-touch/drag to change the brightness or disable changing the brightness completely.
@ -85,8 +91,6 @@ This images are stored in a seperate file _(lightswitch.images.json)_.
### Worth Mentioning ### Worth Mentioning
--- ---
#### To do list #### To do list
* Catch the touch and draw input related to this widget to prevent actions in the active app.
_(For now I have no idea how to achieve this, help is appreciated)_
* Manage images for the lock icon through a _Customize and Upload App_ page. * Manage images for the lock icon through a _Customize and Upload App_ page.
#### Requests, Bugs and Feedback #### Requests, Bugs and Feedback

View File

@ -2,7 +2,7 @@
"id": "lightswitch", "id": "lightswitch",
"name": "Light Switch Widget", "name": "Light Switch Widget",
"shortName": "Light Switch", "shortName": "Light Switch",
"version": "0.03", "version": "0.04",
"description": "A fast way to switch LCD backlight on/off, change the brightness and show the lock status. All in one widget.", "description": "A fast way to switch LCD backlight on/off, change the brightness and show the lock status. All in one widget.",
"icon": "images/app.png", "icon": "images/app.png",
"screenshots": [ "screenshots": [

View File

@ -7,6 +7,7 @@
colors: "011", colors: "011",
image: "default", image: "default",
touchOn: "clock,launch", touchOn: "clock,launch",
oversize: 20,
dragDelay: 500, dragDelay: 500,
minValue: 0.1, minValue: 0.1,
unlockSide: "", unlockSide: "",
@ -45,7 +46,7 @@
return { return {
value: entry.value.indexOf(settings[key]), value: entry.value.indexOf(settings[key]),
min : 0, min : 0,
max : entry.value.length-1, max : entry.value.length - 1,
wrap : true, wrap : true,
format: v => entry.title ? entry.title[v] : entry.value[v], format: v => entry.title ? entry.title[v] : entry.value[v],
onchange: function(v) { onchange: function(v) {
@ -57,11 +58,11 @@
// return entry for numerical value // return entry for numerical value
return { return {
value: settings[key] * entry.factor, value: settings[key] * entry.factor,
step: entry.step,
format: v => v > 0 ? v + entry.unit : "off",
min : entry.min, min : entry.min,
max : entry.max, max : entry.max,
step: entry.step,
wrap : true, wrap : true,
format: v => v > 0 ? v + entry.unit : "off",
onchange: function(v) { onchange: function(v) {
writeSetting(key, v / entry.factor, entry.drawWidgets); writeSetting(key, v / entry.factor, entry.drawWidgets);
}, },
@ -96,6 +97,14 @@
value: ["", "clock", "clock,setting.app.js", "clock,launch", "clock,setting.app.js,launch", "always"], value: ["", "clock", "clock,setting.app.js", "clock,launch", "clock,setting.app.js,launch", "always"],
drawWidgets: true drawWidgets: true
}, },
oversize: {
factor: 1,
unit: "px",
min: 0,
max: 50,
step: 1,
drawWidgets: true
},
dragDelay: { dragDelay: {
factor: 1, factor: 1,
unit: "ms", unit: "ms",
@ -142,6 +151,7 @@
"Image": getEntry("image"), "Image": getEntry("image"),
"-- Control": 0, "-- Control": 0,
"Touch": getEntry("touchOn"), "Touch": getEntry("touchOn"),
"Oversize": getEntry("oversize"),
"Drag Delay": getEntry("dragDelay"), "Drag Delay": getEntry("dragDelay"),
"Min Value": getEntry("minValue"), "Min Value": getEntry("minValue"),
"-- Unlock": 0, "-- Unlock": 0,

View File

@ -10,8 +10,8 @@
"101" -> magenta "101" -> magenta
* image: string // * image: string //
"default" -> "default" -> image nearest to the default lock
"random" -> "random" -> a random image from all available
* touchOn: string // select when widget touch is active * touchOn: string // select when widget touch is active
"" -> only on default clock "" -> only on default clock
@ -19,6 +19,9 @@
"clock,launch" -> on all clocks and lanchers (default) "clock,launch" -> on all clocks and lanchers (default)
"always" -> always "always" -> always
* oversize: int // extends the touch area of the widget in px in all directions
0 to 50, 20 as default
* dragDelay: int // drag listener reset time in ms * dragDelay: int // drag listener reset time in ms
// time until a drag is needed to activate backlight changing mode // time until a drag is needed to activate backlight changing mode
0 -> disabled 0 -> disabled
@ -59,6 +62,7 @@
"colors": "011", "colors": "011",
"image": "default", "image": "default",
"touchOn": "clock,launch", "touchOn": "clock,launch",
"oversize": 20,
"dragDelay": 500, "dragDelay": 500,
"minValue": 0.1, "minValue": 0.1,
"unlockSide": "", "unlockSide": "",

View File

@ -4,6 +4,7 @@
colors: "011", colors: "011",
image: "default", image: "default",
touchOn: "clock,launch", touchOn: "clock,launch",
oversize: 20,
dragDelay: 500, dragDelay: 500,
minValue: 0.1, minValue: 0.1,
unlockSide: "", unlockSide: "",
@ -162,6 +163,11 @@
// change brigthness value, skip write to storage while still touching // change brigthness value, skip write to storage while still touching
w.changeValue(value, event.b); w.changeValue(value, event.b);
// masks this drag event by messing up the event handler
// see https://github.com/espruino/Espruino/issues/2151
Bangle.removeListener("drag", w.dragListener);
Bangle["#ondrag"] = [w.dragListener].concat(Bangle["#ondrag"]);
// on touch release remove drag listener and reset drag status to indicate stopped drag action // on touch release remove drag listener and reset drag status to indicate stopped drag action
if (!event.b) { if (!event.b) {
Bangle.removeListener("drag", w.dragListener); Bangle.removeListener("drag", w.dragListener);
@ -184,14 +190,14 @@
if (w.dragStatus === "off") { if (w.dragStatus === "off") {
// check if inside widget area // check if inside widget area
if (!(!w || cursor.x < w.x || cursor.x > w.x + w.width || if (!(!w || cursor.x < w.x - w.oversize || cursor.x > w.x + w.width + w.oversize ||
cursor.y < w.y || cursor.y > w.y + 23)) { cursor.y < w.y - w.oversize || cursor.y > w.y + 23 + w.oversize)) {
// first touch feedback // first touch feedback
Bangle.buzz(25); Bangle.buzz(25);
// check if drag is disabled // check if drag is disabled
if (w.dragDelay) { if (w.dragDelay) {
// add drag listener // add drag listener at first position
Bangle.on("drag", w.dragListener); Bangle["#ondrag"] = [w.dragListener].concat(Bangle["#ondrag"]);
// set drag timeout // set drag timeout
w.dragStatus = setTimeout((w) => { w.dragStatus = setTimeout((w) => {
// remove drag listener // remove drag listener
@ -204,6 +210,10 @@
} }
// switch backlight // switch backlight
w.changeValue(); w.changeValue();
// masks this touch event by messing up the event handler
// see https://github.com/espruino/Espruino/issues/2151
Bangle.removeListener("touch", w.touchListener);
Bangle["#ontouch"] = [w.touchListener].concat(Bangle["#ontouch"]);
} }
} }
@ -236,11 +246,11 @@
// add lock listener // add lock listener
Bangle.on("lock", w.draw); Bangle.on("lock", w.draw);
// add touch listener to control the light depending on settings // add touch listener to control the light depending on settings at first position
if (w.touchOn === "always" || !global.__FILE__ || if (w.touchOn === "always" || !global.__FILE__ ||
w.touchOn.includes(__FILE__) || w.touchOn.includes(__FILE__) ||
w.touchOn.includes(require("Storage").readJSON(__FILE__.replace("app.js", "info")).type)) w.touchOn.includes(require("Storage").readJSON(__FILE__.replace("app.js", "info")).type))
Bangle.on("touch", w.touchListener); Bangle["#ontouch"] = [w.touchListener].concat(Bangle["#ontouch"]);
// add tap listener to unlock and/or flash backlight // add tap listener to unlock and/or flash backlight
if (w.unlockSide || w.tapSide) Bangle.on("tap", require("lightswitch.js").tapListener); if (w.unlockSide || w.tapSide) Bangle.on("tap", require("lightswitch.js").tapListener);