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

Passing a % value to property in index.gui

ANSWERED

I'm developing a clockface where I pass a property to the index.gui from index.js.

If I pass a numeric value I have no problem, however if I'm attempting to pass a % value the SDK gives me an error as it expect a numeric value while it is a string.

An example of such code is

 

rectHandle.y = startingPoint;

if startingPoint is numeric no problem, if it's for example "20%" it gives me the following error

Unhandled exception: TypeError: Cannot set property to '20%': Unexpected type. Expected a Number

Thanks!

 

Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

Sorry, the percentage values aren't currently supported, but you can calculate the pixel value from the device screen dimensions.

 

 

import { me as device } from "device";
if (!device.screen) device.screen = { width: 348, height: 250 };

let percent = 40;
let pixels = percent / 100 * device.screen.width;
myVar.x = pixels;   

 

View best answer in original post

Best Answer
1 REPLY 1

Sorry, the percentage values aren't currently supported, but you can calculate the pixel value from the device screen dimensions.

 

 

import { me as device } from "device";
if (!device.screen) device.screen = { width: 348, height: 250 };

let percent = 40;
let pixels = percent / 100 * device.screen.width;
myVar.x = pixels;   

 

Best Answer