changing textcolor in a field takes FOREVER

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
adventuresofgreg
Posts: 349
Joined: Tue Oct 28, 2008 1:23 am
Contact:

changing textcolor in a field takes FOREVER

Post by adventuresofgreg » Thu Nov 03, 2011 4:33 pm

Hi: I'm having a problem with setting textstyle and textcolor in a field with a script for iOS. I have a field with 90 lines, and the following script which looks at the content of each line and changes the color and textstyle of the line takes 20 SECONDS TO RUN on my iPad!!!!

Since you can only color and style text in a field (not in memory), I don't see any way around this??? Without the color or style changes, the field loads in about 3.5 seconds (due to other scripts involved).

I'm using LC v5.0

---------------
repeat for z
if item 4 of line x of thetextholder = "correct" then
set the textstyle of line x of field thetext to "bold"
set the textcolor of line x of field thetext to 0,140,0
end if
if item 4 of line x of thetextholder = "wrong" then
--set the textstyle of line x of field thetext to "bold"
set the textcolor of line x of field thetext to 220,0,0
end if
put x+1 into x
end repeat

Klaus
Posts: 14182
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: changing textcolor in a field takes FOREVER

Post by Klaus » Thu Nov 03, 2011 5:06 pm

Hi Greg,

did you "lock screen" and "unlock screen" before/after your changes?
...
lock screen
repeat for z
...
end repeat
unlock screen
...


Best

Klaus

adventuresofgreg
Posts: 349
Joined: Tue Oct 28, 2008 1:23 am
Contact:

Re: changing textcolor in a field takes FOREVER

Post by adventuresofgreg » Thu Nov 03, 2011 5:14 pm

oh ya. duh. I knew that. :-)

Klaus
Posts: 14182
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: changing textcolor in a field takes FOREVER

Post by Klaus » Thu Nov 03, 2011 6:20 pm

:D

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4166
Joined: Sun Jan 07, 2007 9:12 pm

Re: changing textcolor in a field takes FOREVER

Post by bn » Thu Nov 03, 2011 9:38 pm

to shorten FOREVER even a bit more:

Code: Select all

on mouseUp
   put "0,140,0" into tGreen
   put "220,0,0" into tRed
   put "<p>" into tP
   put "</p>" into tPEnd
   put "<b>" into tB
   put "</b>" into tBEnd
   put "<font color=" & quote & tGreen & quote & ">" into tStartFontGreen
   put "<font color=" & quote & tRed & quote & ">" into tStartFontRed
   put "</font>" into tEndFont
   
   put field "theText" into tData -- take the field into a varible, a lot faster
   put field "theTextHolder" into theTextHolder -- assuming your variable theTextHolder comes from a field of the same name
   
   put 1 into tCounter
   repeat for each line aLine in theTextHolder
      if item 4 of aLIne = "correct" then
         put tP & tStartFontGreen & tB & line tCounter of tData & tBEnd & tEndFont & tPEnd & return after tCollect -- bold and green
      end if
      if item 4 of aLine = "wrong" then
         --put tP & tStartFontRed & tB & line tCounter of tData & tBEnd & tEndFont & tPEnd & return after tCollect -- bold and red
         put tP & tStartFontRed  & line tCounter of tData & tEndFont & tPEnd & return after tCollect -- just red
      end if
      add 1 to tCounter
   end repeat
   delete last char of tCollect
   set the htmlText of field "NewHTML" to tCollect  -- for testing you make a new field, 
   -- set the htmlText of field "theText" to tCollect  -- in your app you probably would want to put it back into field "theText"
end mouseUp
I had a similar problem on a slow iPhone G3 and resorted to do the coloring and setting bold by constructing the html on the fly.

It is orders of magnitude faster then setting the attributes of a line of a field etc.

kind regards

Bernd

PS I can hear you even without all caps. No need yelling.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4166
Joined: Sun Jan 07, 2007 9:12 pm

Re: changing textcolor in a field takes FOREVER

Post by bn » Thu Nov 03, 2011 10:19 pm

Hi,

here is the stack I used to test this in the IDE.

colorize HTML Text.livecode.zip
(4.1 KiB) Downloaded 352 times
Kind regards

Bernd

adventuresofgreg
Posts: 349
Joined: Tue Oct 28, 2008 1:23 am
Contact:

Re: changing textcolor in a field takes FOREVER

Post by adventuresofgreg » Fri Nov 04, 2011 12:06 am

Yes, thank you. That is MUCH more efficient. :-)

Post Reply