Text colour

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
Traxgeek
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 281
Joined: Wed Jan 09, 2013 10:11 am

Text colour

Post by Traxgeek » Thu Dec 04, 2014 9:11 am

Hi, I'm sure this must have been covered but I can't find where ! :oops:

I'm playing with html text input controls.
I can, post-writing my html text, select a chunk and colour it - or whatever I wish to do with it (bold, italic, whatever) - no problems there.
I can also set the text/'foregroundColor' BUT...

What I cannot seem to do is set the foreground colour for the next one, or more, characters that I am about to write/enter.

When I try to set the foreground colour (naturally enough, kind of) the whole of my text changes colour to the newly selected colour.
Is there a way to set the colour of, if you like, the cursor; so that any future characters typed/entered are the new colour whilst any existing text colouring remains unchanged.
(With drawing controls, one can set the 'penColor' but I haven't found a way to do this for text...
As always, any and all help really appreciated.

Trax.
I'm 'getting there'... just far too slowly !
Mac (Siera) and PC (Win7)
LiveCode 8.1.2 / 7.1.1

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

Re: Text colour

Post by bn » Thu Dec 04, 2014 11:44 am

Trax,

I am not sure I understand completely what you want.
Assuming you want to type html text in a regular LC field (as opposed to setting the htmlText of a LC field)

would something like this in the field's script help?

Code: Select all

on keyUp pKey
   put "blue,red,green,brown" into tColors
   put the selectedChunk into tSelChunk
   put word 4 of tSelChunk into tNo
   set the foregroundColor of char tNo of me to any item of tColors
end keyUp
kind regards
Bernd

Traxgeek
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 281
Joined: Wed Jan 09, 2013 10:11 am

Re: Text colour

Post by Traxgeek » Fri Dec 05, 2014 12:34 pm

Hi Bernd,
I'm not too good at explaining myself at the best of times - I'll try again...

I have a field into which I type.
Sometimes I just type, sometimes I cut 'n' paste something from a web page and then modify or add to it in some way (i.e. sometimes it's effectively plain text , other times it's html text.

I can retrospectively/after typing something, hilite a chunk (say a word or a line of text) and then colour it, make it bold etc. all by setting the 'textstyle' of that selected chunk. No worries there...

What I'd like to be able to do though is select the colour of any future text that I am about to/will write.
I think your response gives me a working idea though which would be to set the colour of the char at the current cursor location so that when I do start typing then my selected colour will come into play.

Thanks.

Trax
I'm 'getting there'... just far too slowly !
Mac (Siera) and PC (Win7)
LiveCode 8.1.2 / 7.1.1

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

Re: Text colour

Post by dunbarx » Fri Dec 05, 2014 4:29 pm

Hi.

Why not set a custom property of the field so that the new text will take that color? You can select the color from a pullDown or answer a dialog, whatever. Now modify the code so that the "next" char interrogates the current state of that property.

(pseudo)

set the foreColor of the next char to the nextCharColor of me

Craig Newman

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Text colour

Post by jacque » Sat Dec 06, 2014 4:49 pm

The selectedChunk has a value even if it's just an insertion point. You should be able to set text properties on that. All subsequent text should assume the revised styling.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Traxgeek
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 281
Joined: Wed Jan 09, 2013 10:11 am

Re: Text colour

Post by Traxgeek » Sun Dec 07, 2014 3:57 pm

Thank you Jacque, Thank you dubarx and Thank you Bernd.
Much appreciated all three of you.
I'm 'getting there'... just far too slowly !
Mac (Siera) and PC (Win7)
LiveCode 8.1.2 / 7.1.1

Post Reply