Setting the text style of certain words in a field

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller

Setting the text style of certain words in a field

Postby LouisThompson » Thu Jul 13, 2017 1:03 pm

Hi,

I've played around, searched, but not found anything...
(Sounds like the first line of a Country & Western song :-)

Anyway, I have a field which contains a Python Script.

I'd like to set the text style of certain words...

eg
def, return, import, for : bold, blue
numbers should all be red
comments should be green

I'm happy to parse the field to find the relevant sections and words, but how do I apply the text style atrributes.

Thanks

Louis
LouisThompson
 
Posts: 4
Joined: Mon Oct 03, 2016 8:11 pm

Re: Setting the text style of certain words in a field

Postby bogs » Thu Jul 13, 2017 1:16 pm

I believe the htmlText property in the dictionary may be what you want. You can set many aspects of text styling with it, including colors. Alternately, textStyle / textColor could be used. Just type "text" in the dictionary, there is a lot there :)
Image
bogs
 
Posts: 384
Joined: Sat Feb 25, 2017 10:45 pm

Re: Setting the text style of certain words in a field

Postby dunbarx » Thu Jul 13, 2017 1:50 pm

What Bogs said.

The HTML text will allow you to attach style tags to text within, say, a variable. You need to research this as per his suggestion, since this is a powerful tool indeed.

But just to get back to basics, put some numbers and ordinary words in a field. Put this in a button script somewhere:
Code: Select all
on mouseUp
   repeat with y = 1 to the number of words of fld 1
      if word y of fld 1 is a number then set the textColor of word y of fld 1 to "yellow"
      else set the textColor of word y of fld 1 to "blue"
   end repeat
end mouseUp


This will require forethought to parse text , as you say, into several different categories. The "offset" function might come in handy...

Craig Newman
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
 
Posts: 4793
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Setting the text style of certain words in a field

Postby MaxV » Mon Jul 17, 2017 12:46 pm

Livecode Wiki: http://livecode.wikia.com
My livecode blog: http://livecodeitalia.blogspot.it
To post code use this: http://tinyurl.com/ogp6d5w
MaxV
 
Posts: 1285
Joined: Tue May 28, 2013 2:20 pm
Location: Italy


Return to Getting Started with LiveCode - Complete Beginners

Who is online

Users browsing this forum: No registered users and 5 guests

cron