Re: Colouring words
On Aug 10, 2015, at 12:15 PM, Richmond wrote: > On 10/08/15 19:03, Mike Bonner wrote: >> oh. Assuming you're on a version of lc that supports truewords >> >> > > Mine all seem to support falsewords . . . > > Err, sorry, the mask slipped there a minute :/ > > I see that version 7.0.5 supports truewords, and that's good enough for me. > > Thanks for that one. Here's a quick and dirty command that does what you want. Requires the utility function wordoffsets(), which I posted a few days ago on another thread, also available in the Master Library. Call it by specifying the word, the color, and the field ref: colorizeWord "was", "red", the long id of fld "text" on colorizeWord pWord, pColor, fLongID put the text of fLongID into fText put wordoffsets(pWord,fText,true) into offList lock screen -- speeds up the routine considerably, as the screen refresh --only is done once repeat for each item i in offList set the textColor of word i of fLongID to pColor end repeat end colorizeWord You could modify this for LC 7+ to use trueword -- expand wordoffsets() to create a new function truewordoffsets(). Yet another example of how the offsets()/wordoffsets()/lineoffsets() functions make life so much easier…. (All these are in the Master Library.) Richmond: you may want to rename the function to "colourizewords". :-) -- Peter Peter M. Brigham pmb...@gmail.com http://home.comcast.net/~pmbrig ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Colouring words
On 8/10/2015 12:39 PM, Richmond wrote: but, because one cannot set the textColor of a word in a stringVariable it is very slow with large texts because it has to work within the field. That's why I usually use the html suggestion that Mark S. provided. After getting the htmltext of the field, you can replace all instances of the target word with color tags in one line of code. Then set the htmltext of the field to the resulting value of the variable: get the htmltext of fld "what" replace "finalSolution666" with "finalSolution666" in it set the htmltext of fld "what" to it -- Jacqueline Landman Gay | jac...@hyperactivesw.com HyperActive Software | http://www.hyperactivesw.com ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Colouring words
I was going to suggest looking at styledText too, but it is kind of tricky to insert a run within the array. I think Richmond should look at some of the text routines in the masterLibrary. There are several that might be interesting: LineOffsets returns a list of lines that contain a string within container - create a list of each line that contains "only" WordOffsets returns a list of word offsets of a string within a container - create a new list that has line number and the word offsets within the line. wordBounds returns the start and end character of a word specified by line number and work offset. - Based on the line number and word offset, get the start and end character and change the color within the field variable with the screen locked. On 8/10/15 1:59 PM, Mike Bonner wrote: It sounds like you might want to look at the styledtext. Its a bit convoluted, but once you get it figured out, it should be very fast. Pseudo code for this would be.. put the text of the field into a variable. repeat for each line (paragraph) and build up an array of "runs" with descriptive text styling for each paragraph. Apply the resulting array to the field. Sounds simple.. Isn't. On Mon, Aug 10, 2015 at 11:40 AM, Michael Doub wrote: Yet another approach: put "this is the only one" into fld 1 put empty into s1 put empty into e1 get MatchChunk (line 1of fld 1,"(?i).+(only).+",s1,e1) -- the regexp capture returns the start and end characters the match set the textcolor of char s1 to e1 of line 1 of fld 1 to red On 8/10/15 12:03 PM, Mike Bonner wrote: You can do this.. Still a bit ugly but it works. set the textcolor of trueword ( truewordoffset("only",line 5 of field 1)) of line 5 of field 1 to red On Mon, Aug 10, 2015 at 9:13 AM, Richmond wrote: On 10/08/15 16:51, dunb...@aol.com wrote: @Mark There is nothing wrong with setting the textColor of an entire line. Any valid chunk expression would do. No, there is nothing wrong with that, but that is not what I want to do. Richmond. @, Richmond: What are you seeing? Why does it not work? I am in v 6.7. Craig Newman ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Colouring words
It sounds like you might want to look at the styledtext. Its a bit convoluted, but once you get it figured out, it should be very fast. Pseudo code for this would be.. put the text of the field into a variable. repeat for each line (paragraph) and build up an array of "runs" with descriptive text styling for each paragraph. Apply the resulting array to the field. Sounds simple.. Isn't. On Mon, Aug 10, 2015 at 11:40 AM, Michael Doub wrote: > Yet another approach: > >put "this is the only one" into fld 1 > >put empty into s1 >put empty into e1 >get MatchChunk (line 1of fld 1,"(?i).+(only).+",s1,e1) > -- the regexp capture returns the start and end characters the match > >set the textcolor of char s1 to e1 of line 1 of fld 1 to red > > On 8/10/15 12:03 PM, Mike Bonner wrote: > >> You can do this.. Still a bit ugly but it works. >> >> set the textcolor of trueword ( truewordoffset("only",line 5 of field 1)) >> of line 5 of field 1 to red >> >> >> On Mon, Aug 10, 2015 at 9:13 AM, Richmond >> wrote: >> >> On 10/08/15 16:51, dunb...@aol.com wrote: >>> >>> @Mark There is nothing wrong with setting the textColor of an entire line. Any valid chunk expression would do. No, there is nothing wrong with that, but that is not what I want to do. >>> >>> Richmond. >>> >>> >>> @, Richmond: What are you seeing? Why does it not work? I am in v 6.7. Craig Newman ___ >>> use-livecode mailing list >>> use-livecode@lists.runrev.com >>> Please visit this url to subscribe, unsubscribe and manage your >>> subscription preferences: >>> http://lists.runrev.com/mailman/listinfo/use-livecode >>> >>> ___ >> use-livecode mailing list >> use-livecode@lists.runrev.com >> Please visit this url to subscribe, unsubscribe and manage your >> subscription preferences: >> http://lists.runrev.com/mailman/listinfo/use-livecode >> >> > > ___ > use-livecode mailing list > use-livecode@lists.runrev.com > Please visit this url to subscribe, unsubscribe and manage your > subscription preferences: > http://lists.runrev.com/mailman/listinfo/use-livecode > ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Colouring words
Yet another approach: put "this is the only one" into fld 1 put empty into s1 put empty into e1 get MatchChunk (line 1of fld 1,"(?i).+(only).+",s1,e1) -- the regexp capture returns the start and end characters the match set the textcolor of char s1 to e1 of line 1 of fld 1 to red On 8/10/15 12:03 PM, Mike Bonner wrote: You can do this.. Still a bit ugly but it works. set the textcolor of trueword ( truewordoffset("only",line 5 of field 1)) of line 5 of field 1 to red On Mon, Aug 10, 2015 at 9:13 AM, Richmond wrote: On 10/08/15 16:51, dunb...@aol.com wrote: @Mark There is nothing wrong with setting the textColor of an entire line. Any valid chunk expression would do. No, there is nothing wrong with that, but that is not what I want to do. Richmond. @, Richmond: What are you seeing? Why does it not work? I am in v 6.7. Craig Newman ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Colouring words
The thing that emerges from my question is that to colour a word or phrase programmatically in a textField is a fiddly business and it would be nice (??) if a simpler way to do this were introduced. This works very well: on mouseUp put 1 into VOCABLE repeat until word VOCABLE in fld "TEKST" is "finalSolution666" put VOCABLE into fld "KOUNT" if word VOCABLE of fld "TEKST" is "the" then set the textColor of word VOCABLE of fld "TEKST" to red end if add 1 to VOCABLE end repeat end mouseUp but, because one cannot set the textColor of a word in a stringVariable it is very slow with large texts because it has to work within the field. Richmond. ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Colouring words
Richmond. I see, you wanted to use the literal word as a chunk expression. But you surely know this is not valid in LC, and will have to use the wordOffset or something similar so you can get an actual valid chunk. Craig -Original Message- From: Richmond To: How to use LiveCode Sent: Mon, Aug 10, 2015 7:40 am Subject: Colouring words what is wrong with this: if line 5 of fld "WHAT" contains "only" then set the textColor of "only" in line 5 of fld "WHAT" to red end if ??? I would like to set certain phrases in a sentence to a different textColor to the other words . . . . . . should be dead easy. Richmond. ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Colouring words
On 10/08/15 19:03, Mike Bonner wrote: oh. Assuming you're on a version of lc that supports truewords Mine all seem to support falsewords . . . Err, sorry, the mask slipped there a minute :/ I see that version 7.0.5 supports truewords, and that's good enough for me. Thanks for that one. Richmond. ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Colouring words
You can do this.. Still a bit ugly but it works. set the textcolor of trueword ( truewordoffset("only",line 5 of field 1)) of line 5 of field 1 to red On Mon, Aug 10, 2015 at 9:13 AM, Richmond wrote: > On 10/08/15 16:51, dunb...@aol.com wrote: > >> @Mark >> >> >> There is nothing wrong with setting the textColor of an entire line. Any >> valid chunk expression would do. >> > > No, there is nothing wrong with that, but that is not what I want to do. > > Richmond. > > >> >> @, Richmond: >> >> >> What are you seeing? Why does it not work? I am in v 6.7. >> >> >> Craig Newman >> >> >> >> > > ___ > use-livecode mailing list > use-livecode@lists.runrev.com > Please visit this url to subscribe, unsubscribe and manage your > subscription preferences: > http://lists.runrev.com/mailman/listinfo/use-livecode > ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Colouring words
oh. Assuming you're on a version of lc that supports truewords On Mon, Aug 10, 2015 at 10:03 AM, Mike Bonner wrote: > You can do this.. Still a bit ugly but it works. > > set the textcolor of trueword ( truewordoffset("only",line 5 of field 1)) > of line 5 of field 1 to red > > > On Mon, Aug 10, 2015 at 9:13 AM, Richmond > wrote: > >> On 10/08/15 16:51, dunb...@aol.com wrote: >> >>> @Mark >>> >>> >>> There is nothing wrong with setting the textColor of an entire line. Any >>> valid chunk expression would do. >>> >> >> No, there is nothing wrong with that, but that is not what I want to do. >> >> Richmond. >> >> >>> >>> @, Richmond: >>> >>> >>> What are you seeing? Why does it not work? I am in v 6.7. >>> >>> >>> Craig Newman >>> >>> >>> >>> >> >> ___ >> use-livecode mailing list >> use-livecode@lists.runrev.com >> Please visit this url to subscribe, unsubscribe and manage your >> subscription preferences: >> http://lists.runrev.com/mailman/listinfo/use-livecode >> > > ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Colouring words
On 10/08/15 16:51, dunb...@aol.com wrote: @Mark There is nothing wrong with setting the textColor of an entire line. Any valid chunk expression would do. No, there is nothing wrong with that, but that is not what I want to do. Richmond. @, Richmond: What are you seeing? Why does it not work? I am in v 6.7. Craig Newman ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Colouring words
@Mark There is nothing wrong with setting the textColor of an entire line. Any valid chunk expression would do. @, Richmond: What are you seeing? Why does it not work? I am in v 6.7. Craig Newman -Original Message- From: Richmond To: How to use LiveCode Sent: Mon, Aug 10, 2015 8:58 am Subject: Re: Colouring words On 10/08/15 14:45, Mark Schonewille wrote: > Hi Richmond, > > It may not be as easy as you think: > > repeat with x = 1 to number of words of line y of fld "What" > if word x of line y of fld "What" is "only" then > set the textColor of word x of line y of fld "What" to red > end if > end repeat > > or > > put the htmlText of fld "What" into myText > replace "only" with "only set the htmlText of fld "What" to myText > > Both approaches have advantages and disadvantages. > > -- > Best regards, > > Mark Schonewille > > > On 8/10/2015 13:39, Richmond wrote: >> what is wrong with this: >> >> if line 5 of fld "WHAT" contains "only" then >> set the textColor of "only" in line 5 of fld "WHAT" to red >> end if >> >> ??? >> >> I would like to set certain phrases in a sentence to a different >> textColor to the other words . . . >> >> . . . should be dead easy. >> >> Richmond. Oh, well . . . I was well aware I could do this: on mouseUp set the textColor of word 3 of line 1 of fld "WHAT" to red end mouseUp it just seemed incredibly longwinded to have to write stuff like this: on mouseUp if word 3 of line 1 of fld "WHAT" is "only" then set the textColor of word 3 of line 1 of fld "WHAT" to red end if end mouseUp and then, as you have suggested, write a routine to trawl through all the words in a line. Richmond. ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Colouring words
On 10/08/15 14:45, Mark Schonewille wrote: Hi Richmond, It may not be as easy as you think: repeat with x = 1 to number of words of line y of fld "What" if word x of line y of fld "What" is "only" then set the textColor of word x of line y of fld "What" to red end if end repeat or put the htmlText of fld "What" into myText replace "only" with "only On 8/10/2015 13:39, Richmond wrote: what is wrong with this: if line 5 of fld "WHAT" contains "only" then set the textColor of "only" in line 5 of fld "WHAT" to red end if ??? I would like to set certain phrases in a sentence to a different textColor to the other words . . . . . . should be dead easy. Richmond. Oh, well . . . I was well aware I could do this: on mouseUp set the textColor of word 3 of line 1 of fld "WHAT" to red end mouseUp it just seemed incredibly longwinded to have to write stuff like this: on mouseUp if word 3 of line 1 of fld "WHAT" is "only" then set the textColor of word 3 of line 1 of fld "WHAT" to red end if end mouseUp and then, as you have suggested, write a routine to trawl through all the words in a line. Richmond. ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Colouring words
Hi Richmond, It may not be as easy as you think: repeat with x = 1 to number of words of line y of fld "What" if word x of line y of fld "What" is "only" then set the textColor of word x of line y of fld "What" to red end if end repeat or put the htmlText of fld "What" into myText replace "only" with "onlyhttp://economy-x-talk.com Twitter: http://twitter.com/xtalkprogrammer KvK: 50277553 Installer Maker for LiveCode: http://qery.us/468 Buy my new book "Programming LiveCode for the Real Beginner" http://qery.us/3fi LiveCode on Facebook: https://www.facebook.com/groups/runrev/ On 8/10/2015 13:39, Richmond wrote: what is wrong with this: if line 5 of fld "WHAT" contains "only" then set the textColor of "only" in line 5 of fld "WHAT" to red end if ??? I would like to set certain phrases in a sentence to a different textColor to the other words . . . . . . should be dead easy. Richmond. ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode