Page 1 of 1

Setting a variable to NULL?

Posted: Fri Mar 13, 2015 5:46 pm
by trevordevore
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?

Re: Setting a variable to NULL?

Posted: Fri Mar 13, 2015 6:02 pm
by LCMark
@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.

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
You can check whether optional types contain something by using 'is defined' / 'is not defined' / 'is undefined' / 'is not undefined'.

Re: Setting a variable to NULL?

Posted: Fri Mar 13, 2015 6:23 pm
by trevordevore
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?

Re: Setting a variable to NULL?

Posted: Fri Mar 13, 2015 7:56 pm
by LCMark
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)

Re: Setting a variable to NULL?

Posted: Fri Mar 13, 2015 9:29 pm
by livecodeali
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 :-)

Re: Setting a variable to NULL?

Posted: Fri Mar 13, 2015 9:31 pm
by livecodeali
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.

Re: Setting a variable to NULL?

Posted: Fri Mar 13, 2015 9:51 pm
by trevordevore
@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!