styling lines of a field dynamically

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: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
Da_Elf
Posts: 311
Joined: Sun Apr 27, 2014 2:45 am

styling lines of a field dynamically

Post by Da_Elf » Thu Oct 23, 2014 12:55 am

This code works. If there is someone who knows an easier way to do it please share. Until then if this helps anyone then feel free to use it.
I created it since there was never the same amount of lines between titles to uniformly choose a line number to style

Code: Select all

on mouseUp
   put empty into fooditems
   put 1 into titlearraycount
   repeat for 5 times
      put "This is a title" & return after fooditems
      put the number of lines in fooditems into listTitles[titlearraycount]
      add 1 to titlearraycount
      put "this is some text" & return after fooditems
      put "this is some more text" & return after fooditems
      put "this will finish it" & return after fooditems
      put "-------------------------" & return after fooditems
   end repeat
   set the text of fld "A" to fooditems
   repeat for each element deline in listTitles
      set the textSize of line deline of fld "A" to "22"
      set the textStyle of line deline of fld "A" to "bold"
   end repeat
end mouseUp

MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

Re: styling lines of a field dynamically

Post by MaxV » Wed Oct 29, 2014 5:26 pm

Here is my way:

Code: Select all

put "<h1>This is a title</h1><font size=22>this is some text<br>this is some more text<br>this will finish it</font><br>-------------------------" into temp
set the htmlText of field "A" to temp
just 2 lines. 8)
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

Da_Elf
Posts: 311
Joined: Sun Apr 27, 2014 2:45 am

Re: styling lines of a field dynamically

Post by Da_Elf » Thu Oct 30, 2014 3:50 am

Yes.. this has been a learning experience. At least I'm learning

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: styling lines of a field dynamically

Post by [-hh] » Thu Oct 30, 2014 2:08 pm

Hi Da_Elf,

good idea to "serialise" this. There is another advantage of your method:
You created a 'numbering system' of the entries with that.
I changed the second part of your script slightly to show what I mean.

Code: Select all

on mouseUp
  put empty into fooditems
  put 1 into titlearraycount
  repeat for 5 times
    put "This is a title" & return after fooditems
    put the number of lines in fooditems into listTitles[titlearraycount]
    add 1 to titlearraycount
    put "this is some text" & return after fooditems
    put "this is some more text" & return after fooditems
    put "this will finish it" & return after fooditems
    put "-------------------------" & return after fooditems
  end repeat
  lock screen; lock messages
  put fooditems into fld "A"; set textsize of fld "A" to 14
  put the keys of listTitles into kk; sort kk numeric
  repeat for each line k in kk
    put listTitles[k] into deline
    put "[" & k &"]" & space before line deline of fld "A"
    set textStyle of line deline of fld "A" to "bold"
    set textSize of line deline of fld "A" to "22"
    -- put item (1+ k mod 5) of "green,red,cyan,gray,yellow" into tc
    -- set textColor of first word of line deline of fld "A" to tc
    -- set backcolor of line deline of fld "A" to tc
    -- set backColor of first word of line deline of fld "A" to "black"
  end repeat
  unlock screen; unlock messages
end mouseUp
shiftLock happens

Post Reply