-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[widclkinfo] Keeps focus when widget_utils.swipeOn() #3680
Draft
cbkerr
wants to merge
12
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.
+92
−35
Draft
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
8d626dc
clock_info: Expose internal blur function as force_blur
0d4d1b8
widget_utils: Add shown and hidden events
a906075
widclkinfo: work in progress: Be aware of widget_utils.swipeOn
9ec6acc
Suggestions from review: emit events from Bangle and moving force_blu…
73cf053
Also emit event when autohiding
6cf3393
Listen for widget events from Bangle
8ddfeab
widget_utils: Emit shown and hidden events on show and hide functions
37cc547
widclkinfo: Remove references to widget_utils
adfd5c8
widclkinfo: cleanup event listeners
6aa44dc
widclkinfo: move draw function definition.
8e0d060
widclkinfo: Don't redraw widget if its clock_info is off screen
0d4234d
widclkinfo: balance brackets
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 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 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", | ||
let clockInfoItems = clock_info.load(); | ||
|
||
let clockInfoMenu = 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, | ||
x: 0, | ||
y: -24, // TODO how know if offscreen to start? | ||
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) => { | ||
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"]) | ||
clockInfoMenu.y = options.y; | ||
if (WIDGETS["clkinfo"] && clockInfoMenu.y > -24) { | ||
WIDGETS["clkinfo"].draw(WIDGETS["clkinfo"]); | ||
} | ||
} | ||
}); | ||
|
||
let clockInfoInfo; // when clockInfoMenu.draw is called we set this up | ||
let draw = function(e) { | ||
clockInfoMenu.x = e.x; | ||
var o = clockInfoMenu; | ||
// Clear the background | ||
g.reset(); | ||
// indicate focus | ||
if (clockInfoMenu.focus) { | ||
g.setColor("#f00"); | ||
} | ||
g.clearRect(o.x, o.y, o.x + o.w - 1, o.y + o.h - 1); | ||
|
||
if (clockInfoInfo) { | ||
var x = o.x; | ||
if (clockInfoInfo.img) { | ||
g.drawImage(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) | ||
g.setFont("6x8:1x2"); | ||
g.drawString(clockInfoInfo.text, x + 2, o.y + 12); // draw the text | ||
} | ||
}; | ||
|
||
// The actual widget we're displaying | ||
WIDGETS["clkinfo"] = { | ||
area:"tl", | ||
area: "tl", | ||
width: clockInfoMenu.w, | ||
draw:function(e) { | ||
clockInfoMenu.x = e.x; | ||
clockInfoMenu.y = e.y; | ||
var o = clockInfoMenu; | ||
// Clear the background | ||
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) { | ||
var x = o.x; | ||
if (clockInfoInfo.img) { | ||
g.drawImage(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) | ||
g.setFont("6x8:1x2"); | ||
g.drawString(clockInfoInfo.text, x+2,o.y+12); // draw the text | ||
} | ||
} | ||
draw: draw | ||
}; | ||
} | ||
|
||
Bangle.on("widgets-start-show", () => { | ||
clockInfoMenu.y = 0; | ||
if (WIDGETS["clkinfo"]) { | ||
WIDGETS["clkinfo"].draw(WIDGETS["clkinfo"]); | ||
} | ||
}) | ||
|
||
Bangle.on("widgets-shown", () => { | ||
clockInfoMenu.y = 0; | ||
if (WIDGETS["clkinfo"]) { | ||
WIDGETS["clkinfo"].draw(WIDGETS["clkinfo"]); | ||
} | ||
}); | ||
|
||
Bangle.on("widgets-start-hide", () => { | ||
clockInfoMenu.y = -24; | ||
if (WIDGETS["clkinfo"]) { | ||
WIDGETS["clkinfo"].draw(WIDGETS["clkinfo"]); | ||
} | ||
if (clockInfoMenu.focus) { | ||
clockInfoMenu.blur(); | ||
} | ||
}); | ||
|
||
Bangle.on("widgets-hidden", () => { | ||
clockInfoMenu.y = -24; | ||
if (WIDGETS["clkinfo"]) { | ||
WIDGETS["clkinfo"].draw(WIDGETS["clkinfo"]); | ||
} | ||
// check here too in case widget_utils.hide() is called | ||
if (clockInfoMenu.focus) { | ||
clockInfoMenu.blur(); | ||
} | ||
}); | ||
} |
This file contains 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
Oops, something went wrong.
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.
Would it work if we moved the
widgets-start-show/hide
into the start of theanim()
function?