-
I get about 3-5 calls to
drawWidgets
with around 100ms each. So the bangle is computing, drawing and using power for 400ms on average while not doing anything useful on each clock<->launcher transition.Since the main use of the update method is prevention of additional calls to
drawWidgets
, how about something like the following duringdrawWidgets
:let origDraw = Bangle.drawWidgets; let drawCount = 0; Bangle.drawWidgets = ()=>{drawCount++;}; for (wd of WIDGETS) wd.draw(wd); Bangle.drawWidgets = origDraw; if (drawCount > 0) setTimeout(Bangle.drawWidgets,0);
That would reduce drawing the widgets to one additional time after every change for width/area has been done. Still one call more than needed when using update methods, but less overhead on memory and code size.
appRect
could be updated there as well to keep it dynamic.The wrapping of
draw
to check if widgets are currently hidden could be replaced by just settingdraw = ()=>{}
and restoring that on showing the widgets. Actually thewidget_utils
module could now be used there. That would probably remove the need for my some of myBangle.*Widgets
-methods altogether.
Ahh, thanks! Sorry, I missed that. That could be a good change to pull into the main Espruino versions and will be backwards compatible.
How slow is it really though? I just tested here and I get 70ms for a full widget redraw (which will only happen when apps are swapped from clock->something else or back). But because it's executed in a timeout, the app will load, everything will display fine and then the widget redraw will happen - so it's not going add a noticeable delay to loading.
I'm just conscious that this is for 4 widgets (widclk,widclkbttm,widclose and widcloselaunch), two of which are basically forks, so really only 2 widgets (neither of which are super popular). I wonder how much effort we really need to put into saving that extra 70ms that won't be noticed anyway.
widgetupdate
is interesting, but by wrapping every widget draw function with a check it is adding several ms of overhead to every draw call (and memory use). Also previously appRect was dynamic (if you had a widget that updated itself to appear or disappear, appRect could change over time).I guess one option is to modify drawWidgets at https://github.com/espruino/Espruino/blob/master/libs/js/banglejs/Bangle_drawWidgets_Q3.js#L11 to add
if (wd.update) wd.update();
So then if a widget needed to change its size (or
area
), it could do it on the next drawWidgets call without having to reschedule a whole new draw. That'd add maybe a ms or two todrawWidgets
but in total it's pretty tiny.Yes, I only really noticed it recently. It's a shame there's not a better way around it.
Yes, absolutely!