Setting a variable to NULL?
-
- VIP Livecode Opensource Backer
- Posts: 1005
- Joined: Sat Apr 08, 2006 3:06 pm
- Location: Overland Park, Kansas
- Contact:
Setting a variable to NULL?
So now that we have inherited fonts, I need a way of knowing when to override a font, font size, or font style in my widget. I was hoping to be able to set a variable to NULL so that I could know whether or not the value had been set. For font and font style an empty string or list will work just fine. For numbers I would like to use NULL to designate that the size should be inherited. In this case I could use -1 internally, but if my number needed to use negative or positive values then -1 wouldn't work.
Should we be able to set a Number variable to null?
Should we be able to set a Number variable to null?
Trevor DeVore
ScreenSteps - https://www.screensteps.com
LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder
ScreenSteps - https://www.screensteps.com
LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder
Re: Setting a variable to NULL?
@trevordevore: I'm not sure I follow the use-case.
The 'my font' patch essentially means that you can get the font as described by the standard (inherited) LiveCode text properties - in particular you cannot define textFont/textSize/textStyle properties of widgets (at the moment at least) because the engine manages those for you. Can you explain a little more about your use-case - it might be that the 'my font' approach is unsuitable.
In terms of representing 'nothing' and numbers - you can use 'optional' types.
You can check whether optional types contain something by using 'is defined' / 'is not defined' / 'is undefined' / 'is not undefined'.
The 'my font' patch essentially means that you can get the font as described by the standard (inherited) LiveCode text properties - in particular you cannot define textFont/textSize/textStyle properties of widgets (at the moment at least) because the engine manages those for you. Can you explain a little more about your use-case - it might be that the 'my font' approach is unsuitable.
In terms of representing 'nothing' and numbers - you can use 'optional' types.
Code: Select all
variable tVar is optional number
-- do something to populate tVar
if tVar is undefined then
-- there is no number there
put 100 into tVar
else
-- there is a number there
put undefined into tVar
end if
-- tVar might be a number or might be undefined
-
- VIP Livecode Opensource Backer
- Posts: 1005
- Joined: Sat Apr 08, 2006 3:06 pm
- Location: Overland Park, Kansas
- Contact:
Re: Setting a variable to NULL?
Thanks for the info on "optional". I had seen that in some lcb code but didn't know what it meant.
As for my font, I was looking for a way to display property inspector elements for textFont, textSize, and textStyle. I was just going to come up with different labels that I would use to override the my font settings if they were present. I see that that is a lousy approach.
Any ideas on how to get the textFont/Size/Style properties into the property inspector for a widget?
As for my font, I was looking for a way to display property inspector elements for textFont, textSize, and textStyle. I was just going to come up with different labels that I would use to override the my font settings if they were present. I see that that is a lousy approach.
Any ideas on how to get the textFont/Size/Style properties into the property inspector for a widget?
Trevor DeVore
ScreenSteps - https://www.screensteps.com
LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder
ScreenSteps - https://www.screensteps.com
LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder
Re: Setting a variable to NULL?
For now you can 'hack' it by putting property definitions in the widget with dummy set/get prop handlers - (there must be an editor you can specify for fonts, because the textFont property on classic controls has one). They won't actually get used as the widget doesn't see any reserved property interactions (except via OnParentPropertyChanged and the syntax designed to get the derived values).
I suspect the Property Inspector has a 'built-in' list somewhere, but as we only 'reserved' the font properties today, it hasn't filtered up to the IDE yet. Also, I'm not entirely sure how the textFont editor is hooked into - the classic controls have it, and everything is dynamically generated so there must be an editor you can set in the metadata of the property.
(I must confess, beyond occasional help with specific things, the IDE changes have been runrevben, runrevelanor, runrevali and runrevgeogia's domain thus I don't know the in-depth details of exactly how it works and puts / references things)
I suspect the Property Inspector has a 'built-in' list somewhere, but as we only 'reserved' the font properties today, it hasn't filtered up to the IDE yet. Also, I'm not entirely sure how the textFont editor is hooked into - the classic controls have it, and everything is dynamically generated so there must be an editor you can set in the metadata of the property.
(I must confess, beyond occasional help with specific things, the IDE changes have been runrevben, runrevelanor, runrevali and runrevgeogia's domain thus I don't know the in-depth details of exactly how it works and puts / references things)
-
- Livecode Staff Member
- Posts: 192
- Joined: Thu Apr 18, 2013 2:48 pm
Re: Setting a variable to NULL?
Hi Trevor,
If you put
metadata textFont.options is "execute:get the fontNames; sort it"
metadata textFont.editor is "com.livecode.pi.enum"
then I *think* it will work out putting the font options in the property inspector. You might want
metadata textFont.section is "Text"
too, to put it into the appropriate part of the PI.
If those don't work, then there's a bug for us to look at next week
If you put
metadata textFont.options is "execute:get the fontNames; sort it"
metadata textFont.editor is "com.livecode.pi.enum"
then I *think* it will work out putting the font options in the property inspector. You might want
metadata textFont.section is "Text"
too, to put it into the appropriate part of the PI.
If those don't work, then there's a bug for us to look at next week
-
- Livecode Staff Member
- Posts: 192
- Joined: Thu Apr 18, 2013 2:48 pm
Re: Setting a variable to NULL?
Alternatively, (and probably much more easily) you can add all of the properties to the Toolset/resources/supporting_files/property_definitions/com.livecode.interface.classic.widget.txt file.
-
- VIP Livecode Opensource Backer
- Posts: 1005
- Joined: Sat Apr 08, 2006 3:06 pm
- Location: Overland Park, Kansas
- Contact:
Re: Setting a variable to NULL?
@livecodeali - I added textFont, textSize, and textStyle to the class.widget.txt file and the Text inspector now shows up for widgets. Not sure if there should be a way in each widget definition to specify this or not, but I'm going to leave it on for my work. Thanks!
Trevor DeVore
ScreenSteps - https://www.screensteps.com
LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder
ScreenSteps - https://www.screensteps.com
LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder