Page 1 of 2
Re: How to create a new label field programmatically?
Posted: Wed May 08, 2019 9:28 am
by Klaus
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
Re: How to create a new label field programmatically?
Posted: Wed May 08, 2019 11:44 am
by bogs
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. )

- Holy Transmogrification!
- Untitled 1 -_001.png (6.12 KiB) Viewed 8833 times
*Edit - you can also look up 'newField' in the dictionary, surprisingly enough, the example listed is for a label

Re: How to create a new label field programmatically?
Posted: Wed May 08, 2019 4:08 pm
by richmond62
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 (5.95 KiB) Viewed 8802 times
Re: How to create a new label field programmatically?
Posted: Wed May 08, 2019 4:21 pm
by Klaus
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.

Re: How to create a new label field programmatically?
Posted: Wed May 08, 2019 4:24 pm
by richmond62

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

Re: How to create a new label field programmatically?
Posted: Wed May 08, 2019 4:29 pm
by Klaus
Sigh, we are talking about a LABEL field and not a text entry field with textalign set to RIGHT!
I know you know!

Re: How to create a new label field programmatically?
Posted: Wed May 08, 2019 4:52 pm
by richmond62
Re: How to create a new label field programmatically?
Posted: Wed May 08, 2019 4:55 pm
by dunbarx
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
Re: How to create a new label field programmatically?
Posted: Wed May 08, 2019 4:57 pm
by richmond62
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 
Re: How to create a new label field programmatically?
Posted: Wed May 08, 2019 5:02 pm
by dunbarx
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
Re: How to create a new label field programmatically?
Posted: Wed May 08, 2019 5:06 pm
by dunbarx
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
Re: How to create a new label field programmatically?
Posted: Wed May 08, 2019 5:07 pm
by richmond62

- Screenshot 2019-05-08 at 19.06.42.png (4.98 KiB) Viewed 8785 times
-
the labelThing yielded by that script is completely uneditable.
Give it a try:
-
Re: How to create a new label field programmatically?
Posted: Wed May 08, 2019 5:36 pm
by Klaus
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!
Re: How to create a new label field programmatically?
Posted: Wed May 08, 2019 5:58 pm
by bogs
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
*Edit 2 - Here is a
video of the process.
Re: How to create a new label field programmatically?
Posted: Wed May 08, 2019 6:40 pm
by richmond62
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