LiveCode
  • Why LiveCode?
  • Customers
  • Resources
  • Education
  • Consulting
  • Pricing
  • Blog
  • Login
  • Try LiveCode
Back to
  • slides
  • tutorial
Resources

Read Only Properties

Topic Progress:
← Back to Lesson

So far we have only looked at properties that can be set by the user.

In this lesson we will implement some read only properties that depend entirely on the widget state. These properties will be familiar to anyone experienced with LiveCode Script.

  • formattedWidth – Reports the width needed by an object to display its full contents without scrolling. This property is read-only and cannot be set.
  • formattedHeight – Reports the height needed by an object to display its full contents without scrolling. This property is read-only and cannot be set.

We will implement these two properties for the Rotated Text widget by calculating the space the text displayed in the widget requires and returning these values.

Declaring properties

Firstly declare the properties in the widget source code.

Add two instance variables to hold the property values and add definitions for the formattedWidth and formattedHeight properties.

Because the properties are read only they do not require setter identifiers. The getter simply returns the value of the variable.

widget community.livecode.elanorb.rotatedtext

… widget inclusions and metadata
… existing property definitions

private variable mFormattedWidth as Real
private variable mFormattedHeight as Real
property "formattedWidth" get mFormattedWidth
property "formattedHeight" get mFormattedHeight

… OnPaint and OnCreate handlers
… Property Setters
… Event handlers
… OnSave and OnLoad handlers

end widget

Storing the values

We want to update the values of the formattedWidth and formattedHeight properties whenever the state of the widget changes. This ensures the correct value will always be returned by the property.

Update the OnPaint handler to calculate and store the formattedWidth andformattedHeight of the widget whenever it is redrawn.

  • Declare a rectangle variable.
  • Get the bounds of the text on the canvas. This returns the bounding box of the text when drawn at point 0,0 as a rectangle, taking into account the font, style and text size of the canvas.
  • Update the variables holding the property values with the width and height of the bounding box of the text.
public handler OnPaint()
 … previous code

 variable tBounds as Rectangle
 put the bounds of text mContent on this canvas into tBounds
 put the width of tBounds into mFormattedWidth
 put the height of tBounds into mFormattedHeight
end handler

Testing read only properties

Compile and test the widget using the Extension Builder.

  • Go into Edit mode.
  • Select the widget in the test stack.
  • Open the Property Inspector.

The formattedWidth and formattedHeight properties will be shown on the Basic pane, they can’t be edited because the are read only.

You can check the width and height properties in the Position pane and see they are different values.

propertyInspector5

Hiding properties

There may be cases where your widget has properties that you do not want to show in the Property Inspector. This may be because they are read only, internal or undocumented.

You can set property metadata to prevent the properties being visible to the user.

Add ‘user_visible’ metadata to the formattedWidth and formattedHeight properties.

 

widget community.livecode.elanorb.rotatedtext

… widget inclusions and metadata
… existing property definitions

private variable mFormattedWidth as Real
private variable mFormattedHeight as Real
property "formattedWidth" get mFormattedWidth
metadata formattedWidth.user_visible is "false"
property "formattedHeight" get mFormattedHeight
metadata formattedHeight.user_visible is "false"

… OnPaint and OnCreate handlers
… Property Setters
… Event handlers
.... OnSave and OnLoad handlers

end widget

Testing non user-visible properties

Compile and test the widget using the Extension Builder.

  • Go into Edit mode.
  • Select the widget on the test stack.
  • Open the Property Inspector.

The formattedWidth and formattedHeight properties will not be shown in the Property Inspector.

However you can get the property value from code. Execute the following code in the Message Box to test the property.

put the formattedHeight of widget 1
messageBox

← Previous Topic

← Previous Topic Next Topic →
  •  
  •  
  • (0)
  •  

Expand All | Collapse All
Lessons Status
1 - Hello World Library
  • Introduction
  • Installing a Text Editor
  • Creating an LCB library
  • LCB library definition
  • LCB handler definitions
  • Compiling and testing a library in LiveCode
  • LCB metadata
  • Installing an LCB Library
  • Packaging and sharing an LCB library
  • Including an LCB library in a standalone
  • Conclusion
2 - Extended Hello World Library
  • Introduction
  • Explicit Types
  • LCB Lists and Arrays
  • Type Conversion between LCB and LiveCode Script
  • Using Explicit Typing in the Library
  • Passing Parameters to the Library
  • Using Lists in the Library
  • Documenting the Library
  • Browsing the Documentation
  • Conclusion
3 - Rotated Text Widget
  • Introduction
  • Defining a Widget
  • LCB Module Level Variables
  • Widget Properties
  • Widget Handlers
  • LCB Canvas Operations
  • Compiling and Testing the Widget
  • Installing the Widget and adding it to a Stack
  • Including the Widget in a Standalone
  • Conclusion
4 - Extended Rotated Text Widget
  • Introduction
  • Integrating Properties
  • Accessing LiveCode Control Properties
  • Handling Mouse Events
  • Saving and Loading Widgets
  • Read Only Properties
  • Documenting the Widget
  • Conclusion
5 - Pie Chart Widget
  • Introduction
  • Planning the Widget
  • Widget Properties
  • The OnCreate Handler
  • The OnPaint Handler
  • Responding to Mouse Events
  • Saving and Loading the Widget
  • Installing and Including the Widget in a Standalone
  • Documenting the Widget
  • Conclusion
6 - Modifying the Line Graph Widget
  • Introduction
  • Duplicating the Line Graph Widget
  • Additional Color Properties
  • Filling the area below the line
  • Adding graph marker mouse events
  • Conclusion
7 - Additional Resources
  • Extending LiveCode Guide
  • LiveCode Builder Language Reference
  • LiveCode Builder Style Guide
  • LiveCode Documentation Format
 

LCB Source

LCB Source
 

Login

LiveCode

  • Why LiveCode?
  • Pricing
  • Customer Stories
  • Extensions
  • LiveCode in Education
  • LiveCode in Business

Looking for LiveCode FileMaker?

LiveCode for FM

Resources

  • Docs
  • API (Language Dictionary)
  • Lessons
  • Sample Stacks
  • Forums
  • Stackoverflow
  • User Groups
  • Support
  • Directory
  • LiveCode Services

About

  • About
  • Meet The Team
  • Careers at LiveCode
  • Contact us

Recent Posts

  • LiveCode Classic 10.0.1 Stable and 10.0.2-rc-1 Released
  • Create Progress – the Three D’s
  • LiveCode Create: Closing out the year with big steps forward
  • Create dp-5: Unified Engines and Shared Extensions
  • 3 Great New LiveCode Releases
Sitemap
Terms Privacy Policy EULA
Brought to you by LiveCode Ltd, Registered in Scotland, No. SC200728
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.Ok