Insert text in field

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
SEAL29
Posts: 63
Joined: Fri Oct 02, 2020 3:32 pm

Insert text in field

Post by SEAL29 » Sun Oct 11, 2020 3:24 pm

If i paste text (cmd+v) in field, it always converts it to the font used by that program. In the Inspector under the Font option i setting the font is Calibri and size is 13. How that should be set so that it does not change?

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10099
Joined: Fri Feb 19, 2010 10:17 am

Re: Insert text in field

Post by richmond62 » Sun Oct 11, 2020 9:14 pm

Code: Select all

set the textFont of field "fDATA" to "Courier"
set the textSize of field "fDATA" to 36

Frankly, you'd save a lot of time, instead of asking basic questions here by just poking around in the Dictionary.

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

Re: Insert text in field

Post by dunbarx » Sun Oct 11, 2020 9:35 pm

Ask anything you want. We love to answer.

A new field will inherit the text properties of the OS unless you explicitly set them yourself. Such properties are, by default, empty.

Try it. Make a new field and from msg:

Code: Select all

answer the textSize of last field
You will get empty.

Now, again in msg:

Code: Select all

set the textSize of last field to 14
If you now ask for the textSize of that same field, you will get 14.

Lots of properties work this way. This can cause a lot of wasted effort if you forget this.
Craig.

AxWald
Posts: 578
Joined: Thu Mar 06, 2014 2:57 pm

Re: Insert text in field

Post by AxWald » Sun Oct 11, 2020 10:50 pm

Hi,
I understand your question this way [explanation in square brackets by me):
SEAL29 wrote:
Sun Oct 11, 2020 3:24 pm
If i paste text [from Word] in field, it [LiveCode] always converts it to the font used by that program [Word].
[...] How that should be set so that it does not change?
Answer then is: If you paste styled text into a field, LC will try to keep these attributes.

If you want your field to keep its text in Calibri 13, give it this code:

Code: Select all

on textchanged
   set the textFont of char 1 to -1 of me to "Calibri"
   set the textSize of char 1 to -1 of me to 13
   --  you need to set the styles, too:
   set the textStyle of char 1 to -1 of me to "plain"
end textchanged
Have fun!
All code published by me here was created with Community Editions of LC (thus is GPLv3).
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!

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

Re: Insert text in field

Post by FourthWorld » Mon Oct 12, 2020 5:06 am

See the clipboardData global property in the Dictionary. It's an array, with keys for many representations.

Try:

Code: Select all

put the clipboardData["text"] into the selection 
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

SEAL29
Posts: 63
Joined: Fri Oct 02, 2020 3:32 pm

Re: Insert text in field

Post by SEAL29 » Mon Oct 12, 2020 3:03 pm

AxWald wrote:
Sun Oct 11, 2020 10:50 pm
Hi,
I understand your question this way [explanation in square brackets by me):
SEAL29 wrote:
Sun Oct 11, 2020 3:24 pm
If i paste text [from Word] in field, it [LiveCode] always converts it to the font used by that program [Word].
[...] How that should be set so that it does not change?
Answer then is: If you paste styled text into a field, LC will try to keep these attributes.

If you want your field to keep its text in Calibri 13, give it this code:

Code: Select all

on textchanged
   set the textFont of char 1 to -1 of me to "Calibri"
   set the textSize of char 1 to -1 of me to 13
   --  you need to set the styles, too:
   set the textStyle of char 1 to -1 of me to "plain"
end textchanged
Have fun!
Thank you, this work like a charm. Thanks to everyone else for the help.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10099
Joined: Fri Feb 19, 2010 10:17 am

Re: Insert text in field

Post by richmond62 » Mon Oct 12, 2020 4:18 pm

Answer then is: If you paste styled text into a field, LC will try to keep these attributes.
Um . . .

Be aware that that will only hold true so long as that font exists on an end-user's operating system . . .

&&&&&&

cross-platform fonts are a minefield of horros.

Post Reply