LiveCode LessonsLiveCode BuilderCreating Widgets Default chapterAccessing LiveCode Properties in a Widget

Accessing LiveCode Properties in a Widget

When writing a widget you create any properties your widget needs. As well as these widget properties you can also link your widget to standard LiveCode control properties, such as font, background color etc.

All controls in LiveCode, both widgets and classic controls, have a set of basic properties which are always present and do not need to be implemented when writing a widget. Any widget you create will always have these properties in its Property Inspector.

Basic LiveCode Properties

The properties that all widgets have by default are

  • Basic
    • name
    • kind
    • tooltip
    • visible
    • disabled
  • Custom properties
    • custom property sets
    • custom properties
  • Colors
    • ink
    • blendLevel
  • Size and Position
    • lockLoc
    • width
    • height
    • location
    • left
    • top
    • right
    • bottom
    • layer
  • Text
    • textFont
    • textSize
  • Advanced
    • layerMode
    • behavior
    • traversalOn
    • number

Accessing Standard Properties

Although all controls, including widgets, have all the basic properties some work automatically and some need to be taken into account when you draw the widget.

For example the width property works automatically but the textSize property requires some extra handling when the widget is drawn.

The two basic text properties all controls have are textFont and textSize.

To use the values of these properties when drawing the widget you get the effective text properties of the widget using my font and apply the values when drawing the widget.

public handler OnPaint()
   ...

   set the font of this canvas to my font

end handler

Linking to other LiveCode Properties

You can also link to other standard LiveCode properties beyond the basic, built in set.

For example we might want to set the Text fill of a widget.

Text fill, or foregroundColor to use the property name, is a standard LiveCode property but it not part of the basic set.

To access it we have to specify that the widget has the property, but we do not have to define the property itself.

Metadata for LiveCode Properties

To define a LiveCode property in a widget you provide metadata, but do not need to define the property within the widget.

This will give the widget access to the foregroundColor property, and it will be settable in the Property Inspector.

metadata foregroundColor.editor is "com.livecode.pi.color"
metadata foregroundColor.default is ""
metadata foregroundColor.section is "Colors"
metadata foregroundColor.label is "Text fill"

Applying the foregroundColor

As well as providing the metadata for the property the OnPaint handler must use the value of the property.

public handler OnPaint()
   ...

   set the font of this canvas to my font
   set the paint of this canvas to my foreground paint

end handler

Accessible LiveCode Properties

  • abbrevId,
  • abbrevName
  • abbrevOwner
  • altId
  • backColor
  • backPattern
  • backPixel
  • blendLevel
  • borderColor
  • borderPattern
  • borderPixel
  • bottom
  • bottomColor
  • bottomLeft
  • bottomPattern
  • bottomPixel
  • bottomRight
  • brushColor
  • cantSelect
  • colors
  • customKeys
  • customProperties
  • customPropertySet
  • customPropertySets
  • disabled,
  • enabled
  • focusColor
  • focusPattern
  • focusPixel
  • foreColor
  • forePattern
  • forePixel
  • height
  • hiliteColor
  • hilitePattern
  • hilitePixel
  • ink
  • invisible
  • kind
  • layer
  • layerMode
  • left
  • location
  • lockLocation
  • longId
  • longName
  • longOwner
  • name
  • number
  • owner
  • parentScript
  • patterns
  • penColor
  • properties
  • rectangle
  • right
  • script
  • selected
  • shadowColor
  • shadowPattern
  • shadowPixel
  • shortId
  • shortName
  • shortOwner
  • textFont
  • textSize
  • textStyle
  • themeControlType
  • toolTip
  • top
  • topColor
  • topLeft
  • topPattern
  • topPixel
  • topRight
  • traversalOn
  • unicodeToolTip
  • visible
  • width

0 Comments

Add your comment

E-Mail me when someone replies to this comment