JohnySeven / TWatchSK

TTGO T-Watch 2020 v1 supporting Signal K features for displaying boat data and controlling devices on board.
MIT License
9 stars 1 forks source link

DUI - Added support for formating label's texts, fixed color from hex #55

Closed JohnySeven closed 3 years ago

JohnySeven commented 3 years ago

This update will fix issue when user is specifying color from hex. This update adds new binding property 'format' that allows user to format binding text result.

Something like:

"binding": { "format": "Depth $$ m", }

And $$ will be replaced by calculated value from SK, result will be:

Depth 4.3 m

Please test it with latest Designer - supports both of the changes. Thanks

ba58smith commented 3 years ago

To use this:

  1. Make the Binding to the Path the normal way:
  2. Add "binding": { "format": "Depth $$ m", } to the Format field.
  3. Whatever value comes from the binding in Step 1 will be put in place of the $$ in Step 2.

Right?

ba58smith commented 3 years ago

If you're finished with this PR, go ahead and merge it. I've looked at the code and I understand only about half of it. (Unless you WANT me to test it before you merge it - and if you do, I will.)

JohnySeven commented 3 years ago

Do you want me to explain some bits?

ba58smith commented 3 years ago

Most of the "bits" I don't understand very well are about working with JSON. I know what it does, and how it works IN GENERAL, but I'm not familiar with the details - like when you use a JsonObject vs. JsonArray, and when you CreateNestedObject(), etc. But I've been looking at the data that the Watch sends to SK as a single delta (battery, uptime, and something else), trying to break that out into three separate deltas so they can be displayed in Instrument Panel. I'll dig into the JSON stuff then.

But there is one line of code in what you just added that doesn't make any sense to me: replace.replace("$$", stringValue.c_str()); The first replace is an instance of a String. But I don't understand the syntax of replace.replace().

JohnySeven commented 3 years ago

Well the replace is instance of string, the format text from binding object. I call replace function of string class that will replace occurrences of "$$" from first argument with string in second argument in replace variable that is in instance of string - man, does it even make sense? Maybe I'll rename the variable to make it more understandable.

ba58smith commented 3 years ago

Ah, that makes sense. I thought the two "replace" were referring to the same instance of a String, and it was some kind of String class magic.

JohnySeven commented 3 years ago

I've managed to rename the variable replace and merging!