alter textstyle 'on the fly'

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

glenn9
Posts: 223
Joined: Wed Jan 15, 2020 10:45 pm
Location: Europe

alter textstyle 'on the fly'

Post by glenn9 » Sun Mar 06, 2022 12:43 pm

Dear all

I'm wanting to alter textstyle as I type and although I've solved it with a 'kludge', I was wondering if there was a better way of achieving this?

Specifically what I'm wanting to achieve is that if a specific character is entered then the colour of that character is then changed.

I've managed to achieve this with the following code:

Code: Select all

     on rawkeyup
        if the last char of fld"Notes" is "z" then
        set the forecolor of the last char of fld"Notes" to red
  else
     	set the forecolor of the last char of fld"Notes" to black
  end if
   end rawkeyup
This works to a degree but if I then alter already typed text to the specified text, then of course this doesn't work!

I guess what I want to code is something like this (which of course doesn't work!)...

Code: Select all

...
if rawkeyup is "z" then 
set the forecolor of rawkeyup to red
...

Grateful for any ideas...

Thanks,

Glenn

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: alter textstyle 'on the fly'

Post by Klaus » Sun Mar 06, 2022 12:52 pm

Hi Glenn,
This works to a degree but if I then alter already typed text to the specified text, then of course this doesn't work!
sorry, don't understand?


Best

Klaus

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: alter textstyle 'on the fly'

Post by jmburnod » Sun Mar 06, 2022 12:55 pm

Hi,
You may use keyup instead rawkeyup (rawkeyup return a integer)
Something like that

Code: Select all

on keyup pKey
if pKey = "z" then
   set the forecolor of the last char of fld "Notes" to red
end if	
end keyup
Best regards
Jean-Marc
https://alternatic.ch

glenn9
Posts: 223
Joined: Wed Jan 15, 2020 10:45 pm
Location: Europe

Re: alter textstyle 'on the fly'

Post by glenn9 » Sun Mar 06, 2022 3:25 pm

Klaus wrote:
Sun Mar 06, 2022 12:52 pm
Hi Glenn,
This works to a degree but if I then alter already typed text to the specified text, then of course this doesn't work!
sorry, don't understand?


Best

Klaus
Hi Klaus,

apologies for the awkward wording.

if the last character I type is a 'z' then the code will as expected change the colour of the 'z' to red.

If however I go back to text that is already in the field, and change one of characters to a 'z', the colour of the 'z' wont of course change, but the last char of the field (whatever it might be) will change to red!

I guess what I'm looking for is a way of scripting 'keyup' to change the textstyle of a char as its typed, independent of where it is in the field, as at the moment I can only do this for the last char of a field?

Hope this makes sense!

Thanks,

Glenn

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: alter textstyle 'on the fly'

Post by Klaus » Sun Mar 06, 2022 3:44 pm

Aha, thanks, get it now! :-)

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: alter textstyle 'on the fly'

Post by jmburnod » Sun Mar 06, 2022 5:46 pm

Hi Glen,
This works for an insertion, not for a selection

Code: Select all

on keyUp pk
   put the selectedchunk into tSC
   put the value of word 4 of tSC into tNumC
   if pk = "z" then
      set the forecolor of char tNumC of fld "notes" to red
   else
      set the forecolor of char tNumC of fld "notes" to black
   end if
end keyUp
https://alternatic.ch

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: alter textstyle 'on the fly'

Post by Klaus » Sun Mar 06, 2022 6:46 pm

Cool!

but no need to use VALUE!

Code: Select all

...
put word 4 of tSC into tNumC
...
Will do.

glenn9
Posts: 223
Joined: Wed Jan 15, 2020 10:45 pm
Location: Europe

Re: alter textstyle 'on the fly'

Post by glenn9 » Sun Mar 06, 2022 8:20 pm

jmburnod wrote:
Sun Mar 06, 2022 5:46 pm
Hi Glen,
This works for an insertion, not for a selection

Code: Select all

on keyUp pk
   put the selectedchunk into tSC
   put the value of word 4 of tSC into tNumC
   if pk = "z" then
      set the forecolor of char tNumC of fld "notes" to red
   else
      set the forecolor of char tNumC of fld "notes" to black
   end if
end keyUp
Hi Jean-Marc,

Many thanks, this works perfectly and exactly how I was imagining it.

Initially I couldn't understand at all why it worked but on checking the dictionary and going into debug mode I now see why it works and why 'word 4' is important.

after now seeing how this works I can only echo Klaus's comment... very cool!

Thank you again.

Regards,

Glenn

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: alter textstyle 'on the fly'

Post by jmburnod » Mon Mar 07, 2022 10:33 am

Hi Glenn,
Glad when I can help
This version below works with a selection

Code: Select all

on keyUp pk
   put the selectedchunk into tSC
   put  word 2 of tSC into tStart
   put  word 4 of tSC into tEnd 
   if tStart > tEnd then
      put tEnd into tNumS
   else
      put tStart into tNumS
   end if
   if pk = "z" then
      set the forecolor of char tNumS of fld "notes" to red
   else
      set the forecolor of char tNumS of fld "notes" to black
   end if
end keyUp
P.S: I'm curious to know why you need it.
Best
Jean-Marc
https://alternatic.ch

glenn9
Posts: 223
Joined: Wed Jan 15, 2020 10:45 pm
Location: Europe

Re: alter textstyle 'on the fly'

Post by glenn9 » Mon Mar 07, 2022 11:14 am

Thanks Jean-Marc,

The background is that I'm often in a position where I am taking almost verbatim typed notes during a conversation, and if there are any points raised that require further clarification, rather than interrupt the conversation flow, I simply type a quick marker after the item raised, usually a '(' rather than the 'z'!, so that I can then revisit the item at the end of the conversation and add more details.

If the notes are lengthy I've sometimes nearly overlooked the points that I wanted more detail on, and so having the marker in red makes it easier for me to spot!

Hope of interest.

Regards,

Glenn

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9663
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: alter textstyle 'on the fly'

Post by dunbarx » Mon Mar 07, 2022 3:01 pm

Fun stuff. I would make the "markers" more prominent than simply making a single char red. Maybe change the textSize of that char?

Craig

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: alter textstyle 'on the fly'

Post by jmburnod » Tue Mar 08, 2022 3:55 pm

Hi Glenn,
Thank you for your message.
Interessant challenge
I wonder if using metadata property would be useful in your "scribe" position.
Just an idea
When you type your marker char you can select a keyword among a list which become the metadata of the previous word.

Best regards
Jean-Marc
https://alternatic.ch

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9663
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: alter textstyle 'on the fly'

Post by dunbarx » Tue Mar 08, 2022 5:52 pm

Jean-Marc.

The "metaData" of a char or word is way cool. I have never used it, but wish I had a reason to. It is sort of like a custom property, but assigned to chunks.

But how would that stand out when the reader is trying to locate specific locations in a body of text that are of interest?

Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9663
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: alter textstyle 'on the fly'

Post by dunbarx » Tue Mar 08, 2022 5:58 pm

Well, one way would be to set, say, the backColor of the chunk of interest so it can be found easily, and if the lockText of the field is set:

Code: Select all

on mouseUp
   answer the metaData of the clickchunk
end mouseUp
The metaData being a text string of any length. This can be written when the "special" char or word is typed. An "ask" dialog can pop up where the user can enter a notation, and set the metaData to that text.

Craig

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: alter textstyle 'on the fly'

Post by jmburnod » Tue Mar 08, 2022 6:51 pm

Hi Craig,
But how would that stand out when the reader is trying to locate specific locations in a body of text that are of interest?
Why not set the textstyle of target word to "link" ?

Jean-Marc
https://alternatic.ch

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”