how many time is the function onLayout(dc) called?

Hi all,

I've just added some log (device dimension HxW and field dimension HxW) to the default data-field project to understand the logic behind the onLayout(dc) when I change data field (1,2,3...) from simulator.

(https://github.com/dodor84/data-field)

  • This is the log when the sim start with one field:

initialize
D: 322x246 - 322x246

  • then I add another field (2 field)

D: 322x246 - 160x246

  • then I add another field (3 field)

D: 322x246 - 106x246
D: 322x246 - 105x246
D: 322x246 - 106x246
D: 322x246 - 105x246
D: 322x246 - 106x246
D: 322x246 - 105x246
D: 322x246 - 106x246
D: 322x246 - 105x246
D: 322x246 - 106x246
D: 322x246 - 105x246
D: 322x246 - 106x246
D: 322x246 - 105x246
D: 322x246 - 106x246
D: 322x246 - 105x246
D: 322x246 - 106x246
D: 322x246 - 105x246
D: 322x246 - 106x246
D: 322x246 - 105x246
D: 322x246 - 106x246

...

every second the function is called.

-----------------------------

In docs I read that the function is called before the View is shown to load resources and set up the layout of the View: https://developer.garmin.com/connect-iq/api-docs/Toybox/WatchUi/View.html#onLayout-instance_method

Why with one or two field is the function called just one time and when there are 3 or more field is called every second?

Is just a problem on the simulator?

can this be a battery leak?

thanks,

Edoardo

  • The sim works different than on a read device, where typically, a CIQ DF is only displayed once or twice.  On a real device, onLayout is called when the DF is first displayed, and the onUpdate() while it is displayed.  If you change data screens so that DF isn't displayed, neither is called.

    In the sim if you are displaying the Df in a 4 field layout, onLayout are called 4 times every second, as each DF can be different in things like size and obscurity flags.

    if you are on a real device, and you have the same DF in two positions on the same screen, onLayout and onUpdate will be called every second for each one.

  • thank you so much. Now is more clear the behavior behind onLayout.