How to create a new label field programmatically?

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

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

Re: How to create a new label field programmatically?

Post by Klaus » Wed May 08, 2019 9:28 am

Hi Ricky,

welcome to the forum!
I found a response from dunbarx on a mailing list, but it gives me an error:
CODE: SELECT ALL
Well, I do not see any code except: select all ?

All created objects in LC are dervied from a "template".
so you need to set the neccessary properties for -> the templatefield
and THEN create a field, something like:

Code: Select all

...
## visible = true by default, no need to set this explicitely
set the locktext of the templatefield to true
## (field content cannot be edited)
## You can set the content set the content:
set the text of the templatefield to "Hi Ricky!"
set the hscrollbar of the templatefield to false
set the vscrollbar of the templatefield to false
set the showborder of the templatefield to false
## etc... for loc, width, height, textalign... set whatever you need
## NOW create the field:
create field

## After creation:
## Good style and will avoid surprises
RESET the templatefield
...
Best

Klaus

bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: How to create a new label field programmatically?

Post by bogs » Wed May 08, 2019 11:44 am

Hello rickymonkson,

Klaus's explanation is a very full one, for creating a template then the control.

On the off chance you actually mean just creating a new object (field, button, card, etc), you can do it pretty easily on one line with just "create [object]".

Labels are just a field as you already know, with different properties set. Klaus points out that setting some properties aren't exactly necessary (your not going to have a scrollbar by default, so you don't need to set one to false if you don't need it). I typed this into the messagebox on a new stack:

Code: Select all

create field "myLabel"; put "This is my new label" into the last field; set the lockText of the last field to true; set the opaque of the last field to false;
Each semi-colon is the equivalent of a new line, you could also have written it like this:

Code: Select all

on [handler or message you want to respond to]
	create field "myLabel"
	put "This is my new label" into the last field
	set the lockText of the last field to true
	set the opaque of the last field to false
end [handler or message]
And of course you can refine it further to suit your needs, height, width, etc.

The above code produced the following 3 fields (field 1 was line 1, field 2 was line 2, etc. )
Untitled 1 -_001.png
Holy Transmogrification!
Untitled 1 -_001.png (6.12 KiB) Viewed 8838 times
*Edit - you can also look up 'newField' in the dictionary, surprisingly enough, the example listed is for a label :D
Image

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

Re: How to create a new label field programmatically?

Post by richmond62 » Wed May 08, 2019 4:08 pm

Maybe I'm a bit stupid, but it escapse me what the difference is between a textField and a labelField beyond the fact that the text in the labelField is right-justified by default.

Someone, someweher, seems to be overcomplicating things a wee bit. I did this in a Button:

Code: Select all

on mouseUp
   create fld "lf"
   set the text of fld "lf" to "looks easy"
   set the textAlign of fld "lf" to right
end mouseUp
-
labelFFFFF.png
labelFFFFF.png (5.95 KiB) Viewed 8807 times

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

Re: How to create a new label field programmatically?

Post by Klaus » Wed May 08, 2019 4:21 pm

richmond62 wrote:
Wed May 08, 2019 4:08 pm
Maybe I'm a bit stupid...
No comment, but try to enter text into a LABEL field (with the browse tool!) and come back again. :D

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

Re: How to create a new label field programmatically?

Post by richmond62 » Wed May 08, 2019 4:24 pm

Screenshot 2019-05-08 at 18.23.36.png
Screenshot 2019-05-08 at 18.23.36.png (5.41 KiB) Viewed 8801 times
-
Not a problem with my recipe. 8)

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

Re: How to create a new label field programmatically?

Post by Klaus » Wed May 08, 2019 4:29 pm

Sigh, we are talking about a LABEL field and not a text entry field with textalign set to RIGHT!
I know you know! 8)

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

Re: How to create a new label field programmatically?

Post by richmond62 » Wed May 08, 2019 4:52 pm


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

Re: How to create a new label field programmatically?

Post by dunbarx » Wed May 08, 2019 4:55 pm

Boys, boys.

Interestingly, I cannot find a way to change an existing out-of-the-box label field into an ordinary field. There is some property beyond just the lockText, traversalOn, etc.

Or is it its own object class?

Anyone?

Craig
Last edited by dunbarx on Wed May 08, 2019 4:59 pm, edited 1 time in total.

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

Re: How to create a new label field programmatically?

Post by richmond62 » Wed May 08, 2019 4:57 pm

try to enter text into a LABEL field (with the browse tool!)
Why?

All the person wants to do is create a labelField programmatically.

This does "it":

Code: Select all

on mouseUp
   set the text of the templateField to "label:"
   set the width of the templateField to 100
   set the height of the templateField to 21
   set the visible of the templateField to true
   set the dontwrap of the templateField to true
   set the locktext of the templateField to true
   set the threeD of the templateField to true
   set the showfocusborder of the templateField to false
   set the showborder of the templateField to false
   set the traversalOn of the templateField to false
   set the textAlign of the templateField to right
   set the loc of the templateField to the loc of this card
   create field "lfld"
end mouseUp
And before, Klaus, you change your mind about my stupidity, I "lifted" that code from here:

https://forums.livecode.com/viewtopic.php?t=9904 8)

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

Re: How to create a new label field programmatically?

Post by dunbarx » Wed May 08, 2019 5:02 pm

Richmond.

Doing that creates a field, but not a label field. See my post just above.

The field you get, if you turn on traversalOn and turn off lockText, is editable. A label field is not, or at least I cannot find out how to. I compared "the Properties" of each kind of field, and they all match. But I cannot edit a"true" label Field.

Craig

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

Re: How to create a new label field programmatically?

Post by dunbarx » Wed May 08, 2019 5:06 pm

All.

And surely one can create a "label" field that works and looks just like the one in the tools palette. And that sort of field can be made from the templateField.

But I cannot make a true label field that way.

Craig

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

Re: How to create a new label field programmatically?

Post by richmond62 » Wed May 08, 2019 5:07 pm

Screenshot 2019-05-08 at 19.06.42.png
Screenshot 2019-05-08 at 19.06.42.png (4.98 KiB) Viewed 8790 times
-
the labelThing yielded by that script is completely uneditable.

Give it a try:
-
Create a label.livecode.zip
Here's the stack
(1011 Bytes) Downloaded 251 times

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

Re: How to create a new label field programmatically?

Post by Klaus » Wed May 08, 2019 5:36 pm

Richmond,

this:

Code: Select all

...
set the locktext of the templateField to true
...
is the step you left out in your first posting:

Code: Select all

on mouseUp
   create fld "lf"
   set the text of fld "lf" to "looks easy"
   set the textAlign of fld "lf" to right
end mouseUp
But nevertheless you claimed that this would create a LABEL field!?
COME ON!

bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: How to create a new label field programmatically?

Post by bogs » Wed May 08, 2019 5:58 pm

dunbarx wrote:
Wed May 08, 2019 4:55 pm
Interestingly, I cannot find a way to change an existing out-of-the-box label field into an ordinary field. There is some property beyond just the lockText, traversalOn, etc.

Or is it its own object class?

Anyone?

Craig
Well, far as I can tell, it is just a field. Here are the props for a label :

Code: Select all

altId	0
autoHilite	false
autoTab	false
backColor	
backPattern	
behavior	
blendLevel	0
borderColor	
borderPattern	
borderWidth	2
bottomColor	
bottomPattern	
cantSelect	false
colorOverlay	
disabled	false
dontSearch	false
dontWrap	true
dropShadow	
firstIndent	0
fixedLineHeight	true
focusColor	
focusPattern	
foreColor	
forePattern	
hGrid	false
hScroll	0
hScrollbar	false
hiliteColor	
hilitePattern	
hilitedLines	
htmlText	<p>Label:</p>
id	1018
ink	srcCopy
innerGlow	
innerShadow	
layer	1
layerMode	static
listBehavior	false
lockLoc	false
lockText	true
margins	8
multipleHilites	false
name	Label Field
noncontiguousHilites	false
opaque	false
outerGlow	
rect	26,26,126,47
scrollbarWidth	20
shadow	false
shadowColor	
shadowOffset	4
shadowPattern	
sharedText	true
showBorder	false
showFocusBorder	true
showLines	false
style	transparent
tabStops	
textAlign	right
textFont	
textHeight	
textSize	
textStyle	
threeD	true
threeDHilite	false
toggleHilites	false
toolTip	
topColor	
topPattern	
traversalOn	false
vGrid	false
vScroll	0
vScrollbar	false
visible	true
and for a regular field...

Code: Select all

altId	0
autoHilite	true
autoTab	false
backColor	
backPattern	
behavior	
blendLevel	0
borderColor	
borderPattern	
borderWidth	2
bottomColor	
bottomPattern	
cantSelect	false
colorOverlay	
disabled	false
dontSearch	false
dontWrap	false
dropShadow	
firstIndent	0
fixedLineHeight	true
focusColor	
focusPattern	
foreColor	
forePattern	
hGrid	false
hScroll	0
hScrollbar	false
hiliteColor	
hilitePattern	
hilitedLines	
htmlText	<p></p>
id	1020
ink	srcCopy
innerGlow	
innerShadow	
layer	2
layerMode	static
listBehavior	false
lockLoc	false
lockText	false
margins	8
multipleHilites	false
name	Field
noncontiguousHilites	false
opaque	true
outerGlow	
rect	24,69,124,90
scrollbarWidth	20
shadow	false
shadowColor	
shadowOffset	4
shadowPattern	
sharedText	false
showBorder	true
showFocusBorder	true
showLines	false
style	rectangle
tabStops	
textAlign	left
textFont	
textHeight	
textSize	
textStyle	
threeD	true
threeDHilite	false
toggleHilites	false
toolTip	
topColor	
topPattern	
traversalOn	true
vGrid	false
vScroll	0
vScrollbar	false
visible	true
Main differences I see are opaque, locktext, border, and transversal.

*Edit - I forgot autoHilite :oops:

*Edit 2 - Here is a video of the process.
Image

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

Re: How to create a new label field programmatically?

Post by richmond62 » Wed May 08, 2019 6:40 pm

So, in theory, one could just take a basic textField and reset 5 properties:

opaque, locktext, dontWrap, traversalOn, and autoHilite . . .

( can't see a difference in terms of the border )

also wonder about "transversal"; must remember to set LGBT to true.

BUT that does not seem enough:

Button 'make Field"

Code: Select all

on mouseUp
   set the opaque of fld "ff" to true
   set the autoHilite of fld "ff" to true
   set the dontWrap of fld "ff" to true
   set the lockText of fld "ff" to true
   set the traversalOn of fld "ff" to true
end mouseUp

Button "make Label"

Code: Select all

on mouseUp
   set the opaque of fld "ff" to false
   set the autoHilite of fld "ff" to false
   set the dontWrap of fld "ff" to false
   set the lockText of fld "ff" to false
   set the traversalOn of fld "ff" to false
end mouseUp
TRANSversal.livecode.zip
Here's the stack
(1.1 KiB) Downloaded 254 times

Post Reply