-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[widclkinfo] Ensure we cancel focus when widget_utils.swipeOn() pushes widget bar off screen #3680
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
cbkerr
wants to merge
25
commits into
espruino:master
Choose a base branch
from
cbkerr:widclkinfo-swipeOn-aware
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
0ab04e4
clock_info: Expose internal blur function as force_blur
e86fca8
widget_utils: Add shown and hidden events
e985056
widclkinfo: work in progress: Be aware of widget_utils.swipeOn
413b33f
Suggestions from review: emit events from Bangle and moving force_blu…
9bd9344
Also emit event when autohiding
b5ffb5a
Listen for widget events from Bangle
3a0de90
widget_utils: Emit shown and hidden events on show and hide functions
40059b7
widclkinfo: Remove references to widget_utils
b44fc18
widclkinfo: cleanup event listeners
4584330
widclkinfo: move draw function definition.
de845be
widclkinfo: Don't redraw widget if its clock_info is off screen
72a6b1d
widclkinfo: balance brackets
ba5d98a
widclkinfo: Make clockInfoMenu part of the widget
302e48b
widget_utils: Move events to anim function
86e6f86
widget_utils: format indentation
b99bc3e
clock_info: Use ensure_blur as public function in options
f1b8749
widclkinfo: update version and changelog
dd5fcd4
clock_info: update changelog
c7d7c8b
clock_info: bump version
89fb705
Remove test code comment
dbdf1a5
Note possible off by one error in detecting taps on clock_info
2c16883
widget_utils: Work to fix logic error in animation state handling
403ee4e
widclkinfo: Remove debug line
1358c99
widget_utils: fix missing bracket
71a98ac
widget_utils: Fix ambiguous if else
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
0.01: New Widget! | ||
0.02: Now use an app ID (to avoid conflicts with clocks that also use ClockInfo) | ||
0.03: Fix widget clearing too far down | ||
0.04: If a small font is needed, use 6x8 but twice as high | ||
0.04: If a small font is needed, use 6x8 but twice as high | ||
0.05: Defocus the clock_info if widget_utils is used to move widgets off screen |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,93 @@ | ||
if (!require("clock_info").loadCount) { // don't load if a clock_info was already loaded | ||
// Load the clock infos | ||
let clockInfoItems = require("clock_info").load(); | ||
// Add the | ||
let clockInfoMenu = require("clock_info").addInteractive(clockInfoItems, { | ||
app : "widclkinfo", | ||
// Add the dimensions we're rendering to here - these are used to detect taps on the clock info area | ||
x : 0, y: 0, w: 72, h:24, | ||
// You can add other information here you want to be passed into 'options' in 'draw' | ||
// This function draws the info | ||
draw : (itm, info, options) => { | ||
// itm: the item containing name/hasRange/etc | ||
// info: data returned from itm.get() containing text/img/etc | ||
// options: options passed into addInteractive | ||
clockInfoInfo = info; | ||
if (WIDGETS["clkinfo"]) | ||
WIDGETS["clkinfo"].draw(WIDGETS["clkinfo"]); | ||
} | ||
}); | ||
let clockInfoInfo; // when clockInfoMenu.draw is called we set this up | ||
(() => { | ||
if (!require("clock_info").loadCount) { // don't load if a clock_info was already loaded | ||
const clock_info = require("clock_info"); | ||
|
||
// The actual widget we're displaying | ||
WIDGETS["clkinfo"] = { | ||
area:"tl", | ||
width: clockInfoMenu.w, | ||
draw:function(e) { | ||
clockInfoMenu.x = e.x; | ||
clockInfoMenu.y = e.y; | ||
var o = clockInfoMenu; | ||
// Clear the background | ||
area: "tl", | ||
width: 0, //this.clockInfoMenu.w, | ||
init: function() { | ||
this.width = this.clockInfoMenu.w; | ||
delete this.init; | ||
return this; | ||
}, | ||
clockInfoInfo: undefined, // defined during clockInfoMenu.draw() | ||
clockInfoMenu: clock_info.addInteractive(clock_info.load(), { | ||
app: "widclkinfo", | ||
// Add the dimensions we're rendering to here - these are used to detect taps on the clock info area | ||
x: 0, | ||
y: 0, // TODO how know if offscreen to start? | ||
w: 72, | ||
h: 23, // workaround off by one error in clock_info | ||
// You can add other information here you want to be passed into 'options' in 'draw' | ||
// This function draws the info | ||
draw: (itm, info, options) => { | ||
// itm: the item containing name/hasRange/etc | ||
// info: data returned from itm.get() containing text/img/etc | ||
// options: options passed into addInteractive | ||
var wi = WIDGETS["clkinfo"]; | ||
wi.clockInfoInfo = info; | ||
wi.clockInfoMenu.y = options.y; | ||
if (WIDGETS["clkinfo"] && wi.clockInfoMenu.y > -24) { | ||
WIDGETS["clkinfo"].draw(WIDGETS["clkinfo"]); | ||
Comment on lines
+27
to
+31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any way to not refer to the global values here? |
||
} | ||
} | ||
}), | ||
draw: function(e) { | ||
this.clockInfoMenu.x = e.x; | ||
var o = this.clockInfoMenu; | ||
g.reset(); | ||
// indicate focus - make background reddish | ||
//if (clockInfoMenu.focus) g.setBgColor(g.blendColor(g.theme.bg, "#f00", 0.25)); | ||
if (clockInfoMenu.focus) g.setColor("#f00"); | ||
g.clearRect(o.x, o.y, o.x+o.w-1, o.y+o.h-1); | ||
if (clockInfoInfo) { | ||
// indicate focus | ||
if (this.clockInfoMenu.focus) { | ||
g.setColor("#f00"); | ||
} | ||
g.clearRect(o.x, o.y, o.x + o.w - 1, o.y + o.h - 1); | ||
if (this.clockInfoInfo) { | ||
var x = o.x; | ||
if (clockInfoInfo.img) { | ||
g.drawImage(clockInfoInfo.img, x,o.y); // draw the image | ||
x+=24; | ||
if (this.clockInfoInfo.img) { | ||
g.drawImage(this.clockInfoInfo.img, x, o.y); // draw the image | ||
x += 24; | ||
} | ||
var availableWidth = o.x+clockInfoMenu.w - (x+2); | ||
g.setFont("6x8:2").setFontAlign(-1,0); | ||
if (g.stringWidth(clockInfoInfo.text) > availableWidth) | ||
var availableWidth = o.x + this.clockInfoMenu.w - (x + 2); | ||
g.setFont("6x8:2").setFontAlign(-1, 0); | ||
if (g.stringWidth(this.clockInfoInfo.text) > availableWidth) | ||
g.setFont("6x8:1x2"); | ||
g.drawString(clockInfoInfo.text, x+2,o.y+12); // draw the text | ||
g.drawString(this.clockInfoInfo.text, x + 2, o.y + 12); // draw the text | ||
} | ||
} | ||
}; | ||
} | ||
}.init(); | ||
|
||
// We make clock info touch area active on the start of the animation | ||
Bangle.on("widgets-start-show", () => { | ||
var wi = WIDGETS["clkinfo"]; | ||
if (wi) { | ||
wi.clockInfoMenu.y = 0; | ||
wi.draw(wi); | ||
} | ||
}); | ||
|
||
Bangle.on("widgets-shown", () => { | ||
var wi = WIDGETS["clkinfo"]; | ||
if (wi) { | ||
wi.clockInfoMenu.y = 0; | ||
wi.draw(wi); | ||
} | ||
}); | ||
|
||
Bangle.on("widgets-start-hide", () => { | ||
var wi = WIDGETS["clkinfo"]; | ||
if (wi) { | ||
wi.clockInfoMenu.ensure_blur(); // let user see defocus cue before hiding | ||
wi.clockInfoMenu.y = -24; | ||
wi.draw(wi); | ||
} | ||
}); | ||
|
||
Bangle.on("widgets-hidden", () => { | ||
var wi = WIDGETS["clkinfo"]; | ||
if (wi) { | ||
wi.clockInfoMenu.ensure_blur(); | ||
wi.clockInfoMenu.y = -24; | ||
wi.draw(wi); | ||
} | ||
}); | ||
}})() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ exports.hide = function() { | |
w.area = ""; | ||
if (w.x!=undefined) g.clearRect(w.x,w.y,w.x+w.width-1,w.y+23); | ||
} | ||
Bangle.emit("widgets-hidden"); | ||
}; | ||
|
||
/// Show any hidden widgets | ||
|
@@ -25,6 +26,7 @@ exports.show = function() { | |
delete w._area; | ||
w.draw(w); | ||
} | ||
Bangle.emit("widgets-shown"); | ||
}; | ||
|
||
/// Remove anything not needed if the overlay was removed | ||
|
@@ -129,19 +131,41 @@ exports.swipeOn = function(autohide) { | |
function anim(dir, callback) { | ||
if (exports.animInterval) clearInterval(exports.animInterval); | ||
exports.animInterval = setInterval(function() { | ||
exports.offset += dir; | ||
// exports.offset < -23 + |dir| > -|dir| otherwise | ||
// dir >0 start showing shown this step showing | ||
// <0 hidden this step start hiding hiding | ||
Comment on lines
+134
to
+136
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is probably a more efficient way to do these nested conditions |
||
let stop = false; | ||
if (dir>0 && exports.offset>=0) { // fully down | ||
stop = true; | ||
exports.offset = 0; | ||
} else if (dir<0 && exports.offset<-23) { // fully up | ||
stop = true; | ||
exports.offset = -24; | ||
if (dir > 0) { | ||
if (exports.offset >= -dir) { | ||
// nearly shown | ||
stop = true; | ||
exports.offset = 0; // clamp | ||
Bangle.emit("widgets-shown"); | ||
} else if (exports.offset < -23 + dir) { | ||
Bangle.emit("widgets-start-show"); | ||
} else { | ||
Bangle.emit("widgets-anim-step"); | ||
} | ||
} else if (dir < 0) { | ||
if (exports.offset > dir) { | ||
Bangle.emit("widgets-start-hide"); | ||
} else if (exports.offset < -23 - dir) { | ||
// nearly hidden | ||
stop = true; | ||
exports.offset = -24; // clamp | ||
Bangle.emit("widgets-hidden"); | ||
} else { | ||
Bangle.emit("widgets-anim-step"); | ||
} | ||
} | ||
if (stop) { | ||
clearInterval(exports.animInterval); | ||
delete exports.animInterval; | ||
if (callback) callback(); | ||
if (callback) { | ||
callback(); | ||
} | ||
} else { | ||
exports.offset += dir; | ||
} | ||
queueDraw(); | ||
}, 50); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Want to be sure this is consistent with how we define rectangles for widgets and app area etc