Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How does multiple position updates behave?

ANSWERED

SDK:5.0.2

Device: Fitbit Versa3(36.128.5.38)

 

What does it do internally when I write code like below?

 

Spoiler
aGraphicsElement.x = 10;
if (foo) {
  aGraphicsElement.x += 10;
}

When foo is true, Will the rendering invoke twice? Or, combine into once?

 

Is it be better to write like below?

 

Spoiler
let x = 10;
if (foo) {
  x += 10;

aGraphicsElement.x = x;
Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

I think the latter could be more efficient, because changing an element's x might result in the layout being recalculated each time. (Maybe it doesn't, if  layouts are only recalculated after all of your code has finished.)

Although it's probably not what you want to do, you could write aGraphicsElement.x = foo? 20 : 10;

Peter McLennan
Gondwana Software

View best answer in original post

Best Answer
2 REPLIES 2

I think the latter could be more efficient, because changing an element's x might result in the layout being recalculated each time. (Maybe it doesn't, if  layouts are only recalculated after all of your code has finished.)

Although it's probably not what you want to do, you could write aGraphicsElement.x = foo? 20 : 10;

Peter McLennan
Gondwana Software
Best Answer

@Gondwana 
Thank you for your replay.

I think same thing.

 

I've been plotting to cut corners. But I' ll write right way.

Best Answer
0 Votes