Adding multiple textstyle

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
jalz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 340
Joined: Fri Sep 12, 2008 11:04 pm

Adding multiple textstyle

Post by jalz » Thu Sep 25, 2014 10:34 pm

Hi Guys,

Im working on my data entry screen. I want to have four buttons to style my text, plain, bold, italics and underline. Each of the buttons has the following stype of code on the mouseup handler.

set the textStyle of the selectedChunk to "bold"

So when I highlight my text, and apply the bold button, the text as expected goes bold. Similarly when I select Italics, the highlighted text turns into italics.

What I want to also to do is if the selected text already has a style attached to it, I want to add another style to it. I've checked dictionary it looks like you can add a styleslist. The only thing is I don't know what delimiter I need to use for the styles list. I've got the following code below on my mouse up handler for the bold button. Can someone point me in the right direction please.


put the textStyle of the selectedChunk into tStyle
set the textStyle of the selectedChunk to "bold " & tStyle

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Adding multiple textstyle

Post by FourthWorld » Thu Sep 25, 2014 11:44 pm

For the last several versions, text styles can also be set using array notation to toggle each individually:

Code: Select all

set the textStyle["bold"] of word 1 of fld 1 to true
set the textStyle["italic"] of line 2 of fld 1 to false
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10333
Joined: Wed May 06, 2009 2:28 pm

Re: Adding multiple textstyle

Post by dunbarx » Fri Sep 26, 2014 12:40 am

Hi.

You can also do this in the clear:

set the textstyle of yourChunk to "italic,bold,box"

But I think what you want to do is to build compound textstyles onto chunks that may already have one. That is, if the third word is already "italic", and you press the "bold" button, the textstyle does not simply change to" bold", but rather to "italic,bold".

Is this so? If it is, you seem more than capable fo implementing it. You do not even need a custom property to hold the "history" of the existing style suite, since the "textStyle" property already does all that. Get going. Or ignore me if I am off base here.

EDIT: You already nearly did this above, I now see. You neglected to insert a comma, though. The syntax for a styleList is "style1,stlye2,style3,etc."

Craig Newman

jalz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 340
Joined: Fri Sep 12, 2008 11:04 pm

Re: Adding multiple textstyle

Post by jalz » Fri Sep 26, 2014 1:56 pm

Hi Both,

Thanks Craig, that was exactly what I was looking for. I used the pipe delimiter and the space as a delimiter but should have used the comma!

All the best
Jalz

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

Re: Adding multiple textstyle

Post by Klaus » Fri Sep 26, 2014 2:06 pm

I used the pipe delimiter and the space as a delimiter but should have used the comma!
The dictionary does actually not leave any doubt about this! 8)

Post Reply