Using ternary operators in text field

Hello, I am a graphic designer playing developer here, so a bit of a newbie. Is there any way to use ternary operators within a text field in WFS?

Use case: I’m trying to create a “fuzzy time” text watch face… i.e. “quarter to 5” instead of 5:12-5:17 etc.

Could anyone guide me here?

Thanks!

Yes there is good training on this for Tag Expressions and it shows how to use ternary operations.

Ron
Samsung Developer Relations

Thanks @r.liechty_SDR - but how do I use these operations in a text component?

1 Like

Inquiring minds … :grinning:

For example you place there text field layer for each quote you plan to have there. Then write the conditions in the opacity field. For example ([MIN]>11)*([MIN]<18)?100:0 for the text “quarter to [HOUR]” will make it 100% opaque each hour from 12th to 17th minute. It should be possible to insert the conditionals directly in the text, but somehow I cant manage it to work right.

Ok thanks Peter. Do you mind checking if that’s just a bug, or if conditionals are purposely not allowed in text? This might be a feature request… I’d far rather write one script then a couple hundred.

Also, my earlier example had a typo… I’m trying to do “quarter to five” not “5”. 288+ text blocks, here i come!

Lmk if you see a faster workaround.

Thx

This returns
Time is Less for first quarter hour and Time is More for the next 45 mins it is the text is in quotes
Time is ([MIN] <15 ? "Less" : "More")

Ron
Samsung Developer Relations

1 Like

Aha - you’re a lifesaver! Still a bit of nesting to do, but this greatly speeds things up.

Another learning: text fields don’t wrap when string is longer than text box is wide…

@r.liechty_SDR Running into an issue here.

(([MIN]>=53)*([MIN]<=57)?"five to": (([MIN]>=48)*([MIN]<=52)?"ten to": (([MIN]>=43)*([MIN]<=47)?"quarter to": (([MIN]>=38)*([MIN]<=42)?"twenty to": (([MIN]>=33)*([MIN]<=37)?"twenty-five to": (([MIN]>=28)*([MIN]<=32)?"half past": (([MIN]>=23)*([MIN]<=27)?"twenty-five after": (([MIN]>=18)*([MIN]<=22)?"twenty after": (([MIN]>=13)*([MIN]<=17)?"quarter after": (([MIN]>=8)*([MIN]<=12)?"ten after": (([MIN]>=3)*([MIN]<=7)?"five after": ((([MIN]>=58)*([MIN]<=2)?"o'clock": (([HOUR_0_23]==23)*([MIN]>=58)?"": (([HOUR_0_23]==12)*([MIN]<=2)?"": (([HOUR_0_23]==11)*([MIN]>=58)?"": (([HOUR_0_23]==0)*([MIN]<=2)?"":"o'clock")))))))))))))))))

This runs fine in WFS, but when run on Galaxy Watch 4, the above formula returns “false” in place of “twenty to” below:
image

LMK if you see why this is occurring.

It’s a bug. See this thread: TAG expression runs in the emulator but not on watch