Page 1 of 1

Bold or Change Text color of various lines in Tree View?

Posted: Fri Mar 27, 2020 11:56 pm
by bmcgonag
Hello,

I have a card with a tree view on it that I'm successfully filling with the data I want pulled from an API - Yay! Now, I want to use a property of "online" from the data I pull, to set the text of that associated line in the tree view to either bold, or a different color, or something to make those lines stand out better.

Here's the code I have so far:

Code: Select all

on openCard
   -- set the headers for the API call
   set the httpHeaders to "authorization: bearer <myAPIToken>"
   put "https://my.zerotier.com/api/network" into tUrl
   get url tUrl
   
   -- deal with return data - which works the way I have it here, but it seems wrong since the result isn't empty..but anyway
   
   if the result is empty then
      put it into tJSON
      put JSONtoArray(tJSON) into tArray
      
      repeat with x = 1 to the number of elements in tArray
         
         -- use the returned ID for each network to call and get the machine members of the network
         put tArray[x]["config"]["id"] into tId
         set the httpHeaders to "authorization: bearer <myAPIToken>"
         put "https://my.zerotier.com/api/network/" & tId & "/member" into t2Url
         get url t2Url
         if the result is empty then
            put it into t2JSON
            put JSONtoArray(t2JSON) into t2Array
            
            repeat with y = 1 to the number of elements in t2Array
            
               put t2Array[y]["config"]["ipAssignments"][1] into tIp
               put tArray[x]["config"]["name"] into tNetName
               put t2Array[y]["name"] into tMachName
               if t2Array[y]["online"] = true then
                  -- do something here to set bold or text color?
                  -- So far when I do something here, it gives me an error below where I'm actually adding the data to the trer view.
               end if
               put tIp into temp[tNetName][tMachname]
            end repeat
         else
            answer "Something went wrong."
         end if
      end repeat
      set the sortType of widget 1 to "text"
      set the showseparator of widget 1 to true
      set the sortOrder of widget 1 to "ascending"
      set the arraydata of widget 1 to temp
   else
      put "Something weird happened here!" into Output
   end if
end openCard
As alwas, any help or pointers is much appreciated.

Re: Bold or Change Text color of various lines in Tree View?

Posted: Sat Mar 28, 2020 12:59 pm
by Klaus
An ARRAY is a variable and variable do not have a (text)STYLE property.
And there is no indication in the dictionary, so I am afraid this is just not possible.
We can only set text and styles for the whole widget.

Re: Bold or Change Text color of various lines in Tree View?

Posted: Sat Mar 28, 2020 3:10 pm
by bmcgonag
Ok, thank you.

I wonder if I can add a checkmark icon or something in the tree view some how.

Re: Bold or Change Text color of various lines in Tree View?

Posted: Sun Mar 29, 2020 10:23 am
by Klaus
Hi bmcgonag,
I wonder if I can add a checkmark icon or something in the tree view some how.
I also doubt we can set an ICON here, but "something" is surely possible with a UNICODE character. :D
LC now supports UNICODE and that is just text in the end.
Something like this: ✔︎ ➡️ ❤️ 🌎...
You get the picture.


Best

Klaus

Re: Bold or Change Text color of various lines in Tree View?

Posted: Mon Mar 30, 2020 12:37 pm
by bmcgonag
I thought the same thing, but it just put :check_mark: and :smile: in the space versus showing the character. I'll look up unicode and see if I can tell what I may have done wrong.

Thank you again.

Re: Bold or Change Text color of various lines in Tree View?

Posted: Mon Mar 30, 2020 12:45 pm
by Klaus
Well, this is a tad more complicated. :D

Here a little example that will put a checkmark into a field:

Code: Select all

on mouseUp
   put numtocodepoint(0x2714) into fld 1
end mouseUp

Re: Bold or Change Text color of various lines in Tree View?

Posted: Thu Apr 02, 2020 8:07 pm
by bmcgonag
Klaus wrote:
Mon Mar 30, 2020 12:45 pm
Well, this is a tad more complicated. :D

Here a little example that will put a checkmark into a field:

Code: Select all

on mouseUp
   put numtocodepoint(0x2714) into fld 1
end mouseUp
Klaus rocks! That worked beautifully!